├── .gitattributes ├── .gitignore ├── KinectWebServer.sln ├── KinectWebServer ├── App.config ├── KinectWebServer.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── TestPage.html ├── TestSite │ ├── TestPage.html │ ├── Web.Debug.config │ ├── Web.config │ └── kinect.js ├── kinect.js └── packages.config ├── README.md └── TestSite ├── TestPage.html ├── Web.Debug.config ├── Web.config └── kinect.js /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | bld/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | 19 | # Roslyn cache directories 20 | *.ide/ 21 | 22 | # MSTest test Results 23 | [Tt]est[Rr]esult*/ 24 | [Bb]uild[Ll]og.* 25 | 26 | #NUNIT 27 | *.VisualState.xml 28 | TestResult.xml 29 | 30 | # Build Results of an ATL Project 31 | [Dd]ebugPS/ 32 | [Rr]eleasePS/ 33 | dlldata.c 34 | 35 | *_i.c 36 | *_p.c 37 | *_i.h 38 | *.ilk 39 | *.meta 40 | *.obj 41 | *.pch 42 | *.pdb 43 | *.pgc 44 | *.pgd 45 | *.rsp 46 | *.sbr 47 | *.tlb 48 | *.tli 49 | *.tlh 50 | *.tmp 51 | *.tmp_proj 52 | *.log 53 | *.vspscc 54 | *.vssscc 55 | .builds 56 | *.pidb 57 | *.svclog 58 | *.scc 59 | 60 | # Chutzpah Test files 61 | _Chutzpah* 62 | 63 | # Visual C++ cache files 64 | ipch/ 65 | *.aps 66 | *.ncb 67 | *.opensdf 68 | *.sdf 69 | *.cachefile 70 | 71 | # Visual Studio profiler 72 | *.psess 73 | *.vsp 74 | *.vspx 75 | 76 | # TFS 2012 Local Workspace 77 | $tf/ 78 | 79 | # Guidance Automation Toolkit 80 | *.gpState 81 | 82 | # ReSharper is a .NET coding add-in 83 | _ReSharper*/ 84 | *.[Rr]e[Ss]harper 85 | *.DotSettings.user 86 | 87 | # JustCode is a .NET coding addin-in 88 | .JustCode 89 | 90 | # TeamCity is a build add-in 91 | _TeamCity* 92 | 93 | # DotCover is a Code Coverage Tool 94 | *.dotCover 95 | 96 | # NCrunch 97 | _NCrunch_* 98 | .*crunch*.local.xml 99 | 100 | # MightyMoose 101 | *.mm.* 102 | AutoTest.Net/ 103 | 104 | # Web workbench (sass) 105 | .sass-cache/ 106 | 107 | # Installshield output folder 108 | [Ee]xpress/ 109 | 110 | # DocProject is a documentation generator add-in 111 | DocProject/buildhelp/ 112 | DocProject/Help/*.HxT 113 | DocProject/Help/*.HxC 114 | DocProject/Help/*.hhc 115 | DocProject/Help/*.hhk 116 | DocProject/Help/*.hhp 117 | DocProject/Help/Html2 118 | DocProject/Help/html 119 | 120 | # Click-Once directory 121 | publish/ 122 | 123 | # Publish Web Output 124 | *.[Pp]ublish.xml 125 | *.azurePubxml 126 | ## TODO: Comment the next line if you want to checkin your 127 | ## web deploy settings but do note that will include unencrypted 128 | ## passwords 129 | #*.pubxml 130 | 131 | # NuGet Packages Directory 132 | packages/* 133 | ## TODO: If the tool you use requires repositories.config 134 | ## uncomment the next line 135 | #!packages/repositories.config 136 | 137 | # Enable "build/" folder in the NuGet Packages folder since 138 | # NuGet packages use it for MSBuild targets. 139 | # This line needs to be after the ignore of the build folder 140 | # (and the packages folder if the line above has been uncommented) 141 | !packages/build/ 142 | 143 | # Windows Azure Build Output 144 | csx/ 145 | *.build.csdef 146 | 147 | # Windows Store app package directory 148 | AppPackages/ 149 | 150 | # Others 151 | sql/ 152 | *.Cache 153 | ClientBin/ 154 | [Ss]tyle[Cc]op.* 155 | ~$* 156 | *~ 157 | *.dbmdl 158 | *.dbproj.schemaview 159 | *.pfx 160 | *.publishsettings 161 | node_modules/ 162 | bower_components/ 163 | 164 | # RIA/Silverlight projects 165 | Generated_Code/ 166 | 167 | # Backup & report files from converting an old project file 168 | # to a newer Visual Studio version. Backup files are not needed, 169 | # because we have git ;-) 170 | _UpgradeReport_Files/ 171 | Backup*/ 172 | UpgradeLog*.XML 173 | UpgradeLog*.htm 174 | 175 | # SQL Server files 176 | *.mdf 177 | *.ldf 178 | 179 | # Business Intelligence projects 180 | *.rdl.data 181 | *.bim.layout 182 | *.bim_*.settings 183 | 184 | # Microsoft Fakes 185 | FakesAssemblies/ 186 | 187 | # LightSwitch generated files 188 | GeneratedArtifacts/ 189 | _Pvt_Extensions/ 190 | ModelManifest.xml -------------------------------------------------------------------------------- /KinectWebServer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.22512.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KinectWebServer", "KinectWebServer\KinectWebServer.csproj", "{74862729-BA5E-4DC4-BF89-F99ACCE274F5}" 7 | EndProject 8 | Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "TestSite(1)", "http://localhost:29934", "{208ACD3E-1073-40DA-9C2B-3212F3DEA3CE}" 9 | ProjectSection(WebsiteProperties) = preProject 10 | UseIISExpress = "true" 11 | TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.5" 12 | Debug.AspNetCompiler.VirtualPath = "/localhost_29934" 13 | Debug.AspNetCompiler.PhysicalPath = "TestSite\" 14 | Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_29934\" 15 | Debug.AspNetCompiler.Updateable = "true" 16 | Debug.AspNetCompiler.ForceOverwrite = "true" 17 | Debug.AspNetCompiler.FixedNames = "false" 18 | Debug.AspNetCompiler.Debug = "True" 19 | Release.AspNetCompiler.VirtualPath = "/localhost_29934" 20 | Release.AspNetCompiler.PhysicalPath = "TestSite\" 21 | Release.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_29934\" 22 | Release.AspNetCompiler.Updateable = "true" 23 | Release.AspNetCompiler.ForceOverwrite = "true" 24 | Release.AspNetCompiler.FixedNames = "false" 25 | Release.AspNetCompiler.Debug = "False" 26 | SlnRelativePath = "TestSite\" 27 | DefaultWebSiteLanguage = "Visual C#" 28 | EndProjectSection 29 | EndProject 30 | Global 31 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 32 | Debug|Any CPU = Debug|Any CPU 33 | Release|Any CPU = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 36 | {74862729-BA5E-4DC4-BF89-F99ACCE274F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {74862729-BA5E-4DC4-BF89-F99ACCE274F5}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {74862729-BA5E-4DC4-BF89-F99ACCE274F5}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {74862729-BA5E-4DC4-BF89-F99ACCE274F5}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {208ACD3E-1073-40DA-9C2B-3212F3DEA3CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {208ACD3E-1073-40DA-9C2B-3212F3DEA3CE}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {208ACD3E-1073-40DA-9C2B-3212F3DEA3CE}.Release|Any CPU.ActiveCfg = Debug|Any CPU 43 | {208ACD3E-1073-40DA-9C2B-3212F3DEA3CE}.Release|Any CPU.Build.0 = Debug|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /KinectWebServer/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /KinectWebServer/KinectWebServer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {74862729-BA5E-4DC4-BF89-F99ACCE274F5} 8 | Exe 9 | Properties 10 | KinectWebServer 11 | KinectWebServer 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | ..\packages\log4net.2.0.3\lib\net40-full\log4net.dll 38 | 39 | 40 | ..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll 41 | 42 | 43 | False 44 | ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll 45 | 46 | 47 | 48 | ..\packages\SuperWebSocketNETServer.0.8\lib\net45\SuperSocket.Common.dll 49 | 50 | 51 | ..\packages\SuperWebSocketNETServer.0.8\lib\net45\SuperSocket.Facility.dll 52 | 53 | 54 | ..\packages\SuperWebSocketNETServer.0.8\lib\net45\SuperSocket.SocketBase.dll 55 | 56 | 57 | ..\packages\SuperWebSocketNETServer.0.8\lib\net45\SuperSocket.SocketEngine.dll 58 | 59 | 60 | ..\packages\SuperWebSocketNETServer.0.8\lib\net45\SuperWebSocket.dll 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 92 | -------------------------------------------------------------------------------- /KinectWebServer/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Kinect; 2 | using Newtonsoft.Json; 3 | using SuperSocket.SocketBase.Config; 4 | using SuperWebSocket; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Windows.Media; 10 | using System.Windows.Media.Imaging; 11 | 12 | namespace KinectWebServer 13 | { 14 | public class JointEx 15 | { 16 | public Joint Joint { get; set; } 17 | public ColorSpacePoint ColorSpacePos { get; set; } 18 | }; 19 | 20 | public class ColorFrameData 21 | { 22 | public byte[] Data { get; set; } 23 | public ColorImageFormat Format { get; set; } 24 | } 25 | 26 | class Program 27 | { 28 | static KinectSensor ks; 29 | static MultiSourceFrameReader msfr; 30 | static WebSocketServer appServer; 31 | static ColorFrameData colorData = new ColorFrameData(); 32 | static byte[] encodedBytes; 33 | static Body[] bodies; 34 | static List trackedBodies = new List(); 35 | static List> mappedJoints = new List>(); 36 | static CameraSpacePoint[] cameraTempPoint = new CameraSpacePoint[1]; 37 | static ColorSpacePoint[] colorTempPoint = new ColorSpacePoint[1]; 38 | const int NumJoints = 25; 39 | static ColorSpacePoint[] colorTempPoints = new ColorSpacePoint[NumJoints]; 40 | static List bodyTransferData = new List(); 41 | static void Main(string[] args) 42 | { 43 | Console.WriteLine("Press any key to start the WebSocketServer!"); 44 | 45 | Console.ReadKey(); 46 | Console.WriteLine(); 47 | 48 | ks = KinectSensor.GetDefault(); 49 | 50 | var fd = ks.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); 51 | uint frameSize = fd.BytesPerPixel * fd.LengthInPixels; 52 | colorData.Data = new byte[frameSize]; 53 | colorData.Format = ColorImageFormat.Bgra; 54 | 55 | msfr = ks.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.Color); 56 | 57 | msfr.MultiSourceFrameArrived += msfr_MultiSourceFrameArrived; 58 | 59 | bodies = new Body[ks.BodyFrameSource.BodyCount]; 60 | ks.Open(); 61 | 62 | appServer = new WebSocketServer(); 63 | 64 | var config = new ServerConfig(); 65 | config.Name = "kinect"; 66 | config.Port = 2012; 67 | config.MaxRequestLength = (int)frameSize; 68 | 69 | // Setup the appServer 70 | if (!appServer.Setup(config)) //Setup with listening port 71 | { 72 | Console.WriteLine("Failed to setup!"); 73 | Console.ReadKey(); 74 | return; 75 | } 76 | 77 | Console.WriteLine(); 78 | 79 | // Try to start the appServer 80 | if (!appServer.Start()) 81 | { 82 | Console.WriteLine("Failed to start!"); 83 | Console.ReadKey(); 84 | return; 85 | } 86 | 87 | Console.WriteLine("The server started successfully, press key 'q' to stop it!"); 88 | 89 | while (Console.ReadKey().KeyChar != 'q') 90 | { 91 | Console.WriteLine(); 92 | continue; 93 | } 94 | 95 | //Stop the appServer 96 | appServer.Stop(); 97 | 98 | Console.WriteLine(); 99 | Console.WriteLine("The server was stopped!"); 100 | Console.ReadKey(); 101 | } 102 | 103 | static void msfr_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) 104 | { 105 | if (e.FrameReference == null) 106 | return; 107 | var multiFrame = e.FrameReference.AcquireFrame(); 108 | if (multiFrame == null) 109 | return; 110 | 111 | bool colorRead = false; 112 | FrameDescription fd = null; 113 | if (multiFrame.ColorFrameReference != null) 114 | { 115 | using (var cf = multiFrame.ColorFrameReference.AcquireFrame()) 116 | { 117 | fd = cf.ColorFrameSource.FrameDescription; 118 | cf.CopyConvertedFrameDataToArray(colorData.Data, colorData.Format); 119 | colorRead = true; 120 | } 121 | } 122 | bool bodyRead = false; 123 | if (multiFrame.BodyFrameReference != null) 124 | { 125 | using (var bf = multiFrame.BodyFrameReference.AcquireFrame()) 126 | { 127 | bf.GetAndRefreshBodyData(bodies); 128 | bodyRead = true; 129 | } 130 | } 131 | 132 | byte[] data = null; 133 | if (colorRead == true) 134 | { 135 | data = SendColorData(colorData, fd); 136 | } 137 | string bodyData = null; 138 | if (bodyRead == true) 139 | { 140 | bodyData = SerialiseBodyData(); 141 | } 142 | 143 | var sessions = appServer.GetAllSessions(); 144 | if (sessions.Count() < 1) 145 | return; 146 | 147 | foreach (var session in sessions) 148 | { 149 | if (data != null) 150 | { 151 | session.Send(data, 0, data.Length); 152 | } 153 | if (bodyData != null) 154 | { 155 | session.Send(bodyData); 156 | } 157 | } 158 | } 159 | 160 | private static string SerialiseBodyData() 161 | { 162 | trackedBodies = bodies.Where(b => b.IsTracked == true).ToList(); 163 | if (trackedBodies.Count() < 1) 164 | return null; 165 | 166 | bodyTransferData.Clear(); 167 | foreach (var body in trackedBodies) 168 | { 169 | var list = body.Joints.Select(j => j.Value).Select(p => p.Position).ToArray(); 170 | ks.CoordinateMapper.MapCameraPointsToColorSpace(list, colorTempPoints); 171 | bodyTransferData.Add(colorTempPoints); 172 | } 173 | 174 | var str = JsonConvert.SerializeObject(bodyTransferData); 175 | return str; 176 | } 177 | 178 | private static byte[] SendColorData(ColorFrameData data, FrameDescription fd) 179 | { 180 | if (data == null) 181 | return null; 182 | 183 | var dpiX = 96.0; 184 | var dpiY = 96.0; 185 | var pixelFormat = PixelFormats.Bgra32; 186 | var bytesPerPixel = (pixelFormat.BitsPerPixel) / 8; 187 | var stride = bytesPerPixel * fd.Width; 188 | 189 | var bitmap = BitmapSource.Create(fd.Width, fd.Height, dpiX, dpiY, 190 | pixelFormat, null, data.Data, (int)stride); 191 | var encoder = new JpegBitmapEncoder(); 192 | encoder.Frames.Add(BitmapFrame.Create(bitmap)); 193 | 194 | using (var ms = new MemoryStream()) 195 | using (var br = new BinaryReader(ms)) 196 | { 197 | encoder.Save(ms); 198 | ms.Flush(); 199 | ms.Position = 0; 200 | encodedBytes = br.ReadBytes((int)ms.Length); 201 | } 202 | 203 | return encodedBytes; 204 | } 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /KinectWebServer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("KinectWebServer")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("KinectWebServer")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9d77582a-92d4-4fa1-b068-36b0acda129a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /KinectWebServer/TestPage.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /KinectWebServer/TestSite/TestPage.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /KinectWebServer/TestSite/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /KinectWebServer/TestSite/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /KinectWebServer/TestSite/kinect.js: -------------------------------------------------------------------------------- 1 | var socket; 2 | var myImage; 3 | var context; 4 | var feed; 5 | 6 | document.addEventListener("DOMContentLoaded", function (event) { 7 | context = document.getElementById("myCanvas").getContext("2d"); 8 | 9 | feed = new Image(); 10 | feed.onload = function () { 11 | context.drawImage(feed, 0, 0); 12 | }; 13 | 14 | myImage = document.getElementById('myImg'); 15 | console.log('about to open socket'); 16 | socket = new WebSocket('ws://localhost:2012/kinect'); 17 | console.log('attempted to open socket'); 18 | 19 | socket.onopen = function () { 20 | console.log('socket opened'); 21 | }; 22 | socket.onclose = function () { 23 | console.log('socket closed'); 24 | }; 25 | socket.onerror = function (err) { 26 | console.log('error - ' + err); 27 | }; 28 | socket.onmessage = function (event) { 29 | var colData = window.URL.createObjectURL(event.Data); 30 | feed.src = colData; 31 | window.URL.revokeObjectURL(colData); 32 | }; 33 | }); -------------------------------------------------------------------------------- /KinectWebServer/kinect.js: -------------------------------------------------------------------------------- 1 | var socket; 2 | var myImage; 3 | var context; 4 | var feed; 5 | 6 | document.addEventListener("DOMContentLoaded", function (event) { 7 | context = document.getElementById("myCanvas").getContext("2d"); 8 | 9 | feed = new Image(); 10 | feed.onload = function () { 11 | context.drawImage(feed, 0, 0); 12 | }; 13 | 14 | myImage = document.getElementById('myImg'); 15 | console.log('about to open socket'); 16 | socket = new WebSocket('ws://localhost:2012/kinect'); 17 | console.log('attempted to open socket'); 18 | 19 | socket.onopen = function () { 20 | console.log('socket opened'); 21 | }; 22 | socket.onclose = function () { 23 | console.log('socket closed'); 24 | }; 25 | socket.onerror = function (err) { 26 | console.log('error - ' + err); 27 | }; 28 | socket.onmessage = function (event) { 29 | var colData = window.URL.createObjectURL(event.Data); 30 | feed.src = colData; 31 | window.URL.revokeObjectURL(colData); 32 | }; 33 | }); -------------------------------------------------------------------------------- /KinectWebServer/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kinectv2-webserver 2 | -------------------------------------------------------------------------------- /TestSite/TestPage.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /TestSite/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /TestSite/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /TestSite/kinect.js: -------------------------------------------------------------------------------- 1 | var socket; 2 | var myImage; 3 | var context; 4 | var feed; 5 | var canvasWidth; 6 | var canvasHeight; 7 | 8 | document.addEventListener("DOMContentLoaded", function (event) { 9 | var canvas = document.getElementById("myCanvas"); 10 | canvasWidth = canvas.width; 11 | canvasHeight = canvas.height; 12 | context = canvas.getContext("2d"); 13 | context.fillStyle = "#31B131"; 14 | 15 | feed = new Image(); 16 | feed.onload = function () { 17 | context.drawImage(feed, 0, 0); 18 | }; 19 | 20 | myImage = document.getElementById('myImg'); 21 | console.log('about to open socket'); 22 | socket = new WebSocket('ws://localhost:2012/kinect'); 23 | console.log('attempted to open socket'); 24 | 25 | socket.onopen = function () { 26 | console.log('socket opened'); 27 | }; 28 | socket.onclose = function () { 29 | console.log('socket closed'); 30 | }; 31 | socket.onerror = function (err) { 32 | console.log('error - ' + err); 33 | }; 34 | socket.onmessage = function (event) { 35 | //context.clearRect(0, 0, canvasWidth, canvasHeight); 36 | if (event.data instanceof Blob) { 37 | var colData = window.URL.createObjectURL(event.data); 38 | feed.src = colData; 39 | window.URL.revokeObjectURL(colData); 40 | } else { 41 | var bodies = JSON.parse(event.data); 42 | for (var i = 0; i < bodies.length; i++) { 43 | var jointDictionary = bodies[i]; 44 | for (var joint in jointDictionary) { 45 | var jnt = jointDictionary[joint]; 46 | var x = jnt.X; 47 | var y = jnt.Y; 48 | context.fillRect(x - 8, y - 8, 16, 16); 49 | } 50 | } 51 | } 52 | }; 53 | }); --------------------------------------------------------------------------------