├── .gitignore ├── App.config ├── App.xaml ├── App.xaml.cs ├── KinectV2OSC.csproj ├── KinectV2OSC.sln ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Model ├── Drawing │ ├── FrameTimer.cs │ ├── KinectCanvas.cs │ ├── KinectMapper.cs │ └── Renderers │ │ ├── BackgroundRenderer.cs │ │ ├── EdgeRenderer.cs │ │ ├── HandsRenderer.cs │ │ ├── JointsRenderer.cs │ │ ├── Renderer.cs │ │ └── SkeletonRenderer.cs ├── Inspector.cs └── Network │ ├── BodySender.cs │ └── MessageBuilder.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── README.md ├── config.png ├── kinect.jpg ├── packages.config └── screenshot.png /.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 | [Rr]eleases/ 14 | x64/ 15 | x86/ 16 | build/ 17 | bld/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | 21 | # Roslyn cache directories 22 | *.ide/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | 28 | #NUNIT 29 | *.VisualState.xml 30 | TestResult.xml 31 | 32 | # Build Results of an ATL Project 33 | [Dd]ebugPS/ 34 | [Rr]eleasePS/ 35 | dlldata.c 36 | 37 | *_i.c 38 | *_p.c 39 | *_i.h 40 | *.ilk 41 | *.meta 42 | *.obj 43 | *.pch 44 | *.pdb 45 | *.pgc 46 | *.pgd 47 | *.rsp 48 | *.sbr 49 | *.tlb 50 | *.tli 51 | *.tlh 52 | *.tmp 53 | *.tmp_proj 54 | *.log 55 | *.vspscc 56 | *.vssscc 57 | .builds 58 | *.pidb 59 | *.svclog 60 | *.scc 61 | 62 | # Chutzpah Test files 63 | _Chutzpah* 64 | 65 | # Visual C++ cache files 66 | ipch/ 67 | *.aps 68 | *.ncb 69 | *.opensdf 70 | *.sdf 71 | *.cachefile 72 | 73 | # Visual Studio profiler 74 | *.psess 75 | *.vsp 76 | *.vspx 77 | 78 | # TFS 2012 Local Workspace 79 | $tf/ 80 | 81 | # Guidance Automation Toolkit 82 | *.gpState 83 | 84 | # ReSharper is a .NET coding add-in 85 | _ReSharper*/ 86 | *.[Rr]e[Ss]harper 87 | *.DotSettings.user 88 | 89 | # JustCode is a .NET coding addin-in 90 | .JustCode 91 | 92 | # TeamCity is a build add-in 93 | _TeamCity* 94 | 95 | # DotCover is a Code Coverage Tool 96 | *.dotCover 97 | 98 | # NCrunch 99 | _NCrunch_* 100 | .*crunch*.local.xml 101 | 102 | # MightyMoose 103 | *.mm.* 104 | AutoTest.Net/ 105 | 106 | # Web workbench (sass) 107 | .sass-cache/ 108 | 109 | # Installshield output folder 110 | [Ee]xpress/ 111 | 112 | # DocProject is a documentation generator add-in 113 | DocProject/buildhelp/ 114 | DocProject/Help/*.HxT 115 | DocProject/Help/*.HxC 116 | DocProject/Help/*.hhc 117 | DocProject/Help/*.hhk 118 | DocProject/Help/*.hhp 119 | DocProject/Help/Html2 120 | DocProject/Help/html 121 | 122 | # Click-Once directory 123 | publish/ 124 | 125 | # Publish Web Output 126 | *.[Pp]ublish.xml 127 | *.azurePubxml 128 | # TODO: Comment the next line if you want to checkin your web deploy settings 129 | # but database connection strings (with potential passwords) will be unencrypted 130 | *.pubxml 131 | 132 | # NuGet Packages 133 | *.nupkg 134 | # The packages folder can be ignored because of Package Restore 135 | **/packages/* 136 | # except build/, which is used as an MSBuild target. 137 | !**/packages/build/ 138 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 139 | #!**/packages/repositories.config 140 | 141 | # Windows Azure Build Output 142 | csx/ 143 | *.build.csdef 144 | 145 | # Windows Store app package directory 146 | AppPackages/ 147 | 148 | # Others 149 | sql/ 150 | *.Cache 151 | ClientBin/ 152 | [Ss]tyle[Cc]op.* 153 | ~$* 154 | *~ 155 | *.dbmdl 156 | *.dbproj.schemaview 157 | *.pfx 158 | *.publishsettings 159 | node_modules/ 160 | 161 | # RIA/Silverlight projects 162 | Generated_Code/ 163 | 164 | # Backup & report files from converting an old project file 165 | # to a newer Visual Studio version. Backup files are not needed, 166 | # because we have git ;-) 167 | _UpgradeReport_Files/ 168 | Backup*/ 169 | UpgradeLog*.XML 170 | UpgradeLog*.htm 171 | 172 | # SQL Server files 173 | *.mdf 174 | *.ldf 175 | 176 | # Business Intelligence projects 177 | *.rdl.data 178 | *.bim.layout 179 | *.bim_*.settings 180 | 181 | # Microsoft Fakes 182 | FakesAssemblies/ -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /App.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /App.xaml.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | namespace KinectV2OSC 8 | { 9 | using System; 10 | using System.Windows; 11 | 12 | /// 13 | /// Interaction logic for App 14 | /// 15 | public partial class App : Application 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /KinectV2OSC.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {269A7B21-FBFE-4E7A-8BBE-C8DE2EC0D833} 8 | WinExe 9 | Properties 10 | KinectV2OSC 11 | KinectV2OSC 12 | v4.5 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | 17 | 18 | true 19 | DEBUG;TRACE 20 | full 21 | $(SolutionDir)bin\$(Platform)\$(Configuration)\ 22 | x64 23 | prompt 24 | MinimumRecommendedRules.ruleset 25 | true 26 | 27 | 28 | TRACE 29 | true 30 | pdbonly 31 | $(SolutionDir)bin\$(Platform)\$(Configuration)\ 32 | x64 33 | prompt 34 | MinimumRecommendedRules.ruleset 35 | true 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | OnBuildSuccess 47 | 48 | 49 | 50 | $(KINECTSDK20_DIR)\Assemblies\Microsoft.Kinect.dll 51 | 52 | 53 | packages\Rug.Osc.1.2.5\lib\Rug.Osc.dll 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 4.0 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | MSBuild:Compile 72 | Designer 73 | 74 | 75 | MSBuild:Compile 76 | Designer 77 | 78 | 79 | App.xaml 80 | Code 81 | 82 | 83 | MainWindow.xaml 84 | Code 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | Code 102 | 103 | 104 | True 105 | True 106 | Resources.resx 107 | 108 | 109 | True 110 | Settings.settings 111 | True 112 | 113 | 114 | ResXFileCodeGenerator 115 | Resources.Designer.cs 116 | Designer 117 | 118 | 119 | 120 | SettingsSingleFileGenerator 121 | Settings.Designer.cs 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 136 | -------------------------------------------------------------------------------- /KinectV2OSC.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2013 for Windows Desktop 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KinectV2OSC", "KinectV2OSC.csproj", "{269A7B21-FBFE-4E7A-8BBE-C8DE2EC0D833}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {269A7B21-FBFE-4E7A-8BBE-C8DE2EC0D833}.Debug|x64.ActiveCfg = Debug|x64 15 | {269A7B21-FBFE-4E7A-8BBE-C8DE2EC0D833}.Debug|x64.Build.0 = Debug|x64 16 | {269A7B21-FBFE-4E7A-8BBE-C8DE2EC0D833}.Release|x64.ActiveCfg = Release|x64 17 | {269A7B21-FBFE-4E7A-8BBE-C8DE2EC0D833}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace KinectV2OSC 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel; 6 | using System.Diagnostics; 7 | using System.Globalization; 8 | using System.IO; 9 | using System.Windows; 10 | using System.Windows.Media; 11 | using System.Windows.Media.Imaging; 12 | using Microsoft.Kinect; 13 | using Model.Drawing; 14 | using Model.Network; 15 | 16 | /// 17 | /// Interaction logic for MainWindow 18 | /// 19 | public partial class MainWindow : Window, INotifyPropertyChanged 20 | { 21 | private DrawingImage imageSource; 22 | private KinectSensor kinectSensor; 23 | private BodyFrameReader bodyFrameReader; 24 | private Body[] bodies; 25 | private FrameTimer timer; 26 | private KinectCanvas kinectCanvas; 27 | private BodySender bodySender; 28 | 29 | public event PropertyChangedEventHandler PropertyChanged; 30 | 31 | public ImageSource ImageSource 32 | { 33 | get { return this.imageSource; } 34 | } 35 | 36 | private string framesText; 37 | public string FramesText 38 | { 39 | get { return this.framesText; } 40 | set 41 | { 42 | this.framesText = value; 43 | if (this.PropertyChanged != null) 44 | { 45 | this.PropertyChanged(this, new PropertyChangedEventArgs("FramesText")); 46 | } 47 | } 48 | } 49 | 50 | private string uptimeText; 51 | public string UptimeText 52 | { 53 | get { return this.uptimeText; } 54 | set 55 | { 56 | this.uptimeText = value; 57 | if (this.PropertyChanged != null) 58 | { 59 | this.PropertyChanged(this, new PropertyChangedEventArgs("UptimeText")); 60 | } 61 | } 62 | } 63 | 64 | private string oscText; 65 | public string OscText 66 | { 67 | get { return this.oscText; } 68 | set 69 | { 70 | this.oscText = value; 71 | if (this.PropertyChanged != null) 72 | { 73 | this.PropertyChanged(this, new PropertyChangedEventArgs("OscText")); 74 | } 75 | } 76 | } 77 | 78 | public MainWindow() 79 | { 80 | this.timer = new FrameTimer(); 81 | this.InitKinect(); 82 | this.InitNetwork(); 83 | this.InitWindowObjectAsViewModel(); 84 | } 85 | 86 | private void InitKinect() 87 | { 88 | Size displaySize = new Size(0, 0); 89 | this.kinectSensor = KinectSensor.GetDefault(); 90 | 91 | if (this.kinectSensor != null) 92 | { 93 | this.kinectSensor.Open(); 94 | 95 | var frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription; 96 | displaySize.Width= frameDescription.Width; 97 | displaySize.Height = frameDescription.Height; 98 | 99 | this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); 100 | 101 | this.UptimeText = Properties.Resources.InitializingStatusTextFormat; 102 | } 103 | else 104 | { 105 | this.UptimeText = Properties.Resources.NoSensorFoundText; 106 | } 107 | 108 | this.kinectCanvas = new KinectCanvas(this.kinectSensor, displaySize); 109 | } 110 | 111 | private void InitNetwork() 112 | { 113 | var ipAddress = ReadIpAddressCsv(); 114 | var port = Properties.Resources.PortNumber; 115 | this.bodySender = new BodySender(ipAddress, port); 116 | } 117 | 118 | private void InitWindowObjectAsViewModel() 119 | { 120 | this.imageSource = this.kinectCanvas.GetDrawingImage(); 121 | this.DataContext = this; 122 | this.InitializeComponent(); 123 | } 124 | 125 | private string ReadIpAddressCsv() 126 | { 127 | string ipAddressCsv; 128 | try 129 | { 130 | System.IO.TextReader file = new StreamReader(Properties.Resources.IpAddressFileName); 131 | ipAddressCsv = file.ReadLine(); 132 | file.Close(); 133 | file = null; 134 | } 135 | catch(Exception) 136 | { 137 | ipAddressCsv = Properties.Resources.DefaultIpAddressCsv; 138 | } 139 | return ipAddressCsv; 140 | } 141 | 142 | private void MainWindow_Loaded(object sender, RoutedEventArgs e) 143 | { 144 | if (this.bodyFrameReader != null) 145 | { 146 | this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived; 147 | } 148 | } 149 | 150 | private void MainWindow_Closing(object sender, CancelEventArgs e) 151 | { 152 | if (this.bodyFrameReader != null) 153 | { 154 | this.bodyFrameReader.Dispose(); 155 | this.bodyFrameReader = null; 156 | } 157 | 158 | if (this.kinectSensor != null) 159 | { 160 | this.kinectSensor.Close(); 161 | this.kinectSensor = null; 162 | } 163 | } 164 | 165 | private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e) 166 | { 167 | var frameReference = e.FrameReference; 168 | 169 | try 170 | { 171 | var frame = frameReference.AcquireFrame(); 172 | 173 | if (frame != null) 174 | { 175 | using (frame) 176 | { 177 | this.timer.AddFrame(frameReference); 178 | this.setStatusText(); 179 | this.updateBodies(frame); 180 | this.kinectCanvas.Draw(this.bodies); 181 | this.bodySender.Send(this.bodies); 182 | } 183 | } 184 | } 185 | catch (Exception) 186 | { 187 | Console.WriteLine("Frame exception encountered..."); 188 | } 189 | } 190 | 191 | private void setStatusText() 192 | { 193 | var framesPerSecond = timer.GetFramesPerSecond(); 194 | var runningTime = timer.GetRunningTime(); 195 | this.FramesText = string.Format(Properties.Resources.StandardFramesTextFormat, framesPerSecond); 196 | this.UptimeText = string.Format(Properties.Resources.StandardUptimeTextFormat, runningTime); 197 | this.OscText = bodySender.GetStatusText(); 198 | } 199 | 200 | private void updateBodies(BodyFrame frame) 201 | { 202 | if (this.bodies == null) 203 | { 204 | this.bodies = new Body[frame.BodyCount]; 205 | } 206 | 207 | // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array. 208 | // As long as those body objects are not disposed and not set to null in the array, 209 | // those body objects will be re-used. 210 | frame.GetAndRefreshBodyData(this.bodies); 211 | } 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /Model/Drawing/FrameTimer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using Microsoft.Kinect; 14 | 15 | namespace KinectV2OSC.Model.Drawing 16 | { 17 | public class FrameTimer 18 | { 19 | private BodyFrameReference currentFrame; 20 | private uint framesSinceUpdate = 0; 21 | private double framesPerSecond; 22 | private bool isFirstFrame; 23 | 24 | private Stopwatch stopwatch; 25 | private TimeSpan startTime; 26 | private DateTime nextUpdateTime = DateTime.MinValue; 27 | 28 | public FrameTimer() 29 | { 30 | this.stopwatch = new Stopwatch(); 31 | this.isFirstFrame = true; 32 | } 33 | 34 | public void AddFrame(BodyFrameReference frame) 35 | { 36 | this.currentFrame = frame; 37 | this.framesSinceUpdate++; 38 | this.InitStartTimeOnFirstFrame(); 39 | 40 | if (this.IsReadyForUpdate()) 41 | { 42 | this.PerformUpdate(); 43 | this.SetNextUpdateTime(); 44 | } 45 | 46 | this.InitStopwatchOnFirstFrame(); 47 | this.SetFirstFramePassed(); 48 | } 49 | 50 | public double GetFramesPerSecond() 51 | { 52 | return this.framesPerSecond; 53 | } 54 | 55 | public TimeSpan GetRunningTime() 56 | { 57 | return this.currentFrame.RelativeTime - this.startTime; 58 | } 59 | 60 | private void InitStartTimeOnFirstFrame() 61 | { 62 | if (this.isFirstFrame) 63 | { 64 | this.startTime = this.currentFrame.RelativeTime; 65 | } 66 | } 67 | 68 | private void InitStopwatchOnFirstFrame() 69 | { 70 | if(this.isFirstFrame) 71 | { 72 | this.stopwatch.Start(); 73 | } 74 | } 75 | 76 | private void SetFirstFramePassed() 77 | { 78 | this.isFirstFrame = false; 79 | } 80 | 81 | private bool IsReadyForUpdate() 82 | { 83 | return DateTime.Now >= this.nextUpdateTime; 84 | } 85 | 86 | private void PerformUpdate() 87 | { 88 | framesPerSecond = 0.0; 89 | 90 | if (this.stopwatch.IsRunning) 91 | { 92 | this.stopwatch.Stop(); 93 | this.LogFramesPerSecond(); 94 | this.stopwatch.Reset(); 95 | this.stopwatch.Start(); 96 | } 97 | } 98 | 99 | private void SetNextUpdateTime() 100 | { 101 | this.nextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(1); 102 | } 103 | 104 | private void LogFramesPerSecond() 105 | { 106 | this.framesPerSecond = this.framesSinceUpdate / this.stopwatch.Elapsed.TotalSeconds; 107 | this.framesSinceUpdate = 0; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Model/Drawing/KinectCanvas.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using Microsoft.Kinect; 14 | using KinectV2OSC.Model.Drawing.Renderers; 15 | 16 | namespace KinectV2OSC.Model.Drawing 17 | { 18 | /// 19 | /// Draw 2D shapes from Kinect into a drawing group 20 | /// 21 | public class KinectCanvas 22 | { 23 | private KinectSensor kinectSensor; 24 | private KinectMapper mapper; 25 | private Size displaySize; 26 | 27 | private DrawingGroup drawingGroup; 28 | private BackgroundRenderer backgroundRenderer; 29 | private SkeletonRenderer skeletonRenderer; 30 | private JointsRenderer jointsRenderer; 31 | private HandsRenderer handsRenderer; 32 | private EdgeRenderer edgeRenderer; 33 | 34 | public KinectCanvas(KinectSensor kinectSensor, Size displaySize) 35 | { 36 | this.kinectSensor = kinectSensor; 37 | this.mapper = new KinectMapper(kinectSensor); 38 | this.displaySize = displaySize; 39 | 40 | this.drawingGroup = new DrawingGroup(); 41 | this.backgroundRenderer = new BackgroundRenderer(displaySize); 42 | this.skeletonRenderer = new SkeletonRenderer(displaySize); 43 | this.jointsRenderer = new JointsRenderer(displaySize); 44 | this.handsRenderer = new HandsRenderer(displaySize); 45 | this.edgeRenderer = new EdgeRenderer(displaySize); 46 | } 47 | 48 | public void Draw(Body[] bodies) 49 | { 50 | using (var drawingContext = this.drawingGroup.Open()) 51 | { 52 | this.DrawBackground(drawingContext); 53 | this.DrawAllTracked(bodies, drawingContext); 54 | this.PreventDrawingOutsideCanvas(); 55 | } 56 | } 57 | 58 | public DrawingImage GetDrawingImage() 59 | { 60 | return new DrawingImage(this.drawingGroup); 61 | } 62 | 63 | private void DrawBackground(DrawingContext drawingContext) 64 | { 65 | this.backgroundRenderer.Update(drawingContext); 66 | this.backgroundRenderer.Draw(); 67 | } 68 | 69 | private void DrawAllTracked(Body[] bodies, DrawingContext drawingContext) 70 | { 71 | foreach (Body body in bodies) 72 | { 73 | if (body.IsTracked) 74 | { 75 | var points = mapper.JointsTo2DPoints(body); 76 | 77 | this.edgeRenderer.Update(drawingContext, body, points); 78 | this.skeletonRenderer.Update(drawingContext, body, points); 79 | this.jointsRenderer.Update(drawingContext, body, points); 80 | this.handsRenderer.Update(drawingContext, body, points); 81 | 82 | this.edgeRenderer.Draw(); 83 | this.skeletonRenderer.Draw(); 84 | this.jointsRenderer.Draw(); 85 | this.handsRenderer.Draw(); 86 | } 87 | } 88 | } 89 | 90 | private void PreventDrawingOutsideCanvas() 91 | { 92 | this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displaySize.Width, this.displaySize.Height)); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Model/Drawing/KinectMapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using Microsoft.Kinect; 14 | 15 | namespace KinectV2OSC.Model.Drawing 16 | { 17 | public class KinectMapper 18 | { 19 | private KinectSensor kinectSensor; 20 | 21 | public KinectMapper(KinectSensor kinectSensor) 22 | { 23 | this.kinectSensor = kinectSensor; 24 | } 25 | 26 | public IReadOnlyDictionary JointsTo2DPoints(Body body) 27 | { 28 | var joints = body.Joints; 29 | var points = new Dictionary(); 30 | 31 | foreach (JointType jointType in joints.Keys) 32 | { 33 | var depthSpacePoint = this.kinectSensor.CoordinateMapper.MapCameraPointToDepthSpace(joints[jointType].Position); 34 | points[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y); 35 | } 36 | 37 | return points; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Model/Drawing/Renderers/BackgroundRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using Microsoft.Kinect; 14 | 15 | namespace KinectV2OSC.Model.Drawing.Renderers 16 | { 17 | /// 18 | /// Draw 2D shapes representing a background into a drawing context 19 | /// 20 | public class BackgroundRenderer : Renderer 21 | { 22 | public BackgroundRenderer(Size displaySize) : base(displaySize) { } 23 | 24 | public void Update(DrawingContext drawingContext) 25 | { 26 | this.drawingContext = drawingContext; 27 | } 28 | 29 | public override void Draw() 30 | { 31 | this.drawingContext.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, this.displaySize.Width, this.displaySize.Height)); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Model/Drawing/Renderers/EdgeRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using Microsoft.Kinect; 14 | 15 | namespace KinectV2OSC.Model.Drawing.Renderers 16 | { 17 | /// 18 | /// Draw 2D shapes representing edge boundaries into a drawing context 19 | /// 20 | public class EdgeRenderer : Renderer 21 | { 22 | private const double HandSize = 30; 23 | private const double JointThickness = 3; 24 | private const double ClipBoundsThickness = 10; 25 | 26 | public EdgeRenderer(Size displaySize) : base(displaySize) { } 27 | 28 | public override void Draw() 29 | { 30 | this.DrawTop(body.ClippedEdges); 31 | this.DrawRight(body.ClippedEdges); 32 | this.DrawBottom(body.ClippedEdges); 33 | this.DrawLeft(body.ClippedEdges); 34 | } 35 | 36 | private void DrawTop(FrameEdges clippedEdges) 37 | { 38 | if (clippedEdges.HasFlag(FrameEdges.Top)) 39 | { 40 | var rect = new Rect(0, 0, this.displaySize.Width, ClipBoundsThickness); 41 | drawingContext.DrawRectangle(Brushes.Red, null, rect); 42 | } 43 | } 44 | 45 | private void DrawRight(FrameEdges clippedEdges) 46 | { 47 | if (clippedEdges.HasFlag(FrameEdges.Right)) 48 | { 49 | var rect = new Rect(this.displaySize.Width - ClipBoundsThickness, 0, ClipBoundsThickness, this.displaySize.Height); 50 | drawingContext.DrawRectangle(Brushes.Red, null, rect); 51 | } 52 | } 53 | 54 | private void DrawBottom(FrameEdges clippedEdges) 55 | { 56 | if (clippedEdges.HasFlag(FrameEdges.Bottom)) 57 | { 58 | var rect = new Rect(0, this.displaySize.Height - ClipBoundsThickness, this.displaySize.Width, ClipBoundsThickness); 59 | drawingContext.DrawRectangle(Brushes.Red, null, rect); 60 | } 61 | } 62 | 63 | private void DrawLeft(FrameEdges clippedEdges) 64 | { 65 | if (clippedEdges.HasFlag(FrameEdges.Left)) 66 | { 67 | var rect = new Rect(0, 0, ClipBoundsThickness, this.displaySize.Height); 68 | drawingContext.DrawRectangle(Brushes.Red, null, rect); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Model/Drawing/Renderers/HandsRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using Microsoft.Kinect; 14 | 15 | namespace KinectV2OSC.Model.Drawing.Renderers 16 | { 17 | /// 18 | /// Draw 2D shapes representing human hands into a drawing context 19 | /// 20 | public class HandsRenderer : Renderer 21 | { 22 | private const double HandSize = 20; 23 | 24 | private readonly Brush handClosedBrush = new SolidColorBrush(Color.FromArgb(128, 255, 255, 0)); 25 | private readonly Brush handOpenBrush = new SolidColorBrush(Color.FromArgb(128, 0, 255, 255)); 26 | private readonly Brush handLassoBrush = new SolidColorBrush(Color.FromArgb(128, 255, 0, 255)); 27 | 28 | public HandsRenderer(Size displaySize) : base(displaySize) { } 29 | 30 | public override void Draw() 31 | { 32 | this.DrawHand(body.HandLeftState, drawingPoints[JointType.HandLeft]); 33 | this.DrawHand(body.HandRightState, drawingPoints[JointType.HandRight]); 34 | } 35 | 36 | private void DrawHand(HandState handState, Point handPosition) 37 | { 38 | switch (handState) 39 | { 40 | case HandState.Closed: 41 | drawingContext.DrawEllipse(this.handClosedBrush, null, handPosition, HandSize, HandSize); 42 | break; 43 | 44 | case HandState.Open: 45 | drawingContext.DrawEllipse(this.handOpenBrush, null, handPosition, HandSize, HandSize); 46 | break; 47 | 48 | case HandState.Lasso: 49 | drawingContext.DrawEllipse(this.handLassoBrush, null, handPosition, HandSize, HandSize); 50 | break; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Model/Drawing/Renderers/JointsRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using Microsoft.Kinect; 14 | 15 | namespace KinectV2OSC.Model.Drawing.Renderers 16 | { 17 | /// 18 | /// Draw 2D shapes representing human joints into a drawing context 19 | /// 20 | public class JointsRenderer : Renderer 21 | { 22 | private const double JointThickness = 6; 23 | private readonly Brush trackedJointBrush = Brushes.Green; 24 | private readonly Brush inferredJointBrush = Brushes.LightGreen; 25 | 26 | public JointsRenderer(Size displaySize) : base(displaySize) { } 27 | 28 | public override void Draw() 29 | { 30 | foreach (JointType jointType in joints.Keys) 31 | { 32 | var brush = this.ChooseBrush(jointType); 33 | 34 | if (brush != null) 35 | { 36 | drawingContext.DrawEllipse(brush, null, drawingPoints[jointType], JointThickness, JointThickness); 37 | } 38 | } 39 | } 40 | 41 | private Brush ChooseBrush(JointType jointType) 42 | { 43 | Brush brush = null; 44 | var trackingState = joints[jointType].TrackingState; 45 | 46 | if (trackingState == TrackingState.Tracked) 47 | { 48 | brush = this.trackedJointBrush; 49 | } 50 | else if (trackingState == TrackingState.Inferred) 51 | { 52 | brush = this.inferredJointBrush; 53 | } 54 | 55 | return brush; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Model/Drawing/Renderers/Renderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using Microsoft.Kinect; 14 | 15 | namespace KinectV2OSC.Model.Drawing.Renderers 16 | { 17 | public abstract class Renderer 18 | { 19 | protected DrawingContext drawingContext; 20 | 21 | protected Body body; 22 | protected Inspector inspector; 23 | protected IReadOnlyDictionary joints; 24 | protected IReadOnlyDictionary drawingPoints; 25 | 26 | protected Size displaySize; 27 | 28 | public Renderer(Size displaySize) 29 | { 30 | this.inspector = new Inspector(); 31 | this.displaySize = displaySize; 32 | } 33 | 34 | public void Update(DrawingContext drawingContext, Body body, IReadOnlyDictionary drawingPoints) 35 | { 36 | this.drawingContext = drawingContext; 37 | this.body = body; 38 | this.joints = body.Joints; 39 | this.drawingPoints = drawingPoints; 40 | } 41 | 42 | public abstract void Draw(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Model/Drawing/Renderers/SkeletonRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using Microsoft.Kinect; 14 | 15 | namespace KinectV2OSC.Model.Drawing.Renderers 16 | { 17 | /// 18 | /// Draw 2D shapes representing a skeleton into a drawing context 19 | /// 20 | public class SkeletonRenderer : Renderer 21 | { 22 | private readonly Pen trackedBonePen = new Pen(Brushes.Aqua, 8); 23 | private readonly Pen inferredBonePen = new Pen(Brushes.MediumAquamarine, 2); 24 | 25 | public SkeletonRenderer(Size displaySize) : base(displaySize) { } 26 | 27 | public override void Draw() 28 | { 29 | this.DrawTorso(); 30 | this.DrawRightArm(); 31 | this.DrawLeftArm(); 32 | this.DrawRightLeg(); 33 | this.DrawLeftLeg(); 34 | } 35 | 36 | private void DrawTorso() 37 | { 38 | this.DrawBone(JointType.Head, JointType.Neck); 39 | this.DrawBone(JointType.Neck, JointType.SpineShoulder); 40 | this.DrawBone(JointType.SpineShoulder, JointType.SpineMid); 41 | this.DrawBone(JointType.SpineMid, JointType.SpineBase); 42 | this.DrawBone(JointType.SpineShoulder, JointType.ShoulderRight); 43 | this.DrawBone(JointType.SpineShoulder, JointType.ShoulderLeft); 44 | this.DrawBone(JointType.SpineBase, JointType.HipRight); 45 | this.DrawBone(JointType.SpineBase, JointType.HipLeft); 46 | } 47 | 48 | private void DrawRightArm() 49 | { 50 | this.DrawBone(JointType.ShoulderRight, JointType.ElbowRight); 51 | this.DrawBone(JointType.ElbowRight, JointType.WristRight); 52 | this.DrawBone(JointType.WristRight, JointType.HandRight); 53 | this.DrawBone(JointType.HandRight, JointType.HandTipRight); 54 | this.DrawBone(JointType.WristRight, JointType.ThumbRight); 55 | } 56 | 57 | private void DrawLeftArm() 58 | { 59 | this.DrawBone(JointType.ShoulderLeft, JointType.ElbowLeft); 60 | this.DrawBone(JointType.ElbowLeft, JointType.WristLeft); 61 | this.DrawBone(JointType.WristLeft, JointType.HandLeft); 62 | this.DrawBone(JointType.HandLeft, JointType.HandTipLeft); 63 | this.DrawBone(JointType.WristLeft, JointType.ThumbLeft); 64 | } 65 | 66 | private void DrawRightLeg() 67 | { 68 | this.DrawBone(JointType.HipRight, JointType.KneeRight); 69 | this.DrawBone(JointType.KneeRight, JointType.AnkleRight); 70 | this.DrawBone(JointType.AnkleRight, JointType.FootRight); 71 | } 72 | 73 | private void DrawLeftLeg() 74 | { 75 | this.DrawBone(JointType.HipLeft, JointType.KneeLeft); 76 | this.DrawBone(JointType.KneeLeft, JointType.AnkleLeft); 77 | this.DrawBone(JointType.AnkleLeft, JointType.FootLeft); 78 | } 79 | 80 | private void DrawBone(JointType jointType1, JointType jointType2) 81 | { 82 | Joint joint1 = joints[jointType1]; 83 | Joint joint2 = joints[jointType2]; 84 | 85 | if (this.inspector.IsLowConfidence(joint1, joint2)) return; 86 | Pen pen = this.ChoosePen(joint1, joint2); 87 | 88 | drawingContext.DrawLine(pen, drawingPoints[jointType1], drawingPoints[jointType2]); 89 | } 90 | 91 | private Pen ChoosePen(Joint joint1, Joint joint2) 92 | { 93 | Pen pen = this.inferredBonePen; 94 | 95 | if (this.inspector.GetCombinedTrackingState(joint1, joint2) == TrackingState.Tracked) 96 | { 97 | pen = this.trackedBonePen; 98 | } 99 | 100 | return pen; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Model/Inspector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.Kinect; 7 | 8 | namespace KinectV2OSC.Model 9 | { 10 | public class Inspector 11 | { 12 | public bool IsLowConfidence(Joint joint1, Joint joint2) 13 | { 14 | if (joint1.TrackingState == TrackingState.NotTracked || joint2.TrackingState == TrackingState.NotTracked) 15 | { 16 | return true; 17 | } 18 | 19 | if (joint1.TrackingState == TrackingState.Inferred && joint2.TrackingState == TrackingState.Inferred) 20 | { 21 | return true; 22 | } 23 | 24 | return false; 25 | } 26 | 27 | public TrackingState GetCombinedTrackingState(Joint joint1, Joint joint2) 28 | { 29 | if (joint1.TrackingState == TrackingState.Tracked && joint2.TrackingState == TrackingState.Tracked) 30 | { 31 | return TrackingState.Tracked; 32 | } 33 | 34 | if (joint1.TrackingState == TrackingState.Inferred && joint2.TrackingState == TrackingState.Tracked) 35 | { 36 | return TrackingState.Inferred; 37 | } 38 | 39 | if (joint1.TrackingState == TrackingState.Tracked && joint2.TrackingState == TrackingState.Inferred) 40 | { 41 | return TrackingState.Inferred; 42 | } 43 | 44 | return TrackingState.NotTracked; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Model/Network/BodySender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Collections; 8 | using Microsoft.Kinect; 9 | using Rug.Osc; 10 | 11 | namespace KinectV2OSC.Model.Network 12 | { 13 | public class BodySender 14 | { 15 | private MessageBuilder messageBuilder; 16 | private List oscSenders; 17 | private List ipAddresses; 18 | private OscMessage message; 19 | private string port; 20 | private string status; 21 | 22 | public BodySender(string delimitedIpAddresses, string port) 23 | { 24 | this.status = ""; 25 | this.ipAddresses = this.Parse(delimitedIpAddresses); 26 | this.oscSenders = new List(); 27 | this.port = port; 28 | this.messageBuilder = new MessageBuilder(); 29 | this.TryConnect(); 30 | } 31 | 32 | private void TryConnect() 33 | { 34 | foreach(var ipAddress in this.ipAddresses) 35 | { 36 | try 37 | { 38 | var oscSender = new OscSender(ipAddress, int.Parse(this.port)); 39 | oscSender.Connect(); 40 | this.oscSenders.Add(oscSender); 41 | this.status += "OSC connection established on\nIP: " + ipAddress + "\nPort: " + port + "\n"; 42 | } 43 | catch (Exception e) 44 | { 45 | this.status += "Unable to make OSC connection on\nIP: " + ipAddress + "\nPort: " + port + "\n"; 46 | Console.WriteLine("Exception on OSC connection..."); 47 | Console.WriteLine(e.StackTrace); 48 | } 49 | } 50 | 51 | } 52 | 53 | public void Send(Body[] bodies) 54 | { 55 | foreach (Body body in bodies) 56 | { 57 | if (body.IsTracked) 58 | { 59 | this.Send(body); 60 | } 61 | } 62 | } 63 | 64 | public string GetStatusText() 65 | { 66 | return this.status; 67 | } 68 | 69 | private void Send(Body body) 70 | { 71 | foreach (var joint in body.Joints) 72 | { 73 | message = messageBuilder.BuildJointMessage(body, joint); 74 | this.Broadcast(message); 75 | } 76 | 77 | message = messageBuilder.BuildHandMessage(body, "Left", body.HandLeftState, body.HandLeftConfidence); 78 | this.Broadcast(message); 79 | 80 | message = messageBuilder.BuildHandMessage(body, "Right", body.HandRightState, body.HandRightConfidence); 81 | this.Broadcast(message); 82 | } 83 | 84 | private void Broadcast(OscMessage message) 85 | { 86 | foreach (var oscSender in this.oscSenders) 87 | { 88 | oscSender.Send(message); 89 | } 90 | } 91 | 92 | private List Parse(string delimitedIpAddresses) 93 | { 94 | try 95 | { 96 | var ipAddressStrings = delimitedIpAddresses.Split(','); 97 | var ipAddresses = new List(); 98 | foreach (var ipAddressString in ipAddressStrings) 99 | { 100 | ipAddresses.Add(IPAddress.Parse(ipAddressString)); 101 | } 102 | return ipAddresses; 103 | } 104 | catch (Exception e) 105 | { 106 | status += "Unable to parse IP address string: '" + delimitedIpAddresses + "'"; 107 | Console.WriteLine("Exception parsing IP address string..."); 108 | Console.WriteLine(e.StackTrace); 109 | return null; 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Model/Network/MessageBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.Kinect; 7 | using Rug.Osc; 8 | 9 | namespace KinectV2OSC.Model.Network 10 | { 11 | public class MessageBuilder 12 | { 13 | public OscMessage BuildJointMessage(Body body, KeyValuePair joint) 14 | { 15 | var address = String.Format("/bodies/{0}/joints/{1}", body.TrackingId, joint.Key); 16 | var position = joint.Value.Position; 17 | //System.Diagnostics.Debug.WriteLine(address); 18 | return new OscMessage(address, position.X, position.Y, position.Z, joint.Value.TrackingState.ToString()); 19 | } 20 | 21 | public OscMessage BuildHandMessage(Body body, string key, HandState state, TrackingConfidence confidence) 22 | { 23 | var address = String.Format("/bodies/{0}/hands/{1}", body.TrackingId, key); 24 | //System.Diagnostics.Debug.WriteLine(address); 25 | return new OscMessage(address, state.ToString(), confidence.ToString()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Reflection; 9 | using System.Resources; 10 | using System.Runtime.InteropServices; 11 | using System.Windows; 12 | 13 | // General Information about an assembly is controlled through the following 14 | // set of attributes. Change these attribute values to modify the information 15 | // associated with an assembly. 16 | [assembly: AssemblyTitle("BodyBasics-WPF")] 17 | [assembly: AssemblyDescription("")] 18 | [assembly: AssemblyConfiguration("")] 19 | [assembly: AssemblyTrademark("")] 20 | 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | 26 | // In order to begin building localizable applications, set 27 | // CultureYouAreCodingWith in your .csproj file 28 | // inside a . For example, if you are using US english 29 | // in your source files, set the to en-US. Then uncomment 30 | // the NeutralResourceLanguage attribute below. Update the "en-US" in 31 | // the line below to match the UICulture setting in the project file. 32 | 33 | //// [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 34 | 35 | [assembly: ThemeInfo( 36 | ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located 37 | // (used if a resource is not found in the page, 38 | // or application resource dictionaries) 39 | ResourceDictionaryLocation.SourceAssembly)] // where the generic resource dictionary is located 40 | // (used if a resource is not found in the page, 41 | // app, or any theme specific resource dictionaries) 42 | 43 | // Version information for an assembly consists of the following four values: 44 | // 45 | // Major Version 46 | // Minor Version 47 | // Build Number 48 | // Revision 49 | // 50 | // You can specify all the values or you can default the Build and Revision Numbers 51 | // by using the '*' as shown below: 52 | // [assembly: AssemblyVersion("1.0.*")][assembly: NeutralResourcesLanguageAttribute("en-US")] 53 | [assembly: NeutralResourcesLanguage("en-US")] 54 | [assembly: CLSCompliant(true)] 55 | -------------------------------------------------------------------------------- /Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34014 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace KinectV2OSC.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("KinectV2OSC.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized string similar to 127.0.0.1. 65 | /// 66 | internal static string DefaultIpAddressCsv { 67 | get { 68 | return ResourceManager.GetString("DefaultIpAddressCsv", resourceCulture); 69 | } 70 | } 71 | 72 | /// 73 | /// Looks up a localized string similar to Initializing. 74 | /// 75 | internal static string InitializingStatusTextFormat { 76 | get { 77 | return ResourceManager.GetString("InitializingStatusTextFormat", resourceCulture); 78 | } 79 | } 80 | 81 | /// 82 | /// Looks up a localized string similar to ip.txt. 83 | /// 84 | internal static string IpAddressFileName { 85 | get { 86 | return ResourceManager.GetString("IpAddressFileName", resourceCulture); 87 | } 88 | } 89 | 90 | /// 91 | /// Looks up a localized string similar to Kinect not found.... 92 | /// 93 | internal static string NoSensorFoundText { 94 | get { 95 | return ResourceManager.GetString("NoSensorFoundText", resourceCulture); 96 | } 97 | } 98 | 99 | /// 100 | /// Looks up a localized string similar to 12345. 101 | /// 102 | internal static string PortNumber { 103 | get { 104 | return ResourceManager.GetString("PortNumber", resourceCulture); 105 | } 106 | } 107 | 108 | /// 109 | /// Looks up a localized string similar to {0:N1}fps. 110 | /// 111 | internal static string StandardFramesTextFormat { 112 | get { 113 | return ResourceManager.GetString("StandardFramesTextFormat", resourceCulture); 114 | } 115 | } 116 | 117 | /// 118 | /// Looks up a localized string similar to {0:hh\:mm\:ss}. 119 | /// 120 | internal static string StandardUptimeTextFormat { 121 | get { 122 | return ResourceManager.GetString("StandardUptimeTextFormat", resourceCulture); 123 | } 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 127.0.0.1 122 | 123 | 124 | Initializing 125 | 126 | 127 | ip.txt 128 | 129 | 130 | Kinect not found... 131 | 132 | 133 | 12345 134 | 135 | 136 | {0:N1}fps 137 | 138 | 139 | {0:hh\:mm\:ss} 140 | 141 | -------------------------------------------------------------------------------- /Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34014 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace KinectV2OSC.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | KinectV2OSC 2 | =========== 3 | Broadcasts [KinectV2](http://www.microsoft.com/en-us/kinectforwindows/purchase/) skeletal data over OSC. That's it. 4 | 5 | ![A Kinect V2 sensor](kinect.jpg) 6 | 7 | Handy if you want to quickly get skeleton data off of Windows and onto Mac, or into some other Windows app. 8 | 9 | Just run the app 10 | ---------------- 11 | If you just want to run the app without digging into the code, you can simply follow these instructions: 12 | - Note that you need Windows 8.1, a USB3 port, and a new V2 Kinect sensor 13 | - Download and install the [Kinect for Windows SDK 2.0](http://www.microsoft.com/en-us/kinectforwindows/develop/default.aspx) 14 | - Download the release executable and run it. You should see a screen like this: 15 | 16 | ![Screenshot of KinectV2OSC in action](screenshot.png) 17 | 18 | - By default, the executable broadcasts to port `12345` on IP address `127.0.0.1` 19 | - To broadcast elsewhere, create a file named `ip.txt` in the same folder as the executable. Give the file a comma-separated list of IP asddresses to broadcast to, i.e. 20 | 21 | ```sh 22 | 127.0.0.1,192.168.1.100,192.168.1.112 23 | ``` 24 | 25 | - Re-launch the executable 26 | 27 | Compile from source 28 | ------------------- 29 | If you want to be able to change the port number, or edit the code, you will need to compile from source. Follow these instructions: 30 | - Note that you need Windows 8.1, a USB3 port, and a new V2 Kinect sensor 31 | - Download and install the [Kinect for Windows SDK 2.0](http://www.microsoft.com/en-us/kinectforwindows/develop/default.aspx) 32 | - Install Visual Studio (I am using [Visual Studio Express 2013 for Windows Desktop](http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx) - scroll down to find the download link) 33 | - MAKE SURE you are using Visual Studio Express for **Windows Desktop** - you have to scroll down to find that link!! 34 | - Clone this repo, and open KinectV2OSC.sln in Visual Studio. Hit the green 'Start' button. You should see a screen like this: 35 | 36 | ![Screenshot of KinectV2OSC in action](screenshot.png) 37 | 38 | - To send to another destination, change the IP and port number here, and then re-launch: 39 | 40 | ![How to configure IP and port number](config.png) 41 | 42 | You can enter a single IP Address or multiple, separated by commas. 43 | 44 | What OSC messages get sent? 45 | --------------------------- 46 | OSC messages are sent every frame. For each detected body, you will get a set of joints: 47 | 48 | ```sh 49 | Address: /bodies/{bodyId}/joints/{jointId} 50 | Values: - float: positionX 51 | - float: positionY 52 | - float: positionZ 53 | - string: trackingState (Tracked, NotTracked or Inferred) 54 | ``` 55 | 56 | ...and a pair of hands: 57 | 58 | ```sh 59 | Address: /bodies/{bodyId}/hands/{handId} (Left or Right) 60 | Values: - string: handState (Open, Closed, NotTracked, Unknown) 61 | - string: handConfidence (High, Low) 62 | ``` 63 | 64 | Project dependencies 65 | -------------------- 66 | - [Rug OSC](https://www.nuget.org/packages/Rug.Osc/) to format and send messages 67 | -------------------------------------------------------------------------------- /config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microcosm/KinectV2-OSC/f8826ee47f6fa9e25605c8852f70578de32bc620/config.png -------------------------------------------------------------------------------- /kinect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microcosm/KinectV2-OSC/f8826ee47f6fa9e25605c8852f70578de32bc620/kinect.jpg -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microcosm/KinectV2-OSC/f8826ee47f6fa9e25605c8852f70578de32bc620/screenshot.png --------------------------------------------------------------------------------