Skip to content

Commit f85d803

Browse files
committed
Project sturcture.
1 parent 16ac939 commit f85d803

14 files changed

+648
-0
lines changed

KinectDrawing/KinectDrawing.sln

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KinectDrawing", "KinectDrawing\KinectDrawing.csproj", "{E3F7B08E-6FBC-4553-B732-46634D8D63DF}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E3F7B08E-6FBC-4553-B732-46634D8D63DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E3F7B08E-6FBC-4553-B732-46634D8D63DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E3F7B08E-6FBC-4553-B732-46634D8D63DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E3F7B08E-6FBC-4553-B732-46634D8D63DF}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>

KinectDrawing/KinectDrawing/App.xaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="KinectDrawing.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:KinectDrawing"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace KinectDrawing
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<UserControl x:Class="KinectDrawing.DrawingBrush"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:KinectDrawing"
7+
mc:Ignorable="d"
8+
d:DesignHeight="100" d:DesignWidth="100">
9+
<Viewbox>
10+
<Grid Width="100" Height="100">
11+
<Path Fill="Cyan" Data="M63.6083,33.3253l-5.6326-4.8058c-0.6924-0.5907-1.3169-1.2565-1.8621-1.9852L45.8148,12.7692 c-0.5551-0.7419-1.6389-0.8195-2.2939-0.1644L20.1917,35.9339c-0.8425,0.8426-0.8693,2.2001-0.0607,3.0754l8.6663,9.3792 c0.47,0.5085-0.2387,1.2413-0.7626,0.7885l-9.7507-8.4251c-0.8801-0.7604-2.1978-0.7124-3.0203,0.11l-1.7855,1.7855 c-0.5367,0.5367-0.5957,1.387-0.1381,1.9927L23.687,58.3359c0.5468,0.7236,1.1719,1.3845,1.8641,1.9705l6.1729,5.226 c0.9782,0.8281,2.4278,0.768,3.334-0.1382L63.7421,36.71C64.6933,35.7587,64.6316,34.1985,63.6083,33.3253z" />
12+
<Path Fill="Cyan" Data="M84.7972,75.308c-7.569-7.4921-19.1168-15.9644-19.1168-15.9644c-2.9304-1.9994-2.2886-4.1873-1.0511-5.4247l6.0219-6.0218 c3.1407-3.1407,3.1407-8.233,0-11.3737c-0.5366-0.5366-1.4066-0.5366-1.9432,0.0001l-33.058,33.0579 c-0.5366,0.5366-0.5366,1.4066,0,1.9432c3.1407,3.1407,8.233,3.1407,11.3737,0l6.0217-6.0218 c1.2375-1.2375,2.9297-2.0137,5.4248,1.0511c0,0,8.4723,11.5479,15.9643,19.1168c2.8564,2.8858,7.5142,2.8937,10.3853,0.0226 h0.0001C87.6908,82.8222,87.683,78.1644,84.7972,75.308z M80.9224,81.7959c-1.027,1.027-2.6921,1.027-3.7191,0 c-1.027-1.027-1.027-2.6921,0-3.7191c1.027-1.027,2.6921-1.027,3.7191,0C81.9494,79.1038,81.9494,80.7689,80.9224,81.7959z" />
13+
</Grid>
14+
</Viewbox>
15+
</UserControl>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace KinectDrawing
17+
{
18+
/// <summary>
19+
/// Interaction logic for DrawingBrush.xaml
20+
/// </summary>
21+
public partial class DrawingBrush : UserControl
22+
{
23+
public DrawingBrush()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{E3F7B08E-6FBC-4553-B732-46634D8D63DF}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>KinectDrawing</RootNamespace>
11+
<AssemblyName>KinectDrawing</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
15+
<WarningLevel>4</WarningLevel>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<PlatformTarget>AnyCPU</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="Microsoft.Kinect, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
38+
<Reference Include="System" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Xml" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Xml.Linq" />
44+
<Reference Include="System.Data.DataSetExtensions" />
45+
<Reference Include="System.Net.Http" />
46+
<Reference Include="System.Xaml">
47+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
48+
</Reference>
49+
<Reference Include="WindowsBase" />
50+
<Reference Include="PresentationCore" />
51+
<Reference Include="PresentationFramework" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<ApplicationDefinition Include="App.xaml">
55+
<Generator>MSBuild:Compile</Generator>
56+
<SubType>Designer</SubType>
57+
</ApplicationDefinition>
58+
<Page Include="DrawingBrush.xaml">
59+
<SubType>Designer</SubType>
60+
<Generator>MSBuild:Compile</Generator>
61+
</Page>
62+
<Page Include="MainWindow.xaml">
63+
<Generator>MSBuild:Compile</Generator>
64+
<SubType>Designer</SubType>
65+
</Page>
66+
<Compile Include="App.xaml.cs">
67+
<DependentUpon>App.xaml</DependentUpon>
68+
<SubType>Code</SubType>
69+
</Compile>
70+
<Compile Include="DrawingBrush.xaml.cs">
71+
<DependentUpon>DrawingBrush.xaml</DependentUpon>
72+
</Compile>
73+
<Compile Include="MainWindow.xaml.cs">
74+
<DependentUpon>MainWindow.xaml</DependentUpon>
75+
<SubType>Code</SubType>
76+
</Compile>
77+
</ItemGroup>
78+
<ItemGroup>
79+
<Compile Include="Properties\AssemblyInfo.cs">
80+
<SubType>Code</SubType>
81+
</Compile>
82+
<Compile Include="Properties\Resources.Designer.cs">
83+
<AutoGen>True</AutoGen>
84+
<DesignTime>True</DesignTime>
85+
<DependentUpon>Resources.resx</DependentUpon>
86+
</Compile>
87+
<Compile Include="Properties\Settings.Designer.cs">
88+
<AutoGen>True</AutoGen>
89+
<DependentUpon>Settings.settings</DependentUpon>
90+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
91+
</Compile>
92+
<EmbeddedResource Include="Properties\Resources.resx">
93+
<Generator>ResXFileCodeGenerator</Generator>
94+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
95+
</EmbeddedResource>
96+
<None Include="Properties\Settings.settings">
97+
<Generator>SettingsSingleFileGenerator</Generator>
98+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
99+
</None>
100+
<AppDesigner Include="Properties\" />
101+
</ItemGroup>
102+
<ItemGroup>
103+
<None Include="App.config" />
104+
</ItemGroup>
105+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
106+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
107+
Other similar extension points exist, see Microsoft.Common.targets.
108+
<Target Name="BeforeBuild">
109+
</Target>
110+
<Target Name="AfterBuild">
111+
</Target>
112+
-->
113+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Window x:Class="KinectDrawing.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:KinectDrawing"
7+
mc:Ignorable="d"
8+
Title="KINECT Drawing" Height="350" Width="525"
9+
WindowState="Maximized"
10+
Background="Black"
11+
Closing="Window_Closing">
12+
<Viewbox>
13+
<Grid Width="1920" Height="1080">
14+
<Image Name="camera" />
15+
<Canvas Name="canvas">
16+
<local:DrawingBrush x:Name="brush" Width="300" Height="300" />
17+
<Polyline Name="trail" Stroke="Red" StrokeThickness="15">
18+
<Polyline.Effect>
19+
<BlurEffect Radius="20" />
20+
</Polyline.Effect>
21+
</Polyline>
22+
</Canvas>
23+
</Grid>
24+
</Viewbox>
25+
</Window>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using Microsoft.Kinect;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Runtime.InteropServices;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace KinectDrawing
19+
{
20+
/// <summary>
21+
/// Interaction logic for MainWindow.xaml
22+
/// </summary>
23+
public partial class MainWindow : Window
24+
{
25+
private KinectSensor _sensor = null;
26+
private ColorFrameReader _colorReader = null;
27+
private BodyFrameReader _bodyReader = null;
28+
private IList<Body> _bodies = null;
29+
30+
private int _width = 0;
31+
private int _height = 0;
32+
private byte[] _pixels = null;
33+
private WriteableBitmap _bitmap = null;
34+
35+
public MainWindow()
36+
{
37+
InitializeComponent();
38+
39+
_sensor = KinectSensor.GetDefault();
40+
41+
if (_sensor != null)
42+
{
43+
_sensor.Open();
44+
45+
_width = _sensor.ColorFrameSource.FrameDescription.Width;
46+
_height = _sensor.ColorFrameSource.FrameDescription.Height;
47+
48+
_colorReader = _sensor.ColorFrameSource.OpenReader();
49+
_colorReader.FrameArrived += ColorReader_FrameArrived;
50+
51+
_bodyReader = _sensor.BodyFrameSource.OpenReader();
52+
_bodyReader.FrameArrived += BodyReader_FrameArrived;
53+
54+
_pixels = new byte[_width * _height * 4];
55+
_bitmap = new WriteableBitmap(_width, _height, 96.0, 96.0, PixelFormats.Bgra32, null);
56+
57+
_bodies = new Body[_sensor.BodyFrameSource.BodyCount];
58+
59+
camera.Source = _bitmap;
60+
}
61+
}
62+
63+
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
64+
{
65+
if (_colorReader != null)
66+
{
67+
_colorReader.Dispose();
68+
}
69+
70+
if (_bodyReader != null)
71+
{
72+
_bodyReader.Dispose();
73+
}
74+
75+
if (_sensor != null)
76+
{
77+
_sensor.Close();
78+
}
79+
}
80+
81+
private void ColorReader_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
82+
{
83+
using (var frame = e.FrameReference.AcquireFrame())
84+
{
85+
if (frame != null)
86+
{
87+
frame.CopyConvertedFrameDataToArray(_pixels, ColorImageFormat.Bgra);
88+
89+
_bitmap.Lock();
90+
Marshal.Copy(_pixels, 0, _bitmap.BackBuffer, _pixels.Length);
91+
_bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height));
92+
_bitmap.Unlock();
93+
}
94+
}
95+
}
96+
97+
private void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
98+
{
99+
using (var frame = e.FrameReference.AcquireFrame())
100+
{
101+
if (frame != null)
102+
{
103+
frame.GetAndRefreshBodyData(_bodies);
104+
105+
Body body = _bodies.Where(b => b.IsTracked).FirstOrDefault();
106+
107+
if (body != null)
108+
{
109+
Joint handRight = body.Joints[JointType.HandRight];
110+
111+
if (handRight.TrackingState != TrackingState.NotTracked)
112+
{
113+
CameraSpacePoint handRightPosition = handRight.Position;
114+
ColorSpacePoint handRightPoint = _sensor.CoordinateMapper.MapCameraPointToColorSpace(handRightPosition);
115+
116+
float x = handRightPoint.X;
117+
float y = handRightPoint.Y;
118+
119+
if (!float.IsInfinity(x) && ! float.IsInfinity(y))
120+
{
121+
// DRAW!
122+
trail.Points.Add(new Point { X = x, Y = y });
123+
124+
Canvas.SetLeft(brush, x - brush.Width / 2.0);
125+
Canvas.SetTop(brush, y - brush.Height);
126+
}
127+
}
128+
}
129+
}
130+
}
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)