├── .gitattributes
├── .gitignore
├── Kinect2FaceBasics
├── Kinect2FaceBasics.sln
├── Kinect2FaceBasics_NET
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── ColorBitmapGenerator.cs
│ ├── Kinect2FaceBasics_NET.csproj
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ └── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
└── Kinect2FaceBasics_WinRT
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Assets
│ ├── Logo.scale-100.png
│ ├── SmallLogo.scale-100.png
│ ├── SplashScreen.scale-100.png
│ └── StoreLogo.scale-100.png
│ ├── ColorBitmapGenerator.cs
│ ├── Kinect2FaceBasics_WinRT.csproj
│ ├── Kinect2FaceBasics_WinRT_TemporaryKey.pfx
│ ├── MainPage.xaml
│ ├── MainPage.xaml.cs
│ ├── Package.appxmanifest
│ └── Properties
│ └── AssemblyInfo.cs
├── LICENSE
└── README.md
/.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 | [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 | *.publishproj
132 |
133 | # NuGet Packages
134 | *.nupkg
135 | # The packages folder can be ignored because of Package Restore
136 | **/packages/*
137 | # except build/, which is used as an MSBuild target.
138 | !**/packages/build/
139 | # If using the old MSBuild-Integrated Package Restore, uncomment this:
140 | #!**/packages/repositories.config
141 |
142 | # Windows Azure Build Output
143 | csx/
144 | *.build.csdef
145 |
146 | # Windows Store app package directory
147 | AppPackages/
148 |
149 | # Others
150 | sql/
151 | *.Cache
152 | ClientBin/
153 | [Ss]tyle[Cc]op.*
154 | ~$*
155 | *~
156 | *.dbmdl
157 | *.dbproj.schemaview
158 | *.pfx
159 | *.publishsettings
160 | node_modules/
161 |
162 | # RIA/Silverlight projects
163 | Generated_Code/
164 |
165 | # Backup & report files from converting an old project file
166 | # to a newer Visual Studio version. Backup files are not needed,
167 | # because we have git ;-)
168 | _UpgradeReport_Files/
169 | Backup*/
170 | UpgradeLog*.XML
171 | UpgradeLog*.htm
172 |
173 | # SQL Server files
174 | *.mdf
175 | *.ldf
176 |
177 | # Business Intelligence projects
178 | *.rdl.data
179 | *.bim.layout
180 | *.bim_*.settings
181 |
182 | # Microsoft Fakes
183 | FakesAssemblies/
184 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kinect2FaceBasics_NET", "Kinect2FaceBasics_NET\Kinect2FaceBasics_NET.csproj", "{F701C47B-25C5-4AC4-BE35-6123BED5C2DB}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kinect2FaceBasics_WinRT", "Kinect2FaceBasics_WinRT\Kinect2FaceBasics_WinRT.csproj", "{0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|x64 = Debug|x64
13 | Debug|x86 = Debug|x86
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {F701C47B-25C5-4AC4-BE35-6123BED5C2DB}.Debug|x64.ActiveCfg = Debug|Any CPU
19 | {F701C47B-25C5-4AC4-BE35-6123BED5C2DB}.Debug|x86.ActiveCfg = Debug|Any CPU
20 | {F701C47B-25C5-4AC4-BE35-6123BED5C2DB}.Release|x64.ActiveCfg = Release|Any CPU
21 | {F701C47B-25C5-4AC4-BE35-6123BED5C2DB}.Release|x86.ActiveCfg = Release|Any CPU
22 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Debug|x64.ActiveCfg = Debug|x64
23 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Debug|x64.Build.0 = Debug|x64
24 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Debug|x64.Deploy.0 = Debug|x64
25 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Debug|x86.ActiveCfg = Debug|x86
26 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Debug|x86.Build.0 = Debug|x86
27 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Debug|x86.Deploy.0 = Debug|x86
28 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Release|x64.ActiveCfg = Release|x64
29 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Release|x64.Build.0 = Release|x64
30 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Release|x64.Deploy.0 = Release|x64
31 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Release|x86.ActiveCfg = Release|x86
32 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Release|x86.Build.0 = Release|x86
33 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}.Release|x86.Deploy.0 = Release|x86
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
12 |
17 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/App.xaml.cs:
--------------------------------------------------------------------------------
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 Kinect2FaceBasics_NET
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/ColorBitmapGenerator.cs:
--------------------------------------------------------------------------------
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.Media;
10 | using System.Windows.Media.Imaging;
11 |
12 | namespace Kinect2FaceBasics_NET
13 | {
14 | ///
15 | /// Creates a bitmap representation of a Kinect color frame.
16 | ///
17 | public class ColorBitmapGenerator
18 | {
19 | #region Members
20 |
21 | ///
22 | /// Returns the RGB pixel values.
23 | ///
24 | byte[] _pixels;
25 |
26 | ///
27 | /// Returns the width of the bitmap.
28 | ///
29 | int _width;
30 |
31 | ///
32 | /// Returns the height of the bitmap.
33 | ///
34 | int _height;
35 |
36 | #endregion
37 |
38 | #region Properties
39 |
40 | ///
41 | /// Returns the actual bitmap.
42 | ///
43 | public WriteableBitmap Bitmap { get; private set; }
44 |
45 | #endregion
46 |
47 | #region Methods
48 |
49 | ///
50 | /// Updates the bitmap with new frame data.
51 | ///
52 | /// The specified Kinect color frame.
53 | public void Update(ColorFrame frame)
54 | {
55 | if (Bitmap == null)
56 | {
57 | _width = frame.FrameDescription.Width;
58 | _height = frame.FrameDescription.Height;
59 | _pixels = new byte[_width * _height * 4];
60 | Bitmap = new WriteableBitmap(_width, _height, 96.0, 96.0, PixelFormats.Bgr32, null);
61 | }
62 |
63 | if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
64 | {
65 | frame.CopyRawFrameDataToArray(_pixels);
66 | }
67 | else
68 | {
69 | frame.CopyConvertedFrameDataToArray(_pixels, ColorImageFormat.Bgra);
70 | }
71 |
72 | Bitmap.Lock();
73 |
74 | Marshal.Copy(_pixels, 0, Bitmap.BackBuffer, _pixels.Length);
75 | Bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height));
76 |
77 | Bitmap.Unlock();
78 | }
79 |
80 | #endregion
81 | }
82 |
83 | ///
84 | /// Provides some common functionality for manipulating color frames.
85 | ///
86 | public static class ColorExtensions
87 | {
88 | #region Members
89 |
90 | ///
91 | /// The color bitmap creator.
92 | ///
93 | static ColorBitmapGenerator _bitmapGenerator = new ColorBitmapGenerator();
94 |
95 | #endregion
96 |
97 | #region Public methods
98 |
99 | ///
100 | /// Converts a color frame to a System.Media.Imaging.BitmapSource.
101 | ///
102 | /// The specified color frame.
103 | /// The bitmap representation of the specified color frame.
104 | public static WriteableBitmap ToBitmap(this ColorFrame frame)
105 | {
106 | _bitmapGenerator.Update(frame);
107 |
108 | return _bitmapGenerator.Bitmap;
109 | }
110 |
111 | #endregion
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/Kinect2FaceBasics_NET.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {F701C47B-25C5-4AC4-BE35-6123BED5C2DB}
8 | WinExe
9 | Properties
10 | Kinect2FaceBasics_NET
11 | Kinect2FaceBasics_NET
12 | v4.5
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | 4.0
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | MSBuild:Compile
56 | Designer
57 |
58 |
59 | MSBuild:Compile
60 | Designer
61 |
62 |
63 | App.xaml
64 | Code
65 |
66 |
67 |
68 | MainWindow.xaml
69 | Code
70 |
71 |
72 |
73 |
74 | Code
75 |
76 |
77 | True
78 | True
79 | Resources.resx
80 |
81 |
82 | True
83 | Settings.settings
84 | True
85 |
86 |
87 | ResXFileCodeGenerator
88 | Resources.Designer.cs
89 |
90 |
91 | SettingsSingleFileGenerator
92 | Settings.Designer.cs
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | xcopy "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0\ExtensionSDKs\Microsoft.Kinect.Face\2.0\Redist\CommonConfiguration\x64\NuiDatabase" "NuiDatabase" /e /y /i /r
102 |
103 |
110 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Kinect;
2 | using Microsoft.Kinect.Face;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
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 Kinect2FaceBasics_NET
19 | {
20 | ///
21 | /// Interaction logic for MainWindow.xaml
22 | ///
23 | public partial class MainWindow : Window
24 | {
25 | KinectSensor _sensor = null;
26 | ColorFrameReader _colorReader = null;
27 | BodyFrameReader _bodyReader = null;
28 | IList
_bodies = null;
29 |
30 | // 1) Specify a face frame source and a face frame reader
31 | FaceFrameSource _faceSource = null;
32 | FaceFrameReader _faceReader = null;
33 |
34 | public MainWindow()
35 | {
36 | InitializeComponent();
37 |
38 | _sensor = KinectSensor.GetDefault();
39 |
40 | if (_sensor != null)
41 | {
42 | _sensor.Open();
43 |
44 | _bodies = new Body[_sensor.BodyFrameSource.BodyCount];
45 |
46 | _colorReader = _sensor.ColorFrameSource.OpenReader();
47 | _colorReader.FrameArrived += ColorReader_FrameArrived;
48 | _bodyReader = _sensor.BodyFrameSource.OpenReader();
49 | _bodyReader.FrameArrived += BodyReader_FrameArrived;
50 |
51 | // 2) Initialize the face source with the desired features
52 | _faceSource = new FaceFrameSource(_sensor, 0, FaceFrameFeatures.BoundingBoxInColorSpace |
53 | FaceFrameFeatures.FaceEngagement |
54 | FaceFrameFeatures.Glasses |
55 | FaceFrameFeatures.Happy |
56 | FaceFrameFeatures.LeftEyeClosed |
57 | FaceFrameFeatures.MouthOpen |
58 | FaceFrameFeatures.PointsInColorSpace |
59 | FaceFrameFeatures.RightEyeClosed);
60 | _faceReader = _faceSource.OpenReader();
61 | _faceReader.FrameArrived += FaceReader_FrameArrived;
62 | }
63 | }
64 |
65 | void ColorReader_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
66 | {
67 | using (var frame = e.FrameReference.AcquireFrame())
68 | {
69 | if (frame != null)
70 | {
71 | camera.Source = frame.ToBitmap();
72 | }
73 | }
74 | }
75 |
76 | void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
77 | {
78 | using (var frame = e.FrameReference.AcquireFrame())
79 | {
80 | if (frame != null)
81 | {
82 | frame.GetAndRefreshBodyData(_bodies);
83 |
84 | Body body = _bodies.Where(b => b.IsTracked).FirstOrDefault();
85 |
86 | if (!_faceSource.IsTrackingIdValid)
87 | {
88 | if (body != null)
89 | {
90 | // 4) Assign a tracking ID to the face source
91 | _faceSource.TrackingId = body.TrackingId;
92 | }
93 | }
94 | }
95 | }
96 | }
97 |
98 | void FaceReader_FrameArrived(object sender, FaceFrameArrivedEventArgs e)
99 | {
100 | using (var frame = e.FrameReference.AcquireFrame())
101 | {
102 | if (frame != null)
103 | {
104 | // 4) Get the face frame result
105 | FaceFrameResult result = frame.FaceFrameResult;
106 |
107 | if (result != null)
108 | {
109 | // 5) Do magic!
110 |
111 | // Get the face points, mapped in the color space.
112 | var eyeLeft = result.FacePointsInColorSpace[FacePointType.EyeLeft];
113 | var eyeRight = result.FacePointsInColorSpace[FacePointType.EyeRight];
114 | var nose = result.FacePointsInColorSpace[FacePointType.Nose];
115 | var mouthLeft = result.FacePointsInColorSpace[FacePointType.MouthCornerLeft];
116 | var mouthRight = result.FacePointsInColorSpace[FacePointType.MouthCornerRight];
117 |
118 | var eyeLeftClosed = result.FaceProperties[FaceProperty.LeftEyeClosed];
119 | var eyeRightClosed = result.FaceProperties[FaceProperty.RightEyeClosed];
120 | var mouthOpen = result.FaceProperties[FaceProperty.MouthOpen];
121 |
122 | // Position the canvas UI elements
123 | Canvas.SetLeft(ellipseEyeLeft, eyeLeft.X - ellipseEyeLeft.Width / 2.0);
124 | Canvas.SetTop(ellipseEyeLeft, eyeLeft.Y - ellipseEyeLeft.Height / 2.0);
125 |
126 | Canvas.SetLeft(ellipseEyeRight, eyeRight.X - ellipseEyeRight.Width / 2.0);
127 | Canvas.SetTop(ellipseEyeRight, eyeRight.Y - ellipseEyeRight.Height / 2.0);
128 |
129 | Canvas.SetLeft(ellipseNose, nose.X - ellipseNose.Width / 2.0);
130 | Canvas.SetTop(ellipseNose, nose.Y - ellipseNose.Height / 2.0);
131 |
132 | Canvas.SetLeft(ellipseMouth, ((mouthRight.X + mouthLeft.X) / 2.0) - ellipseMouth.Width / 2.0);
133 | Canvas.SetTop(ellipseMouth, ((mouthRight.Y + mouthLeft.Y) / 2.0) - ellipseMouth.Height / 2.0);
134 | ellipseMouth.Width = Math.Abs(mouthRight.X - mouthLeft.X);
135 |
136 | // Display or hide the ellipses
137 | if (eyeLeftClosed == DetectionResult.Yes || eyeLeftClosed == DetectionResult.Maybe)
138 | {
139 | ellipseEyeLeft.Visibility = Visibility.Collapsed;
140 | }
141 | else
142 | {
143 | ellipseEyeLeft.Visibility = Visibility.Visible;
144 | }
145 |
146 | if (eyeRightClosed == DetectionResult.Yes || eyeRightClosed == DetectionResult.Maybe)
147 | {
148 | ellipseEyeRight.Visibility = Visibility.Collapsed;
149 | }
150 | else
151 | {
152 | ellipseEyeRight.Visibility = Visibility.Visible;
153 | }
154 |
155 | if (mouthOpen == DetectionResult.Yes || mouthOpen == DetectionResult.Maybe)
156 | {
157 | ellipseMouth.Height = 50.0;
158 | }
159 | else
160 | {
161 | ellipseMouth.Height = 20.0;
162 | }
163 | }
164 | }
165 | }
166 | }
167 |
168 | private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
169 | {
170 | if (_colorReader != null)
171 | {
172 | _colorReader.Dispose();
173 | _colorReader = null;
174 | }
175 |
176 | if (_bodyReader != null)
177 | {
178 | _bodyReader.Dispose();
179 | _bodyReader = null;
180 | }
181 |
182 | if (_faceReader != null)
183 | {
184 | _faceReader.Dispose();
185 | _faceReader = null;
186 | }
187 |
188 | if (_faceSource != null)
189 | {
190 | _faceSource.Dispose();
191 | _faceSource = null;
192 | }
193 |
194 | if (_sensor != null)
195 | {
196 | _sensor.Close();
197 | }
198 | }
199 | }
200 | }
201 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("Kinect2FaceBasics_NET")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("Kinect2FaceBasics_NET")]
15 | [assembly: AssemblyCopyright("Copyright © 2014")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.0
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 Kinect2FaceBasics_NET.Properties
12 | {
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 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Kinect2FaceBasics_NET.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/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 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.0
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 Kinect2FaceBasics_NET.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_NET/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
13 |
18 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using Windows.ApplicationModel;
7 | using Windows.ApplicationModel.Activation;
8 | using Windows.Foundation;
9 | using Windows.Foundation.Collections;
10 | using Windows.UI.Xaml;
11 | using Windows.UI.Xaml.Controls;
12 | using Windows.UI.Xaml.Controls.Primitives;
13 | using Windows.UI.Xaml.Data;
14 | using Windows.UI.Xaml.Input;
15 | using Windows.UI.Xaml.Media;
16 | using Windows.UI.Xaml.Navigation;
17 |
18 | // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
19 |
20 | namespace Kinect2FaceBasics_WinRT
21 | {
22 | ///
23 | /// Provides application-specific behavior to supplement the default Application class.
24 | ///
25 | sealed partial class App : Application
26 | {
27 | ///
28 | /// Initializes the singleton application object. This is the first line of authored code
29 | /// executed, and as such is the logical equivalent of main() or WinMain().
30 | ///
31 | public App()
32 | {
33 | this.InitializeComponent();
34 | this.Suspending += OnSuspending;
35 | }
36 |
37 | ///
38 | /// Invoked when the application is launched normally by the end user. Other entry points
39 | /// will be used such as when the application is launched to open a specific file.
40 | ///
41 | /// Details about the launch request and process.
42 | protected override void OnLaunched(LaunchActivatedEventArgs e)
43 | {
44 |
45 | #if DEBUG
46 | if (System.Diagnostics.Debugger.IsAttached)
47 | {
48 | this.DebugSettings.EnableFrameRateCounter = true;
49 | }
50 | #endif
51 |
52 | Frame rootFrame = Window.Current.Content as Frame;
53 |
54 | // Do not repeat app initialization when the Window already has content,
55 | // just ensure that the window is active
56 | if (rootFrame == null)
57 | {
58 | // Create a Frame to act as the navigation context and navigate to the first page
59 | rootFrame = new Frame();
60 | // Set the default language
61 | rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
62 |
63 | rootFrame.NavigationFailed += OnNavigationFailed;
64 |
65 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
66 | {
67 | //TODO: Load state from previously suspended application
68 | }
69 |
70 | // Place the frame in the current Window
71 | Window.Current.Content = rootFrame;
72 | }
73 |
74 | if (rootFrame.Content == null)
75 | {
76 | // When the navigation stack isn't restored navigate to the first page,
77 | // configuring the new page by passing required information as a navigation
78 | // parameter
79 | rootFrame.Navigate(typeof(MainPage), e.Arguments);
80 | }
81 | // Ensure the current window is active
82 | Window.Current.Activate();
83 | }
84 |
85 | ///
86 | /// Invoked when Navigation to a certain page fails
87 | ///
88 | /// The Frame which failed navigation
89 | /// Details about the navigation failure
90 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
91 | {
92 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
93 | }
94 |
95 | ///
96 | /// Invoked when application execution is being suspended. Application state is saved
97 | /// without knowing whether the application will be terminated or resumed with the contents
98 | /// of memory still intact.
99 | ///
100 | /// The source of the suspend request.
101 | /// Details about the suspend request.
102 | private void OnSuspending(object sender, SuspendingEventArgs e)
103 | {
104 | var deferral = e.SuspendingOperation.GetDeferral();
105 | //TODO: Save application state and stop any background activity
106 | deferral.Complete();
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Assets/Logo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vangos/kinect-2-face-basics/8b39602bed38267469197af221d7496457530e8f/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Assets/Logo.scale-100.png
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Assets/SmallLogo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vangos/kinect-2-face-basics/8b39602bed38267469197af221d7496457530e8f/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Assets/SmallLogo.scale-100.png
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Assets/SplashScreen.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vangos/kinect-2-face-basics/8b39602bed38267469197af221d7496457530e8f/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Assets/SplashScreen.scale-100.png
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Assets/StoreLogo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vangos/kinect-2-face-basics/8b39602bed38267469197af221d7496457530e8f/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Assets/StoreLogo.scale-100.png
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/ColorBitmapGenerator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Windows.UI.Xaml.Media.Imaging;
9 | using WindowsPreview.Kinect;
10 |
11 | namespace Kinect2FaceBasics_WinRT
12 | {
13 | ///
14 | /// Creates the bitmap representation of a Kinect color frame.
15 | ///
16 | public class ColorBitmapGenerator
17 | {
18 | #region Properties
19 |
20 | ///
21 | /// Returns the RGB pixel values.
22 | ///
23 | byte[] _pixels;
24 |
25 | ///
26 | /// Returns the width of the bitmap.
27 | ///
28 | int _width;
29 |
30 | ///
31 | /// Returns the height of the bitmap.
32 | ///
33 | int _height;
34 |
35 | ///
36 | /// Returns the stream of the bitmap.
37 | ///
38 | Stream _stream;
39 |
40 | #endregion
41 |
42 | #region Properties
43 |
44 | ///
45 | /// Returns the actual bitmap.
46 | ///
47 | public WriteableBitmap Bitmap { get; protected set; }
48 |
49 | #endregion
50 |
51 | #region Methods
52 |
53 | ///
54 | /// Updates the bitmap with new frame data.
55 | ///
56 | /// The specified Kinect color frame.
57 | /// The specified color format.
58 | public void Update(ColorFrame frame, ColorImageFormat format)
59 | {
60 | if (Bitmap == null)
61 | {
62 | _width = frame.FrameDescription.Width;
63 | _height = frame.FrameDescription.Height;
64 | _pixels = new byte[_width * _height * 4];
65 | Bitmap = new WriteableBitmap(_width, _height);
66 | _stream = Bitmap.PixelBuffer.AsStream();
67 | }
68 |
69 | if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
70 | {
71 | frame.CopyRawFrameDataToArray(_pixels);
72 | }
73 | else
74 | {
75 | frame.CopyConvertedFrameDataToArray(_pixels, format);
76 | }
77 |
78 | _stream.Seek(0, SeekOrigin.Begin);
79 | _stream.Write(_pixels, 0, _pixels.Length);
80 |
81 | Bitmap.Invalidate();
82 | }
83 |
84 | ///
85 | /// Updates the bitmap with new frame data.
86 | ///
87 | /// The specified Kinect color frame.
88 | public void Update(ColorFrame frame)
89 | {
90 | Update(frame, ColorImageFormat.Bgra);
91 | }
92 |
93 | #endregion
94 | }
95 |
96 | ///
97 | /// Provides some common functionality for manipulating color frames.
98 | ///
99 | public static class BitmapExtensions
100 | {
101 | #region Members
102 |
103 | ///
104 | /// The color bitmap creator.
105 | ///
106 | static ColorBitmapGenerator _colorBitmapGenerator = new ColorBitmapGenerator();
107 |
108 | #endregion
109 |
110 | #region Public methods
111 |
112 | ///
113 | /// Converts the specified color frame to a bitmap image.
114 | ///
115 | /// The specified color frame.
116 | /// The bitmap representation of the color frame.
117 | public static WriteableBitmap ToBitmap(this ColorFrame frame)
118 | {
119 | _colorBitmapGenerator.Update(frame);
120 |
121 | return _colorBitmapGenerator.Bitmap;
122 | }
123 |
124 | #endregion
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Kinect2FaceBasics_WinRT.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {0A616C5E-B79E-4D3B-8DD2-1CF37ED5A27A}
8 | AppContainerExe
9 | Properties
10 | Kinect2FaceBasics_WinRT
11 | Kinect2FaceBasics_WinRT
12 | en-US
13 | 8.1
14 | 12
15 | 512
16 | {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
17 | Kinect2FaceBasics_WinRT_TemporaryKey.pfx
18 |
19 |
20 | AnyCPU
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE;NETFX_CORE;WINDOWS_APP
26 | prompt
27 | 4
28 |
29 |
30 | AnyCPU
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE;NETFX_CORE;WINDOWS_APP
35 | prompt
36 | 4
37 |
38 |
39 | true
40 | bin\ARM\Debug\
41 | DEBUG;TRACE;NETFX_CORE;WINDOWS_APP
42 | ;2008
43 | full
44 | ARM
45 | false
46 | prompt
47 | true
48 |
49 |
50 | bin\ARM\Release\
51 | TRACE;NETFX_CORE;WINDOWS_APP
52 | true
53 | ;2008
54 | pdbonly
55 | ARM
56 | false
57 | prompt
58 | true
59 |
60 |
61 | true
62 | bin\x64\Debug\
63 | DEBUG;TRACE;NETFX_CORE;WINDOWS_APP
64 | ;2008
65 | full
66 | x64
67 | false
68 | prompt
69 | true
70 |
71 |
72 | bin\x64\Release\
73 | TRACE;NETFX_CORE;WINDOWS_APP
74 | true
75 | ;2008
76 | pdbonly
77 | x64
78 | false
79 | prompt
80 | true
81 |
82 |
83 | true
84 | bin\x86\Debug\
85 | DEBUG;TRACE;NETFX_CORE;WINDOWS_APP
86 | ;2008
87 | full
88 | x86
89 | false
90 | prompt
91 | true
92 |
93 |
94 | bin\x86\Release\
95 | TRACE;NETFX_CORE;WINDOWS_APP
96 | true
97 | ;2008
98 | pdbonly
99 | x86
100 | false
101 | prompt
102 | true
103 |
104 |
105 |
106 |
107 | Microsoft.Kinect.Face
108 |
109 |
110 | Microsoft Visual C++ 2013 Runtime Package for Windows
111 |
112 |
113 | WindowsPreview.Kinect
114 |
115 |
116 |
117 |
118 | App.xaml
119 |
120 |
121 |
122 | MainPage.xaml
123 |
124 |
125 |
126 |
127 |
128 | Designer
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 | MSBuild:Compile
141 | Designer
142 |
143 |
144 | MSBuild:Compile
145 | Designer
146 |
147 |
148 |
149 | 12.0
150 |
151 |
152 |
159 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Kinect2FaceBasics_WinRT_TemporaryKey.pfx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vangos/kinect-2-face-basics/8b39602bed38267469197af221d7496457530e8f/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Kinect2FaceBasics_WinRT_TemporaryKey.pfx
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Kinect.Face;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Runtime.InteropServices.WindowsRuntime;
7 | using Windows.Foundation;
8 | using Windows.Foundation.Collections;
9 | using Windows.UI.Xaml;
10 | using Windows.UI.Xaml.Controls;
11 | using Windows.UI.Xaml.Controls.Primitives;
12 | using Windows.UI.Xaml.Data;
13 | using Windows.UI.Xaml.Input;
14 | using Windows.UI.Xaml.Media;
15 | using Windows.UI.Xaml.Navigation;
16 | using WindowsPreview.Kinect;
17 |
18 | // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
19 |
20 | namespace Kinect2FaceBasics_WinRT
21 | {
22 | ///
23 | /// An empty page that can be used on its own or navigated to within a Frame.
24 | ///
25 | public sealed partial class MainPage : Page
26 | {
27 | KinectSensor _sensor = null;
28 | ColorFrameReader _colorReader = null;
29 | BodyFrameReader _bodyReader = null;
30 | IList _bodies = null;
31 |
32 | // 1) Specify a face frame source and a face frame reader
33 | FaceFrameSource _faceSource = null;
34 | FaceFrameReader _faceReader = null;
35 |
36 | public MainPage()
37 | {
38 | InitializeComponent();
39 |
40 | _sensor = KinectSensor.GetDefault();
41 |
42 | if (_sensor != null)
43 | {
44 | _sensor.Open();
45 |
46 | _bodies = new Body[_sensor.BodyFrameSource.BodyCount];
47 |
48 | _colorReader = _sensor.ColorFrameSource.OpenReader();
49 | _colorReader.FrameArrived += ColorReader_FrameArrived;
50 | _bodyReader = _sensor.BodyFrameSource.OpenReader();
51 | _bodyReader.FrameArrived += BodyReader_FrameArrived;
52 |
53 | // 2) Initialize the face source with the desired features
54 | _faceSource = new FaceFrameSource(_sensor, 0, FaceFrameFeatures.BoundingBoxInColorSpace |
55 | FaceFrameFeatures.FaceEngagement |
56 | FaceFrameFeatures.Glasses |
57 | FaceFrameFeatures.Happy |
58 | FaceFrameFeatures.LeftEyeClosed |
59 | FaceFrameFeatures.MouthOpen |
60 | FaceFrameFeatures.PointsInColorSpace |
61 | FaceFrameFeatures.RightEyeClosed);
62 | _faceReader = _faceSource.OpenReader();
63 | _faceReader.FrameArrived += FaceReader_FrameArrived;
64 | }
65 | }
66 |
67 | void ColorReader_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
68 | {
69 | using (var frame = e.FrameReference.AcquireFrame())
70 | {
71 | if (frame != null)
72 | {
73 | camera.Source = frame.ToBitmap();
74 | }
75 | }
76 | }
77 |
78 | void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
79 | {
80 | using (var frame = e.FrameReference.AcquireFrame())
81 | {
82 | if (frame != null)
83 | {
84 | frame.GetAndRefreshBodyData(_bodies);
85 |
86 | Body body = _bodies.Where(b => b.IsTracked).FirstOrDefault();
87 |
88 | if (!_faceSource.IsTrackingIdValid)
89 | {
90 | if (body != null)
91 | {
92 | // 4) Assign a tracking ID to the face source
93 | _faceSource.TrackingId = body.TrackingId;
94 | }
95 | }
96 | }
97 | }
98 | }
99 |
100 | void FaceReader_FrameArrived(object sender, FaceFrameArrivedEventArgs e)
101 | {
102 | using (var frame = e.FrameReference.AcquireFrame())
103 | {
104 | if (frame != null)
105 | {
106 | // 4) Get the face frame result
107 | FaceFrameResult result = frame.FaceFrameResult;
108 |
109 | if (result != null)
110 | {
111 | // 5) Do magic!
112 |
113 | // Get the face points, mapped in the color space.
114 | var eyeLeft = result.FacePointsInColorSpace[FacePointType.EyeLeft];
115 | var eyeRight = result.FacePointsInColorSpace[FacePointType.EyeRight];
116 | var nose = result.FacePointsInColorSpace[FacePointType.Nose];
117 | var mouthLeft = result.FacePointsInColorSpace[FacePointType.MouthCornerLeft];
118 | var mouthRight = result.FacePointsInColorSpace[FacePointType.MouthCornerRight];
119 |
120 | var eyeLeftClosed = result.FaceProperties[FaceProperty.LeftEyeClosed];
121 | var eyeRightClosed = result.FaceProperties[FaceProperty.RightEyeClosed];
122 | var mouthOpen = result.FaceProperties[FaceProperty.MouthOpen];
123 |
124 | // Position the canvas UI elements
125 | Canvas.SetLeft(ellipseEyeLeft, eyeLeft.X - ellipseEyeLeft.Width / 2.0);
126 | Canvas.SetTop(ellipseEyeLeft, eyeLeft.Y - ellipseEyeLeft.Height / 2.0);
127 |
128 | Canvas.SetLeft(ellipseEyeRight, eyeRight.X - ellipseEyeRight.Width / 2.0);
129 | Canvas.SetTop(ellipseEyeRight, eyeRight.Y - ellipseEyeRight.Height / 2.0);
130 |
131 | Canvas.SetLeft(ellipseNose, nose.X - ellipseNose.Width / 2.0);
132 | Canvas.SetTop(ellipseNose, nose.Y - ellipseNose.Height / 2.0);
133 |
134 | Canvas.SetLeft(ellipseMouth, ((mouthRight.X + mouthLeft.X) / 2.0) - ellipseMouth.Width / 2.0);
135 | Canvas.SetTop(ellipseMouth, ((mouthRight.Y + mouthLeft.Y) / 2.0) - ellipseMouth.Height / 2.0);
136 | ellipseMouth.Width = Math.Abs(mouthRight.X - mouthLeft.X);
137 |
138 | // Display or hide the ellipses
139 | if (eyeLeftClosed == DetectionResult.Yes || eyeLeftClosed == DetectionResult.Maybe)
140 | {
141 | ellipseEyeLeft.Visibility = Visibility.Collapsed;
142 | }
143 | else
144 | {
145 | ellipseEyeLeft.Visibility = Visibility.Visible;
146 | }
147 |
148 | if (eyeRightClosed == DetectionResult.Yes || eyeRightClosed == DetectionResult.Maybe)
149 | {
150 | ellipseEyeRight.Visibility = Visibility.Collapsed;
151 | }
152 | else
153 | {
154 | ellipseEyeRight.Visibility = Visibility.Visible;
155 | }
156 |
157 | if (mouthOpen == DetectionResult.Yes || mouthOpen == DetectionResult.Maybe)
158 | {
159 | ellipseMouth.Height = 50.0;
160 | }
161 | else
162 | {
163 | ellipseMouth.Height = 20.0;
164 | }
165 | }
166 | }
167 | }
168 | }
169 |
170 | private void Page_Unloaded(object sender, RoutedEventArgs e)
171 | {
172 | if (_colorReader != null)
173 | {
174 | _colorReader.Dispose();
175 | _colorReader = null;
176 | }
177 |
178 | if (_bodyReader != null)
179 | {
180 | _bodyReader.Dispose();
181 | _bodyReader = null;
182 | }
183 |
184 | if (_faceReader != null)
185 | {
186 | _faceReader.Dispose();
187 | _faceReader = null;
188 | }
189 |
190 | if (_faceSource != null)
191 | {
192 | _faceSource = null;
193 | }
194 |
195 | if (_sensor != null)
196 | {
197 | _sensor.Close();
198 | }
199 | }
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Kinect2FaceBasics_WinRT
6 | Galini
7 | Assets\StoreLogo.png
8 |
9 |
10 | 6.3.0
11 | 6.3.0
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Kinect2FaceBasics/Kinect2FaceBasics_WinRT/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("Kinect2FaceBasics_WinRT")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Kinect2FaceBasics_WinRT")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Vangos Pterneas
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Kinect version 2 Face Basics
2 | ====================
3 |
4 | Detects the eyes, mouth, and nose of a person using Kinect for Windows version 2.
5 |
6 | [Read the tutorial on pterneas.com](http://wp.me/p5hxPm-sl)
7 |
8 | [Watch a video of the end result](https://www.youtube.com/watch?v=2QWNXwl_9Ro)
9 |
--------------------------------------------------------------------------------