├── ExpressionMouse.sln ├── ExpressionMouse ├── ExpressionMouse.csproj ├── ExpressionMouseWindow.Designer.cs ├── ExpressionMouseWindow.cs ├── ExpressionMouseWindow.resx ├── MouseControl.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Settings.cs ├── bin │ └── Debug │ │ ├── FaceTrackData.dll │ │ ├── FaceTrackLib.dll │ │ ├── Microsoft.Kinect.Toolkit.FaceTracking.dll │ │ ├── Microsoft.Kinect.dll │ │ ├── Microsoft.Kinect.xml │ │ ├── init.txt │ │ └── settings.xml └── lib │ ├── FaceTrackData.dll │ ├── FaceTrackLib.dll │ ├── Microsoft.Kinect.Toolkit.FaceTracking.dll │ ├── Microsoft.Kinect.dll │ └── Microsoft.Kinect.xml ├── LICENSE ├── README.md ├── TestApp ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── TestApp.csproj └── bin │ └── Debug │ ├── FaceTrackData.dll │ ├── FaceTrackLib.dll │ ├── Microsoft.Kinect.Toolkit.FaceTracking.dll │ ├── Microsoft.Kinect.dll │ ├── Microsoft.Kinect.xml │ ├── TestApp.exe │ ├── TestApp.vshost.exe │ └── TestApp.vshost.exe.manifest └── executable ├── ExpressionMouse.exe ├── FaceTrackData.dll ├── FaceTrackLib.dll ├── Microsoft.Kinect.Toolkit.FaceTracking.dll ├── Microsoft.Kinect.dll ├── Microsoft.Kinect.xml ├── Microsoft.Speech.dll ├── init.txt ├── mouseLog.txt └── settings.xml /ExpressionMouse.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{37EE628D-2409-4A0E-99D4-477733E316CF}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExpressionMouse", "ExpressionMouse\ExpressionMouse.csproj", "{6E7F533D-F149-42C1-B8BC-44F674EACB35}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x86 = Debug|x86 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {37EE628D-2409-4A0E-99D4-477733E316CF}.Debug|x86.ActiveCfg = Debug|x86 17 | {37EE628D-2409-4A0E-99D4-477733E316CF}.Debug|x86.Build.0 = Debug|x86 18 | {37EE628D-2409-4A0E-99D4-477733E316CF}.Release|x86.ActiveCfg = Release|x86 19 | {37EE628D-2409-4A0E-99D4-477733E316CF}.Release|x86.Build.0 = Release|x86 20 | {6E7F533D-F149-42C1-B8BC-44F674EACB35}.Debug|x86.ActiveCfg = Debug|x86 21 | {6E7F533D-F149-42C1-B8BC-44F674EACB35}.Debug|x86.Build.0 = Debug|x86 22 | {6E7F533D-F149-42C1-B8BC-44F674EACB35}.Release|x86.ActiveCfg = Release|x86 23 | {6E7F533D-F149-42C1-B8BC-44F674EACB35}.Release|x86.Build.0 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /ExpressionMouse/ExpressionMouse.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {6E7F533D-F149-42C1-B8BC-44F674EACB35} 9 | WinExe 10 | Properties 11 | FaceMouseConfig 12 | FaceMouseConfig 13 | v4.0 14 | Client 15 | 512 16 | 17 | 18 | x86 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x86 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | False 39 | lib\Microsoft.Kinect.dll 40 | 41 | 42 | False 43 | lib\Microsoft.Kinect.Toolkit.FaceTracking.dll 44 | 45 | 46 | False 47 | lib\Microsoft.Speech.dll 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | Form 65 | 66 | 67 | ExpressionMouseWindow.cs 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | ExpressionMouseWindow.cs 76 | 77 | 78 | ResXFileCodeGenerator 79 | Resources.Designer.cs 80 | Designer 81 | 82 | 83 | True 84 | Resources.resx 85 | 86 | 87 | SettingsSingleFileGenerator 88 | Settings.Designer.cs 89 | 90 | 91 | True 92 | Settings.settings 93 | True 94 | 95 | 96 | 97 | 104 | -------------------------------------------------------------------------------- /ExpressionMouse/ExpressionMouseWindow.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace ExpressionMouse 2 | { 3 | partial class ExpressionMouse 4 | { 5 | /// 6 | /// Erforderliche Designervariable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Verwendete Ressourcen bereinigen. 12 | /// 13 | /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Vom Windows Form-Designer generierter Code 24 | 25 | /// 26 | /// Erforderliche Methode für die Designerunterstützung. 27 | /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ExpressionMouse)); 33 | this.label1 = new System.Windows.Forms.Label(); 34 | this.label2 = new System.Windows.Forms.Label(); 35 | this.btStart = new System.Windows.Forms.Button(); 36 | this.btStop = new System.Windows.Forms.Button(); 37 | this.pbLeft = new System.Windows.Forms.PictureBox(); 38 | this.pbRight = new System.Windows.Forms.PictureBox(); 39 | this.label3 = new System.Windows.Forms.Label(); 40 | this.label4 = new System.Windows.Forms.Label(); 41 | this.label5 = new System.Windows.Forms.Label(); 42 | this.label7 = new System.Windows.Forms.Label(); 43 | this.label9 = new System.Windows.Forms.Label(); 44 | this.label10 = new System.Windows.Forms.Label(); 45 | this.label11 = new System.Windows.Forms.Label(); 46 | this.label12 = new System.Windows.Forms.Label(); 47 | this.label13 = new System.Windows.Forms.Label(); 48 | this.label15 = new System.Windows.Forms.Label(); 49 | this.label16 = new System.Windows.Forms.Label(); 50 | this.label17 = new System.Windows.Forms.Label(); 51 | this.label18 = new System.Windows.Forms.Label(); 52 | this.tbSmoothingFilter = new System.Windows.Forms.TextBox(); 53 | this.nudConvolutionFilterLength = new System.Windows.Forms.NumericUpDown(); 54 | this.nudEyeClosedFilterThreshold = new System.Windows.Forms.NumericUpDown(); 55 | this.nudDoubleClickSecondEyeThreshold = new System.Windows.Forms.NumericUpDown(); 56 | this.nudPercentageHorizontalEdgePixels = new System.Windows.Forms.NumericUpDown(); 57 | this.nudBrowRaiserStartThreshold = new System.Windows.Forms.NumericUpDown(); 58 | this.nudHeadToScreenRelationYHeight = new System.Windows.Forms.NumericUpDown(); 59 | this.nudMouthOpenStartThreshold = new System.Windows.Forms.NumericUpDown(); 60 | this.nudHeadToScreenRelationXWidth = new System.Windows.Forms.NumericUpDown(); 61 | this.nudMouthOpenConfirmation = new System.Windows.Forms.NumericUpDown(); 62 | this.nudScrollMultiplierDown = new System.Windows.Forms.NumericUpDown(); 63 | this.nudScrollMultiplierUp = new System.Windows.Forms.NumericUpDown(); 64 | this.nudMouthOpenEndThreshold = new System.Windows.Forms.NumericUpDown(); 65 | this.label19 = new System.Windows.Forms.Label(); 66 | this.label20 = new System.Windows.Forms.Label(); 67 | this.label21 = new System.Windows.Forms.Label(); 68 | this.nudBrowLowererStartThreshold = new System.Windows.Forms.NumericUpDown(); 69 | this.lbAction = new System.Windows.Forms.ListBox(); 70 | this.ttClickDelay = new System.Windows.Forms.ToolTip(this.components); 71 | this.btReset = new System.Windows.Forms.Button(); 72 | this.nudClickDelay = new System.Windows.Forms.NumericUpDown(); 73 | this.ssInformation = new System.Windows.Forms.StatusStrip(); 74 | this.lbStatus = new System.Windows.Forms.ToolStripStatusLabel(); 75 | this.tiCheckStatus = new System.Windows.Forms.Timer(this.components); 76 | ((System.ComponentModel.ISupportInitialize)(this.pbLeft)).BeginInit(); 77 | ((System.ComponentModel.ISupportInitialize)(this.pbRight)).BeginInit(); 78 | ((System.ComponentModel.ISupportInitialize)(this.nudConvolutionFilterLength)).BeginInit(); 79 | ((System.ComponentModel.ISupportInitialize)(this.nudEyeClosedFilterThreshold)).BeginInit(); 80 | ((System.ComponentModel.ISupportInitialize)(this.nudDoubleClickSecondEyeThreshold)).BeginInit(); 81 | ((System.ComponentModel.ISupportInitialize)(this.nudPercentageHorizontalEdgePixels)).BeginInit(); 82 | ((System.ComponentModel.ISupportInitialize)(this.nudBrowRaiserStartThreshold)).BeginInit(); 83 | ((System.ComponentModel.ISupportInitialize)(this.nudHeadToScreenRelationYHeight)).BeginInit(); 84 | ((System.ComponentModel.ISupportInitialize)(this.nudMouthOpenStartThreshold)).BeginInit(); 85 | ((System.ComponentModel.ISupportInitialize)(this.nudHeadToScreenRelationXWidth)).BeginInit(); 86 | ((System.ComponentModel.ISupportInitialize)(this.nudMouthOpenConfirmation)).BeginInit(); 87 | ((System.ComponentModel.ISupportInitialize)(this.nudScrollMultiplierDown)).BeginInit(); 88 | ((System.ComponentModel.ISupportInitialize)(this.nudScrollMultiplierUp)).BeginInit(); 89 | ((System.ComponentModel.ISupportInitialize)(this.nudMouthOpenEndThreshold)).BeginInit(); 90 | ((System.ComponentModel.ISupportInitialize)(this.nudBrowLowererStartThreshold)).BeginInit(); 91 | ((System.ComponentModel.ISupportInitialize)(this.nudClickDelay)).BeginInit(); 92 | this.ssInformation.SuspendLayout(); 93 | this.SuspendLayout(); 94 | // 95 | // label1 96 | // 97 | this.label1.AutoSize = true; 98 | this.label1.Location = new System.Drawing.Point(16, 0); 99 | this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 100 | this.label1.Name = "label1"; 101 | this.label1.Size = new System.Drawing.Size(93, 17); 102 | this.label1.TabIndex = 0; 103 | this.label1.Text = "Your left Eye:"; 104 | // 105 | // label2 106 | // 107 | this.label2.AutoSize = true; 108 | this.label2.Location = new System.Drawing.Point(157, 0); 109 | this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 110 | this.label2.Name = "label2"; 111 | this.label2.Size = new System.Drawing.Size(102, 17); 112 | this.label2.TabIndex = 1; 113 | this.label2.Text = "Your right Eye:"; 114 | // 115 | // btStart 116 | // 117 | this.btStart.Enabled = false; 118 | this.btStart.Location = new System.Drawing.Point(20, 556); 119 | this.btStart.Margin = new System.Windows.Forms.Padding(4); 120 | this.btStart.Name = "btStart"; 121 | this.btStart.Size = new System.Drawing.Size(140, 47); 122 | this.btStart.TabIndex = 2; 123 | this.btStart.Text = "Start"; 124 | this.btStart.UseVisualStyleBackColor = true; 125 | this.btStart.Click += new System.EventHandler(this.btStart_Click); 126 | // 127 | // btStop 128 | // 129 | this.btStop.Enabled = false; 130 | this.btStop.Location = new System.Drawing.Point(168, 556); 131 | this.btStop.Margin = new System.Windows.Forms.Padding(4); 132 | this.btStop.Name = "btStop"; 133 | this.btStop.Size = new System.Drawing.Size(127, 47); 134 | this.btStop.TabIndex = 3; 135 | this.btStop.Text = "Stop"; 136 | this.btStop.UseVisualStyleBackColor = true; 137 | this.btStop.Click += new System.EventHandler(this.btStop_Click); 138 | // 139 | // pbLeft 140 | // 141 | this.pbLeft.Location = new System.Drawing.Point(20, 21); 142 | this.pbLeft.Margin = new System.Windows.Forms.Padding(4); 143 | this.pbLeft.Name = "pbLeft"; 144 | this.pbLeft.Size = new System.Drawing.Size(89, 59); 145 | this.pbLeft.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 146 | this.pbLeft.TabIndex = 4; 147 | this.pbLeft.TabStop = false; 148 | // 149 | // pbRight 150 | // 151 | this.pbRight.Location = new System.Drawing.Point(166, 21); 152 | this.pbRight.Margin = new System.Windows.Forms.Padding(4); 153 | this.pbRight.Name = "pbRight"; 154 | this.pbRight.Size = new System.Drawing.Size(89, 59); 155 | this.pbRight.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 156 | this.pbRight.TabIndex = 5; 157 | this.pbRight.TabStop = false; 158 | // 159 | // label3 160 | // 161 | this.label3.AutoSize = true; 162 | this.label3.Location = new System.Drawing.Point(16, 84); 163 | this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 164 | this.label3.Name = "label3"; 165 | this.label3.Size = new System.Drawing.Size(77, 17); 166 | this.label3.TabIndex = 9; 167 | this.label3.Text = "Click Delay"; 168 | this.ttClickDelay.SetToolTip(this.label3, "Timespan in Frames which have to elapse between two mouse actions"); 169 | // 170 | // label4 171 | // 172 | this.label4.AutoSize = true; 173 | this.label4.Location = new System.Drawing.Point(16, 111); 174 | this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 175 | this.label4.Name = "label4"; 176 | this.label4.Size = new System.Drawing.Size(243, 17); 177 | this.label4.TabIndex = 10; 178 | this.label4.Text = "Headrotation Smoothing Filter Values"; 179 | this.ttClickDelay.SetToolTip(this.label4, "Weights for calculating weighted average of headrotation. Used for smoothing mous" + 180 | "e cursor."); 181 | // 182 | // label5 183 | // 184 | this.label5.AutoSize = true; 185 | this.label5.Location = new System.Drawing.Point(16, 174); 186 | this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 187 | this.label5.Name = "label5"; 188 | this.label5.Size = new System.Drawing.Size(247, 17); 189 | this.label5.TabIndex = 11; 190 | this.label5.Text = "Used Frames for closed eye detection"; 191 | this.ttClickDelay.SetToolTip(this.label5, "More frames increases accuracy in closed eye detection, but it also increases the" + 192 | " lag between closing eye and mouseclick."); 193 | // 194 | // label7 195 | // 196 | this.label7.AutoSize = true; 197 | this.label7.Location = new System.Drawing.Point(16, 270); 198 | this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 199 | this.label7.Name = "label7"; 200 | this.label7.Size = new System.Drawing.Size(186, 17); 201 | this.label7.TabIndex = 15; 202 | this.label7.Text = "Brow Raiser Start Threshold"; 203 | // 204 | // label9 205 | // 206 | this.label9.AutoSize = true; 207 | this.label9.Location = new System.Drawing.Point(16, 334); 208 | this.label9.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 209 | this.label9.Name = "label9"; 210 | this.label9.Size = new System.Drawing.Size(188, 17); 211 | this.label9.TabIndex = 17; 212 | this.label9.Text = "Mouth Open Start Threshold"; 213 | // 214 | // label10 215 | // 216 | this.label10.AutoSize = true; 217 | this.label10.Location = new System.Drawing.Point(16, 398); 218 | this.label10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 219 | this.label10.Name = "label10"; 220 | this.label10.Size = new System.Drawing.Size(183, 17); 221 | this.label10.TabIndex = 18; 222 | this.label10.Text = "Mouth Open End Threshold"; 223 | // 224 | // label11 225 | // 226 | this.label11.AutoSize = true; 227 | this.label11.Location = new System.Drawing.Point(16, 430); 228 | this.label11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 229 | this.label11.Name = "label11"; 230 | this.label11.Size = new System.Drawing.Size(125, 17); 231 | this.label11.TabIndex = 19; 232 | this.label11.Text = "Scroll Multiplier Up"; 233 | // 234 | // label12 235 | // 236 | this.label12.AutoSize = true; 237 | this.label12.Location = new System.Drawing.Point(16, 462); 238 | this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 239 | this.label12.Name = "label12"; 240 | this.label12.Size = new System.Drawing.Size(142, 17); 241 | this.label12.TabIndex = 20; 242 | this.label12.Text = "Scroll Multiplier Down"; 243 | // 244 | // label13 245 | // 246 | this.label13.AutoSize = true; 247 | this.label13.Location = new System.Drawing.Point(16, 494); 248 | this.label13.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 249 | this.label13.Name = "label13"; 250 | this.label13.Size = new System.Drawing.Size(214, 17); 251 | this.label13.TabIndex = 21; 252 | this.label13.Text = "HeadToScreenRelationX - Width"; 253 | // 254 | // label15 255 | // 256 | this.label15.AutoSize = true; 257 | this.label15.Location = new System.Drawing.Point(16, 366); 258 | this.label15.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 259 | this.label15.Name = "label15"; 260 | this.label15.Size = new System.Drawing.Size(169, 17); 261 | this.label15.TabIndex = 23; 262 | this.label15.Text = "Mouth Open Confirmation"; 263 | // 264 | // label16 265 | // 266 | this.label16.AutoSize = true; 267 | this.label16.Location = new System.Drawing.Point(16, 142); 268 | this.label16.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 269 | this.label16.Name = "label16"; 270 | this.label16.Size = new System.Drawing.Size(239, 17); 271 | this.label16.TabIndex = 24; 272 | this.label16.Text = "Percentage of horizontal edge Pixels"; 273 | this.ttClickDelay.SetToolTip(this.label16, "Used for closed eye detection. More horizontal edge pixels mean a higher probabil" + 274 | "ity for closed eye."); 275 | // 276 | // label17 277 | // 278 | this.label17.AutoSize = true; 279 | this.label17.Location = new System.Drawing.Point(16, 238); 280 | this.label17.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 281 | this.label17.Name = "label17"; 282 | this.label17.Size = new System.Drawing.Size(234, 17); 283 | this.label17.TabIndex = 25; 284 | this.label17.Text = "Double Click Second Eye Threshold"; 285 | this.ttClickDelay.SetToolTip(this.label17, "Threshold for second eye closing value. For differentiating between click and dou" + 286 | "ble click."); 287 | // 288 | // label18 289 | // 290 | this.label18.AutoSize = true; 291 | this.label18.Location = new System.Drawing.Point(16, 206); 292 | this.label18.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 293 | this.label18.Name = "label18"; 294 | this.label18.Size = new System.Drawing.Size(182, 17); 295 | this.label18.TabIndex = 26; 296 | this.label18.Text = "Eye Closed Filter Threshold"; 297 | // 298 | // tbSmoothingFilter 299 | // 300 | this.tbSmoothingFilter.Location = new System.Drawing.Point(269, 107); 301 | this.tbSmoothingFilter.Margin = new System.Windows.Forms.Padding(4); 302 | this.tbSmoothingFilter.Name = "tbSmoothingFilter"; 303 | this.tbSmoothingFilter.Size = new System.Drawing.Size(335, 22); 304 | this.tbSmoothingFilter.TabIndex = 28; 305 | this.tbSmoothingFilter.Text = "64, 55, 45, 35, 25, 20, 15, 10, 8, 7, 6, 5, 4, 3, 2, 1"; 306 | // 307 | // nudConvolutionFilterLength 308 | // 309 | this.nudConvolutionFilterLength.Location = new System.Drawing.Point(269, 171); 310 | this.nudConvolutionFilterLength.Margin = new System.Windows.Forms.Padding(4); 311 | this.nudConvolutionFilterLength.Name = "nudConvolutionFilterLength"; 312 | this.nudConvolutionFilterLength.Size = new System.Drawing.Size(336, 22); 313 | this.nudConvolutionFilterLength.TabIndex = 29; 314 | this.nudConvolutionFilterLength.Value = new decimal(new int[] { 315 | 10, 316 | 0, 317 | 0, 318 | 0}); 319 | // 320 | // nudEyeClosedFilterThreshold 321 | // 322 | this.nudEyeClosedFilterThreshold.DecimalPlaces = 2; 323 | this.nudEyeClosedFilterThreshold.Increment = new decimal(new int[] { 324 | 1, 325 | 0, 326 | 0, 327 | 65536}); 328 | this.nudEyeClosedFilterThreshold.Location = new System.Drawing.Point(269, 203); 329 | this.nudEyeClosedFilterThreshold.Margin = new System.Windows.Forms.Padding(4); 330 | this.nudEyeClosedFilterThreshold.Maximum = new decimal(new int[] { 331 | 1, 332 | 0, 333 | 0, 334 | 0}); 335 | this.nudEyeClosedFilterThreshold.Name = "nudEyeClosedFilterThreshold"; 336 | this.nudEyeClosedFilterThreshold.Size = new System.Drawing.Size(336, 22); 337 | this.nudEyeClosedFilterThreshold.TabIndex = 30; 338 | this.nudEyeClosedFilterThreshold.Value = new decimal(new int[] { 339 | 5, 340 | 0, 341 | 0, 342 | 65536}); 343 | // 344 | // nudDoubleClickSecondEyeThreshold 345 | // 346 | this.nudDoubleClickSecondEyeThreshold.DecimalPlaces = 2; 347 | this.nudDoubleClickSecondEyeThreshold.Increment = new decimal(new int[] { 348 | 5, 349 | 0, 350 | 0, 351 | 131072}); 352 | this.nudDoubleClickSecondEyeThreshold.Location = new System.Drawing.Point(269, 235); 353 | this.nudDoubleClickSecondEyeThreshold.Margin = new System.Windows.Forms.Padding(4); 354 | this.nudDoubleClickSecondEyeThreshold.Maximum = new decimal(new int[] { 355 | 1, 356 | 0, 357 | 0, 358 | 0}); 359 | this.nudDoubleClickSecondEyeThreshold.Name = "nudDoubleClickSecondEyeThreshold"; 360 | this.nudDoubleClickSecondEyeThreshold.Size = new System.Drawing.Size(336, 22); 361 | this.nudDoubleClickSecondEyeThreshold.TabIndex = 31; 362 | this.nudDoubleClickSecondEyeThreshold.Value = new decimal(new int[] { 363 | 18, 364 | 0, 365 | 0, 366 | 131072}); 367 | // 368 | // nudPercentageHorizontalEdgePixels 369 | // 370 | this.nudPercentageHorizontalEdgePixels.Location = new System.Drawing.Point(269, 139); 371 | this.nudPercentageHorizontalEdgePixels.Margin = new System.Windows.Forms.Padding(4); 372 | this.nudPercentageHorizontalEdgePixels.Name = "nudPercentageHorizontalEdgePixels"; 373 | this.nudPercentageHorizontalEdgePixels.Size = new System.Drawing.Size(336, 22); 374 | this.nudPercentageHorizontalEdgePixels.TabIndex = 32; 375 | this.nudPercentageHorizontalEdgePixels.Value = new decimal(new int[] { 376 | 68, 377 | 0, 378 | 0, 379 | 0}); 380 | // 381 | // nudBrowRaiserStartThreshold 382 | // 383 | this.nudBrowRaiserStartThreshold.DecimalPlaces = 2; 384 | this.nudBrowRaiserStartThreshold.Increment = new decimal(new int[] { 385 | 1, 386 | 0, 387 | 0, 388 | 131072}); 389 | this.nudBrowRaiserStartThreshold.Location = new System.Drawing.Point(269, 267); 390 | this.nudBrowRaiserStartThreshold.Margin = new System.Windows.Forms.Padding(4); 391 | this.nudBrowRaiserStartThreshold.Maximum = new decimal(new int[] { 392 | 1, 393 | 0, 394 | 0, 395 | 0}); 396 | this.nudBrowRaiserStartThreshold.Name = "nudBrowRaiserStartThreshold"; 397 | this.nudBrowRaiserStartThreshold.Size = new System.Drawing.Size(336, 22); 398 | this.nudBrowRaiserStartThreshold.TabIndex = 33; 399 | this.nudBrowRaiserStartThreshold.Value = new decimal(new int[] { 400 | 5, 401 | 0, 402 | 0, 403 | 65536}); 404 | // 405 | // nudHeadToScreenRelationYHeight 406 | // 407 | this.nudHeadToScreenRelationYHeight.Location = new System.Drawing.Point(269, 523); 408 | this.nudHeadToScreenRelationYHeight.Margin = new System.Windows.Forms.Padding(4); 409 | this.nudHeadToScreenRelationYHeight.Name = "nudHeadToScreenRelationYHeight"; 410 | this.nudHeadToScreenRelationYHeight.Size = new System.Drawing.Size(336, 22); 411 | this.nudHeadToScreenRelationYHeight.TabIndex = 34; 412 | this.nudHeadToScreenRelationYHeight.Value = new decimal(new int[] { 413 | 25, 414 | 0, 415 | 0, 416 | 0}); 417 | // 418 | // nudMouthOpenStartThreshold 419 | // 420 | this.nudMouthOpenStartThreshold.DecimalPlaces = 2; 421 | this.nudMouthOpenStartThreshold.Increment = new decimal(new int[] { 422 | 5, 423 | 0, 424 | 0, 425 | 131072}); 426 | this.nudMouthOpenStartThreshold.Location = new System.Drawing.Point(269, 331); 427 | this.nudMouthOpenStartThreshold.Margin = new System.Windows.Forms.Padding(4); 428 | this.nudMouthOpenStartThreshold.Maximum = new decimal(new int[] { 429 | 1, 430 | 0, 431 | 0, 432 | 0}); 433 | this.nudMouthOpenStartThreshold.Name = "nudMouthOpenStartThreshold"; 434 | this.nudMouthOpenStartThreshold.Size = new System.Drawing.Size(336, 22); 435 | this.nudMouthOpenStartThreshold.TabIndex = 35; 436 | this.nudMouthOpenStartThreshold.Value = new decimal(new int[] { 437 | 75, 438 | 0, 439 | 0, 440 | 131072}); 441 | // 442 | // nudHeadToScreenRelationXWidth 443 | // 444 | this.nudHeadToScreenRelationXWidth.Location = new System.Drawing.Point(269, 491); 445 | this.nudHeadToScreenRelationXWidth.Margin = new System.Windows.Forms.Padding(4); 446 | this.nudHeadToScreenRelationXWidth.Name = "nudHeadToScreenRelationXWidth"; 447 | this.nudHeadToScreenRelationXWidth.Size = new System.Drawing.Size(336, 22); 448 | this.nudHeadToScreenRelationXWidth.TabIndex = 40; 449 | this.nudHeadToScreenRelationXWidth.Value = new decimal(new int[] { 450 | 35, 451 | 0, 452 | 0, 453 | 0}); 454 | // 455 | // nudMouthOpenConfirmation 456 | // 457 | this.nudMouthOpenConfirmation.DecimalPlaces = 2; 458 | this.nudMouthOpenConfirmation.Increment = new decimal(new int[] { 459 | 5, 460 | 0, 461 | 0, 462 | 131072}); 463 | this.nudMouthOpenConfirmation.Location = new System.Drawing.Point(269, 363); 464 | this.nudMouthOpenConfirmation.Margin = new System.Windows.Forms.Padding(4); 465 | this.nudMouthOpenConfirmation.Maximum = new decimal(new int[] { 466 | 1, 467 | 0, 468 | 0, 469 | 0}); 470 | this.nudMouthOpenConfirmation.Name = "nudMouthOpenConfirmation"; 471 | this.nudMouthOpenConfirmation.Size = new System.Drawing.Size(336, 22); 472 | this.nudMouthOpenConfirmation.TabIndex = 39; 473 | this.nudMouthOpenConfirmation.Value = new decimal(new int[] { 474 | 5, 475 | 0, 476 | 0, 477 | 65536}); 478 | // 479 | // nudScrollMultiplierDown 480 | // 481 | this.nudScrollMultiplierDown.Increment = new decimal(new int[] { 482 | 10, 483 | 0, 484 | 0, 485 | 0}); 486 | this.nudScrollMultiplierDown.Location = new System.Drawing.Point(269, 459); 487 | this.nudScrollMultiplierDown.Margin = new System.Windows.Forms.Padding(4); 488 | this.nudScrollMultiplierDown.Maximum = new decimal(new int[] { 489 | 10000, 490 | 0, 491 | 0, 492 | 0}); 493 | this.nudScrollMultiplierDown.Name = "nudScrollMultiplierDown"; 494 | this.nudScrollMultiplierDown.Size = new System.Drawing.Size(336, 22); 495 | this.nudScrollMultiplierDown.TabIndex = 38; 496 | this.nudScrollMultiplierDown.Value = new decimal(new int[] { 497 | 250, 498 | 0, 499 | 0, 500 | 0}); 501 | // 502 | // nudScrollMultiplierUp 503 | // 504 | this.nudScrollMultiplierUp.Increment = new decimal(new int[] { 505 | 10, 506 | 0, 507 | 0, 508 | 0}); 509 | this.nudScrollMultiplierUp.Location = new System.Drawing.Point(269, 427); 510 | this.nudScrollMultiplierUp.Margin = new System.Windows.Forms.Padding(4); 511 | this.nudScrollMultiplierUp.Maximum = new decimal(new int[] { 512 | 10000, 513 | 0, 514 | 0, 515 | 0}); 516 | this.nudScrollMultiplierUp.Name = "nudScrollMultiplierUp"; 517 | this.nudScrollMultiplierUp.Size = new System.Drawing.Size(336, 22); 518 | this.nudScrollMultiplierUp.TabIndex = 37; 519 | this.nudScrollMultiplierUp.Value = new decimal(new int[] { 520 | 150, 521 | 0, 522 | 0, 523 | 0}); 524 | // 525 | // nudMouthOpenEndThreshold 526 | // 527 | this.nudMouthOpenEndThreshold.DecimalPlaces = 2; 528 | this.nudMouthOpenEndThreshold.Increment = new decimal(new int[] { 529 | 1, 530 | 0, 531 | 0, 532 | 131072}); 533 | this.nudMouthOpenEndThreshold.Location = new System.Drawing.Point(269, 395); 534 | this.nudMouthOpenEndThreshold.Margin = new System.Windows.Forms.Padding(4); 535 | this.nudMouthOpenEndThreshold.Maximum = new decimal(new int[] { 536 | 1, 537 | 0, 538 | 0, 539 | 0}); 540 | this.nudMouthOpenEndThreshold.Name = "nudMouthOpenEndThreshold"; 541 | this.nudMouthOpenEndThreshold.Size = new System.Drawing.Size(336, 22); 542 | this.nudMouthOpenEndThreshold.TabIndex = 36; 543 | this.nudMouthOpenEndThreshold.Value = new decimal(new int[] { 544 | 25, 545 | 0, 546 | 0, 547 | 131072}); 548 | // 549 | // label19 550 | // 551 | this.label19.AutoSize = true; 552 | this.label19.Location = new System.Drawing.Point(635, 55); 553 | this.label19.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 554 | this.label19.Name = "label19"; 555 | this.label19.Size = new System.Drawing.Size(107, 17); 556 | this.label19.TabIndex = 43; 557 | this.label19.Text = "Action Protocol:"; 558 | // 559 | // label20 560 | // 561 | this.label20.AutoSize = true; 562 | this.label20.Location = new System.Drawing.Point(16, 302); 563 | this.label20.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 564 | this.label20.Name = "label20"; 565 | this.label20.Size = new System.Drawing.Size(196, 17); 566 | this.label20.TabIndex = 44; 567 | this.label20.Text = "Brow Lowerer Start Threshold"; 568 | // 569 | // label21 570 | // 571 | this.label21.AutoSize = true; 572 | this.label21.Location = new System.Drawing.Point(16, 526); 573 | this.label21.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 574 | this.label21.Name = "label21"; 575 | this.label21.Size = new System.Drawing.Size(219, 17); 576 | this.label21.TabIndex = 45; 577 | this.label21.Text = "HeadToScreenRelationY - Height"; 578 | // 579 | // nudBrowLowererStartThreshold 580 | // 581 | this.nudBrowLowererStartThreshold.DecimalPlaces = 2; 582 | this.nudBrowLowererStartThreshold.Increment = new decimal(new int[] { 583 | 1, 584 | 0, 585 | 0, 586 | 131072}); 587 | this.nudBrowLowererStartThreshold.Location = new System.Drawing.Point(269, 299); 588 | this.nudBrowLowererStartThreshold.Margin = new System.Windows.Forms.Padding(4); 589 | this.nudBrowLowererStartThreshold.Maximum = new decimal(new int[] { 590 | 1, 591 | 0, 592 | 0, 593 | 0}); 594 | this.nudBrowLowererStartThreshold.Name = "nudBrowLowererStartThreshold"; 595 | this.nudBrowLowererStartThreshold.Size = new System.Drawing.Size(336, 22); 596 | this.nudBrowLowererStartThreshold.TabIndex = 46; 597 | this.nudBrowLowererStartThreshold.Value = new decimal(new int[] { 598 | 16, 599 | 0, 600 | 0, 601 | 131072}); 602 | // 603 | // lbAction 604 | // 605 | this.lbAction.FormattingEnabled = true; 606 | this.lbAction.ItemHeight = 16; 607 | this.lbAction.Location = new System.Drawing.Point(639, 79); 608 | this.lbAction.Margin = new System.Windows.Forms.Padding(4); 609 | this.lbAction.Name = "lbAction"; 610 | this.lbAction.Size = new System.Drawing.Size(443, 468); 611 | this.lbAction.TabIndex = 47; 612 | // 613 | // ttClickDelay 614 | // 615 | this.ttClickDelay.Popup += new System.Windows.Forms.PopupEventHandler(this.ttClickDelay_Popup); 616 | // 617 | // btReset 618 | // 619 | this.btReset.Location = new System.Drawing.Point(303, 555); 620 | this.btReset.Margin = new System.Windows.Forms.Padding(4); 621 | this.btReset.Name = "btReset"; 622 | this.btReset.Size = new System.Drawing.Size(139, 48); 623 | this.btReset.TabIndex = 51; 624 | this.btReset.Text = "Reset values"; 625 | this.btReset.UseVisualStyleBackColor = true; 626 | this.btReset.Click += new System.EventHandler(this.btReset_Click); 627 | // 628 | // nudClickDelay 629 | // 630 | this.nudClickDelay.Location = new System.Drawing.Point(269, 79); 631 | this.nudClickDelay.Margin = new System.Windows.Forms.Padding(4); 632 | this.nudClickDelay.Maximum = new decimal(new int[] { 633 | 1000, 634 | 0, 635 | 0, 636 | 0}); 637 | this.nudClickDelay.Name = "nudClickDelay"; 638 | this.nudClickDelay.Size = new System.Drawing.Size(336, 22); 639 | this.nudClickDelay.TabIndex = 52; 640 | this.nudClickDelay.Value = new decimal(new int[] { 641 | 20, 642 | 0, 643 | 0, 644 | 0}); 645 | // 646 | // ssInformation 647 | // 648 | this.ssInformation.ImageScalingSize = new System.Drawing.Size(20, 20); 649 | this.ssInformation.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 650 | this.lbStatus}); 651 | this.ssInformation.Location = new System.Drawing.Point(0, 607); 652 | this.ssInformation.Name = "ssInformation"; 653 | this.ssInformation.Size = new System.Drawing.Size(1099, 33); 654 | this.ssInformation.TabIndex = 53; 655 | this.ssInformation.Text = "statusStrip1"; 656 | // 657 | // lbStatus 658 | // 659 | this.lbStatus.Name = "lbStatus"; 660 | this.lbStatus.Size = new System.Drawing.Size(331, 28); 661 | this.lbStatus.Text = "Initializing Kinect... Looking for face..."; 662 | // 663 | // tiCheckStatus 664 | // 665 | this.tiCheckStatus.Enabled = true; 666 | this.tiCheckStatus.Interval = 2000; 667 | this.tiCheckStatus.Tick += new System.EventHandler(this.tiCheckStatus_Tick); 668 | // 669 | // ExpressionMouse 670 | // 671 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 672 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 673 | this.ClientSize = new System.Drawing.Size(1099, 640); 674 | this.Controls.Add(this.ssInformation); 675 | this.Controls.Add(this.nudClickDelay); 676 | this.Controls.Add(this.btReset); 677 | this.Controls.Add(this.lbAction); 678 | this.Controls.Add(this.nudBrowLowererStartThreshold); 679 | this.Controls.Add(this.label21); 680 | this.Controls.Add(this.label20); 681 | this.Controls.Add(this.label19); 682 | this.Controls.Add(this.nudHeadToScreenRelationXWidth); 683 | this.Controls.Add(this.nudMouthOpenConfirmation); 684 | this.Controls.Add(this.nudScrollMultiplierDown); 685 | this.Controls.Add(this.nudScrollMultiplierUp); 686 | this.Controls.Add(this.nudMouthOpenEndThreshold); 687 | this.Controls.Add(this.nudMouthOpenStartThreshold); 688 | this.Controls.Add(this.nudHeadToScreenRelationYHeight); 689 | this.Controls.Add(this.nudBrowRaiserStartThreshold); 690 | this.Controls.Add(this.nudPercentageHorizontalEdgePixels); 691 | this.Controls.Add(this.nudDoubleClickSecondEyeThreshold); 692 | this.Controls.Add(this.nudEyeClosedFilterThreshold); 693 | this.Controls.Add(this.nudConvolutionFilterLength); 694 | this.Controls.Add(this.tbSmoothingFilter); 695 | this.Controls.Add(this.label18); 696 | this.Controls.Add(this.label17); 697 | this.Controls.Add(this.label16); 698 | this.Controls.Add(this.label15); 699 | this.Controls.Add(this.label13); 700 | this.Controls.Add(this.label12); 701 | this.Controls.Add(this.label11); 702 | this.Controls.Add(this.label10); 703 | this.Controls.Add(this.label9); 704 | this.Controls.Add(this.label7); 705 | this.Controls.Add(this.label5); 706 | this.Controls.Add(this.label4); 707 | this.Controls.Add(this.label3); 708 | this.Controls.Add(this.pbRight); 709 | this.Controls.Add(this.pbLeft); 710 | this.Controls.Add(this.btStop); 711 | this.Controls.Add(this.btStart); 712 | this.Controls.Add(this.label2); 713 | this.Controls.Add(this.label1); 714 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 715 | this.Margin = new System.Windows.Forms.Padding(4); 716 | this.Name = "ExpressionMouse"; 717 | this.Text = "Kinect ExpressionMouse"; 718 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FaceMouseConfig_FormClosing); 719 | this.Load += new System.EventHandler(this.FaceMouseConfig_Load); 720 | ((System.ComponentModel.ISupportInitialize)(this.pbLeft)).EndInit(); 721 | ((System.ComponentModel.ISupportInitialize)(this.pbRight)).EndInit(); 722 | ((System.ComponentModel.ISupportInitialize)(this.nudConvolutionFilterLength)).EndInit(); 723 | ((System.ComponentModel.ISupportInitialize)(this.nudEyeClosedFilterThreshold)).EndInit(); 724 | ((System.ComponentModel.ISupportInitialize)(this.nudDoubleClickSecondEyeThreshold)).EndInit(); 725 | ((System.ComponentModel.ISupportInitialize)(this.nudPercentageHorizontalEdgePixels)).EndInit(); 726 | ((System.ComponentModel.ISupportInitialize)(this.nudBrowRaiserStartThreshold)).EndInit(); 727 | ((System.ComponentModel.ISupportInitialize)(this.nudHeadToScreenRelationYHeight)).EndInit(); 728 | ((System.ComponentModel.ISupportInitialize)(this.nudMouthOpenStartThreshold)).EndInit(); 729 | ((System.ComponentModel.ISupportInitialize)(this.nudHeadToScreenRelationXWidth)).EndInit(); 730 | ((System.ComponentModel.ISupportInitialize)(this.nudMouthOpenConfirmation)).EndInit(); 731 | ((System.ComponentModel.ISupportInitialize)(this.nudScrollMultiplierDown)).EndInit(); 732 | ((System.ComponentModel.ISupportInitialize)(this.nudScrollMultiplierUp)).EndInit(); 733 | ((System.ComponentModel.ISupportInitialize)(this.nudMouthOpenEndThreshold)).EndInit(); 734 | ((System.ComponentModel.ISupportInitialize)(this.nudBrowLowererStartThreshold)).EndInit(); 735 | ((System.ComponentModel.ISupportInitialize)(this.nudClickDelay)).EndInit(); 736 | this.ssInformation.ResumeLayout(false); 737 | this.ssInformation.PerformLayout(); 738 | this.ResumeLayout(false); 739 | this.PerformLayout(); 740 | 741 | } 742 | 743 | #endregion 744 | 745 | private System.Windows.Forms.Label label1; 746 | private System.Windows.Forms.Label label2; 747 | private System.Windows.Forms.Button btStart; 748 | private System.Windows.Forms.Button btStop; 749 | private System.Windows.Forms.PictureBox pbLeft; 750 | private System.Windows.Forms.PictureBox pbRight; 751 | private System.Windows.Forms.Label label3; 752 | private System.Windows.Forms.Label label4; 753 | private System.Windows.Forms.Label label5; 754 | private System.Windows.Forms.Label label7; 755 | private System.Windows.Forms.Label label9; 756 | private System.Windows.Forms.Label label10; 757 | private System.Windows.Forms.Label label11; 758 | private System.Windows.Forms.Label label12; 759 | private System.Windows.Forms.Label label13; 760 | private System.Windows.Forms.Label label15; 761 | private System.Windows.Forms.Label label16; 762 | private System.Windows.Forms.Label label17; 763 | private System.Windows.Forms.Label label18; 764 | private System.Windows.Forms.TextBox tbSmoothingFilter; 765 | private System.Windows.Forms.NumericUpDown nudConvolutionFilterLength; 766 | private System.Windows.Forms.NumericUpDown nudEyeClosedFilterThreshold; 767 | private System.Windows.Forms.NumericUpDown nudDoubleClickSecondEyeThreshold; 768 | private System.Windows.Forms.NumericUpDown nudPercentageHorizontalEdgePixels; 769 | private System.Windows.Forms.NumericUpDown nudBrowRaiserStartThreshold; 770 | private System.Windows.Forms.NumericUpDown nudHeadToScreenRelationYHeight; 771 | private System.Windows.Forms.NumericUpDown nudMouthOpenStartThreshold; 772 | private System.Windows.Forms.NumericUpDown nudHeadToScreenRelationXWidth; 773 | private System.Windows.Forms.NumericUpDown nudMouthOpenConfirmation; 774 | private System.Windows.Forms.NumericUpDown nudScrollMultiplierDown; 775 | private System.Windows.Forms.NumericUpDown nudScrollMultiplierUp; 776 | private System.Windows.Forms.NumericUpDown nudMouthOpenEndThreshold; 777 | private System.Windows.Forms.Label label19; 778 | private System.Windows.Forms.Label label20; 779 | private System.Windows.Forms.Label label21; 780 | private System.Windows.Forms.NumericUpDown nudBrowLowererStartThreshold; 781 | private System.Windows.Forms.ListBox lbAction; 782 | private System.Windows.Forms.ToolTip ttClickDelay; 783 | private System.Windows.Forms.Button btReset; 784 | private System.Windows.Forms.NumericUpDown nudClickDelay; 785 | private System.Windows.Forms.StatusStrip ssInformation; 786 | private System.Windows.Forms.ToolStripStatusLabel lbStatus; 787 | private System.Windows.Forms.Timer tiCheckStatus; 788 | } 789 | } 790 | 791 | -------------------------------------------------------------------------------- /ExpressionMouse/ExpressionMouseWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Drawing; 5 | using System.Linq; 6 | using System.Windows.Forms; 7 | using System.IO; 8 | using System.Threading; 9 | using Microsoft.Kinect; 10 | using Microsoft.Kinect.Toolkit.FaceTracking; 11 | using System.Xml.Serialization; 12 | using System.Xml; 13 | using Microsoft.Speech.Recognition; 14 | using Microsoft.Speech.AudioFormat; 15 | 16 | namespace ExpressionMouse 17 | { 18 | public partial class ExpressionMouse : Form 19 | { 20 | #region Properties 21 | 22 | private Thread Workerthread; 23 | private KinectSensor Kinect = null; 24 | private FaceTracker faceTracker = null; 25 | private bool DragnDropActive = false; 26 | private List mousePositionHistory = new List(); 27 | private List mouthOpenHistory = new List(); 28 | private List browLowererHistory = new List(); 29 | private List browRaiserHistory = new List(); 30 | private byte[] colorImage; 31 | private ColorImageFormat colorImageFormat = ColorImageFormat.Undefined; 32 | private short[] depthImage; 33 | List gaussFilter = new List(); 34 | private DepthImageFormat depthImageFormat = DepthImageFormat.Undefined; 35 | private SpeechRecognitionEngine speechRecognitionEngine; 36 | public Skeleton[] SkeletonData { get; set; } 37 | private List rightEyeClosedHistory = new List(); 38 | private List leftEyeClosedHistory = new List(); 39 | private List headRotationHistory = new List(); 40 | double gaussFactor = 0; 41 | int clickDelay = 100; 42 | private bool useSpeach = false; 43 | private StatusEnum status = StatusEnum.Initializing; 44 | private DateTime lastFramesReady; 45 | #endregion 46 | 47 | #region 48 | #endregion 49 | 50 | public ExpressionMouse() 51 | { 52 | InitializeComponent(); 53 | 54 | //Try to read the file 55 | TextReader textReader = null; 56 | try 57 | { 58 | XmlDocument xmlDoc = new XmlDocument(); //* create an xml document object. 59 | XmlSerializer deserializer = new XmlSerializer(typeof(Settings)); 60 | textReader = new StreamReader(@"settings.xml"); 61 | Settings setting; 62 | setting = (Settings)deserializer.Deserialize(textReader); 63 | this.nudBrowLowererStartThreshold.Value = setting.BrowLowererStartthreshold; 64 | this.nudBrowRaiserStartThreshold.Value = setting.BrowRaiserStartThreshold; 65 | this.nudClickDelay.Value = setting.ClickDelay; 66 | this.nudConvolutionFilterLength.Value = setting.UsedFramesForClosedEyeDetection; 67 | this.nudDoubleClickSecondEyeThreshold.Value = setting.DoubleClickSecondEyeThreshold; 68 | this.nudEyeClosedFilterThreshold.Value = setting.EyeClosedFilterThreshold; 69 | this.nudHeadToScreenRelationXWidth.Value = setting.HeadToScreenRelationX; 70 | this.nudHeadToScreenRelationYHeight.Value = setting.HeadToScreenRelationY; 71 | this.nudMouthOpenConfirmation.Value = setting.MouthOpenConfirmation; 72 | this.nudMouthOpenEndThreshold.Value = setting.MouthOpenEndThreshold; 73 | this.nudMouthOpenStartThreshold.Value = setting.MouthOpenStartThreshold; 74 | this.nudPercentageHorizontalEdgePixels.Value = setting.PercentageHorizontalEdgePixels; 75 | this.nudScrollMultiplierDown.Value = setting.ScrollMultiplierDown; 76 | this.nudScrollMultiplierUp.Value = setting.ScrollMultiplierUp; 77 | this.tbSmoothingFilter.Text = setting.HeadrotationSmoothingFilterValues; 78 | } 79 | catch (Exception e) 80 | { 81 | } 82 | finally 83 | { 84 | if (textReader != null) 85 | { 86 | textReader.Close(); 87 | } 88 | } 89 | } 90 | 91 | private void Init() 92 | { 93 | try 94 | { 95 | string[] splitString = { ", " }; 96 | gaussFactor = 0; 97 | gaussFilter.Clear(); 98 | string[] filterValues = tbSmoothingFilter.Text.Split(splitString, StringSplitOptions.None); 99 | 100 | foreach (var filterValue in filterValues) 101 | { 102 | int value = Int32.Parse(filterValue); 103 | gaussFilter.Add(value); 104 | gaussFactor += value; 105 | } 106 | Kinect = KinectSensor.KinectSensors.FirstOrDefault(s => s.Status == KinectStatus.Connected); // Get first Kinect Sensor 107 | Kinect.SkeletonStream.Enable(); // Enable skeletal tracking 108 | Kinect.ColorStream.Enable(); 109 | Kinect.DepthStream.Enable(); 110 | SkeletonData = new Skeleton[Kinect.SkeletonStream.FrameSkeletonArrayLength]; // Allocate ST data 111 | Kinect.Start(); // Start Kinect sensor 112 | faceTracker = new FaceTracker(Kinect); 113 | Kinect.AllFramesReady += this.OnAllFramesReady; 114 | 115 | //Set Near and Seated Mode 116 | //Not available for Xbox Sensor! 117 | Kinect.SkeletonStream.EnableTrackingInNearRange = true; 118 | Kinect.DepthStream.Range = DepthRange.Near; 119 | Kinect.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated; 120 | File.AppendAllText("init.txt",DateTime.Now+" - Kinect sensor initialized successfully.\n"); 121 | useSpeach = InitSpeechRecognition(); 122 | } 123 | catch (Exception e) 124 | { 125 | System.Windows.MessageBox.Show("Error during Kinect Initialization. Ensure that Kinect sensor is connected correctly.\n\nError Message:\n" + e.ToString()); 126 | File.AppendAllText("init.txt", DateTime.Now + " - Error during Kinect initialization.\n"); 127 | } 128 | } 129 | 130 | private bool InitSpeechRecognition() 131 | { 132 | RecognizerInfo ri = GetKinetSpeechRecognizer(); 133 | 134 | if (null != ri) 135 | { 136 | this.speechRecognitionEngine = new SpeechRecognitionEngine(ri.Id); 137 | 138 | 139 | var commands = new Choices(); 140 | commands.Add(new SemanticResultValue("Mouse Start", "MOUSE START")); 141 | commands.Add(new SemanticResultValue("Mouse Off", "MOUSE OFF")); 142 | 143 | var gb = new GrammarBuilder { Culture = ri.Culture }; 144 | gb.Append(commands); 145 | var g = new Grammar(gb); 146 | speechRecognitionEngine.LoadGrammar(g); 147 | 148 | speechRecognitionEngine.SpeechRecognized += SpeechRecognized; 149 | speechRecognitionEngine.SpeechRecognitionRejected += SpeechRejected; 150 | 151 | // For long recognition sessions (a few hours or more), it may be beneficial to turn off adaptation of the acoustic model. 152 | // This will prevent recognition accuracy from degrading over time. 153 | ////speechEngine.UpdateRecognizerSetting("AdaptationOn", 0); 154 | 155 | speechRecognitionEngine.SetInputToAudioStream( 156 | Kinect.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null)); 157 | speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple); 158 | return true; 159 | } 160 | return false; 161 | } 162 | 163 | private void SpeechRejected(object sender, SpeechRecognitionRejectedEventArgs e) 164 | { 165 | } 166 | 167 | private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 168 | { 169 | if (useSpeach) 170 | { 171 | // Speech utterance confidence below which we treat speech as if it hadn't been heard 172 | const double ConfidenceThreshold = 0.3; 173 | if (e.Result.Confidence >= ConfidenceThreshold) 174 | { 175 | switch (e.Result.Semantics.Value.ToString()) 176 | { 177 | case "MOUSE START": 178 | StartKinectControl(); 179 | break; 180 | case "MOUSE OFF": 181 | StopKinectControl(); 182 | break; 183 | 184 | } 185 | } 186 | } 187 | } 188 | 189 | /// 190 | /// Gets the metadata for the speech recognizer (acoustic model) most suitable to 191 | /// process audio from Kinect device. 192 | /// 193 | /// 194 | /// RecognizerInfo if found, null otherwise. 195 | /// 196 | private static RecognizerInfo GetKinetSpeechRecognizer() 197 | { 198 | foreach (RecognizerInfo recognizer in SpeechRecognitionEngine.InstalledRecognizers()) 199 | { 200 | string value; 201 | recognizer.AdditionalInfo.TryGetValue("Kinect", out value); 202 | if ("True".Equals(value, StringComparison.OrdinalIgnoreCase) && "en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase)) 203 | { 204 | return recognizer; 205 | } 206 | } 207 | return null; 208 | } 209 | 210 | private void SwitchStatus(StatusEnum newStatus) 211 | { 212 | if (newStatus == StatusEnum.ReadyActivated) 213 | { 214 | lbStatus.Text = "Face control ACTIVE. \"MOUSE OFF\" will stop the mouse."; 215 | this.btStart.BeginInvoke((MethodInvoker)(() => this.btStart.Enabled = false)); 216 | this.btStop.BeginInvoke((MethodInvoker)(() => this.btStop.Enabled = true)); 217 | this.status = newStatus; 218 | } 219 | else if (newStatus == StatusEnum.ReadyDeactivated) 220 | { 221 | lbStatus.Text = "Kinect Ready. Say \"MOUSE START\""; 222 | this.btStart.BeginInvoke((MethodInvoker)(() => this.btStart.Enabled = true)); 223 | this.btStop.BeginInvoke((MethodInvoker)(() => this.btStop.Enabled = false)); 224 | } 225 | else if (newStatus == StatusEnum.UnreadyDeactivated) 226 | { 227 | lbStatus.Text = "Lost Skeleton or face... Trying to recognize person..."; 228 | } 229 | else if (newStatus == StatusEnum.Initializing) 230 | lbStatus.Text = "Initializing. Trying to recognize person..."; 231 | this.status = newStatus; 232 | } 233 | 234 | private void btStart_Click(object sender, EventArgs e) 235 | { 236 | StartKinectControl(); 237 | } 238 | 239 | private void StartKinectControl() 240 | { 241 | if (this.status == StatusEnum.ReadyDeactivated) 242 | SwitchStatus(StatusEnum.ReadyActivated); 243 | } 244 | 245 | private void InitializeKinect() 246 | { 247 | Workerthread = new Thread(this.Init); 248 | Workerthread.Start(); 249 | } 250 | 251 | private void SetPictures(Bitmap leftEye, Bitmap rightEye) 252 | { 253 | pbLeft.Image = rightEye; 254 | pbRight.Image = leftEye; 255 | } 256 | 257 | private void OnAllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs) 258 | { 259 | ColorImageFrame colorImageFrame = null; 260 | DepthImageFrame depthImageFrame = null; 261 | SkeletonFrame skeletonFrame = null; 262 | File.AppendAllText("mouseLog.txt", DateTime.Now + " - All Kinect frames ready.\n"); 263 | try 264 | { 265 | colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame(); 266 | depthImageFrame = allFramesReadyEventArgs.OpenDepthImageFrame(); 267 | skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame(); 268 | 269 | if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null) 270 | { 271 | File.AppendAllText("mouseLog.txt", DateTime.Now + " - Color- depth or Skeletonframe is null. Aborting Frame.\n"); 272 | return; 273 | } 274 | else //if (status == StatusEnum.ReadyActivated || status == StatusEnum.Initializing || status == StatusEnum.UnreadyDeactivated) 275 | { 276 | // Check for image format changes. The FaceTracker doesn't 277 | // deal with that so we need to reset. 278 | HandlePossibleImageFormatChanges(colorImageFrame, depthImageFrame); 279 | WriteDataToMembers(colorImageFrame, depthImageFrame, skeletonFrame); 280 | Skeleton activeSkeleton = null; 281 | activeSkeleton = (from skel in this.SkeletonData where skel.TrackingState == SkeletonTrackingState.Tracked select skel).FirstOrDefault(); 282 | 283 | if (activeSkeleton != null) 284 | { 285 | File.AppendAllText("mouseLog.txt", DateTime.Now + " - Skeleton is there. Trying to find face.\n"); 286 | FaceTrackFrame currentFaceFrame = faceTracker.Track(ColorImageFormat.RgbResolution640x480Fps30, colorImage, depthImageFormat, depthImage, activeSkeleton); 287 | LogFaceDetection(currentFaceFrame); 288 | 289 | //Get relevant Points for blink detection 290 | //Left eye 291 | int minX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveOneFourthLeftEyelid].X); 292 | int minY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveOneFourthLeftEyelid].Y); 293 | int maxX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.BelowThreeFourthLeftEyelid].X); 294 | int maxY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.BelowThreeFourthLeftEyelid].Y); 295 | Bitmap leftEye = EyeExtract(colorImageFrame, currentFaceFrame, minX, minY, maxX, maxY, false); 296 | 297 | //Right eye 298 | minX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveThreeFourthRightEyelid].X); 299 | minY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveThreeFourthRightEyelid].Y); 300 | maxX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.OneFourthBottomRightEyelid].X); 301 | maxY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.OneFourthBottomRightEyelid].Y); 302 | 303 | Bitmap rightEye = EyeExtract(colorImageFrame, currentFaceFrame, minX, minY, maxX, maxY, true); 304 | Bitmap leftEye2 = null; 305 | Bitmap rightEye2 = null; 306 | if (leftEye != null) 307 | leftEye2 = new Bitmap(leftEye); 308 | if (rightEye != null) 309 | rightEye2 = new Bitmap(rightEye); 310 | 311 | this.pbLeft.BeginInvoke((MethodInvoker)(() => this.pbLeft.Image = rightEye2)); 312 | this.pbLeft.BeginInvoke((MethodInvoker)(() => this.pbRight.Image = leftEye2)); 313 | 314 | //Wende Kantenfilter auf die beiden Augen an. 315 | if (rightEye != null && leftEye != null) 316 | { 317 | Dictionary angleCount; 318 | Bitmap edgePicRight = Convolution(ConvertGrey(rightEye), true, out angleCount); 319 | bool rightEyeClosed = IsEyeClosed(angleCount); 320 | Bitmap edgePicLeft = Convolution(ConvertGrey(leftEye), false, out angleCount); 321 | bool leftEyeClosed = IsEyeClosed(angleCount); 322 | 323 | if (rightEyeClosedHistory.Count > 100) 324 | rightEyeClosedHistory.RemoveAt(0); 325 | if (leftEyeClosedHistory.Count > 100) 326 | leftEyeClosedHistory.RemoveAt(0); 327 | leftEyeClosedHistory.Add(leftEyeClosed); 328 | rightEyeClosedHistory.Add(rightEyeClosed); 329 | 330 | //If Face is rotated, move Mouse 331 | MoveMouseAccordingToFaceRotation(currentFaceFrame); 332 | } 333 | else 334 | { 335 | File.AppendAllText("mouseLog.txt", DateTime.Now + " - Face recognized but couldn't find eye in face.\n"); 336 | } 337 | clickDelay++; 338 | 339 | headRotationHistory.Add(currentFaceFrame.Rotation); 340 | if (headRotationHistory.Count >= 100) 341 | headRotationHistory.RemoveAt(0); 342 | } 343 | else 344 | { 345 | File.AppendAllText("mouseLog.txt", DateTime.Now + " - Active Skeleton is null. Couldn't analyze frame.\n"); 346 | } 347 | } 348 | } 349 | catch (Exception e) 350 | { 351 | File.AppendAllText("mouseLog.txt", DateTime.Now + " - Error during frame analyzation.\n"+e.ToString()); 352 | } 353 | finally 354 | { 355 | if (colorImageFrame != null) 356 | colorImageFrame.Dispose(); 357 | 358 | if (depthImageFrame != null) 359 | depthImageFrame.Dispose(); 360 | 361 | if (skeletonFrame != null) 362 | skeletonFrame.Dispose(); 363 | } 364 | } 365 | 366 | private void SetReadyStatus() 367 | { 368 | status = StatusEnum.ReadyDeactivated; 369 | lbStatus.Text = "Kinect ready. Say \"MOUSE START\""; 370 | this.btStart.BeginInvoke((MethodInvoker)(() => this.btStart.Enabled = true)); 371 | } 372 | 373 | private static void LogFaceDetection(FaceTrackFrame currentFaceFrame) 374 | { 375 | if (currentFaceFrame.TrackSuccessful) 376 | { 377 | File.AppendAllText("mouseLog.txt", DateTime.Now + " - Recognized face successfully.\n"); 378 | } 379 | else 380 | { 381 | File.AppendAllText("mouseLog.txt", DateTime.Now + " - Couldn't find face in frame.\n"); 382 | } 383 | } 384 | 385 | private void MoveMouseAccordingToFaceRotation(FaceTrackFrame currentFaceFrame) 386 | { 387 | if (headRotationHistory.Count > gaussFilter.Count - 1 && leftEyeClosedHistory.Count > nudConvolutionFilterLength.Value && currentFaceFrame.TrackSuccessful) 388 | { 389 | lastFramesReady = DateTime.Now; 390 | if (status == StatusEnum.Initializing) 391 | SetReadyStatus(); 392 | else 393 | { 394 | if (status == StatusEnum.UnreadyDeactivated) 395 | SwitchStatus(StatusEnum.ReadyActivated); 396 | else if (status == StatusEnum.ReadyActivated) 397 | { 398 | float browRaiserValue = currentFaceFrame.GetAnimationUnitCoefficients()[AnimationUnit.BrowRaiser]; 399 | float browLowererValue = currentFaceFrame.GetAnimationUnitCoefficients()[AnimationUnit.BrowLower]; 400 | float mouthOpenValue = currentFaceFrame.GetAnimationUnitCoefficients()[AnimationUnit.JawLower]; 401 | if (browRaiserHistory.Count >= 100) 402 | { 403 | browRaiserHistory.RemoveAt(0); 404 | browLowererHistory.RemoveAt(0); 405 | mouthOpenHistory.RemoveAt(0); 406 | } 407 | browLowererHistory.Add(browLowererValue); 408 | browRaiserHistory.Add(browRaiserValue); 409 | mouthOpenHistory.Add(mouthOpenValue); 410 | 411 | //Method 1: Without Smoothing 412 | //System.Drawing.Point smoothedXY = ScaleXY(currentFaceFrame.Rotation); 413 | 414 | //Method 2: Gaussian Smoothing 415 | System.Drawing.Point smoothedXY = CalculateGaussianSmoothedXYPosition(currentFaceFrame); 416 | 417 | //Check for right, left or Double Click 418 | //1. Check if there was already a click 20 Frames ago, or if Drag & Drop is active 419 | if (clickDelay > nudClickDelay.Value && !DragnDropActive) 420 | { 421 | //2. If not, calculate mean values of dy's last 16 Frames 422 | if (HandleMouseClickActions()) 423 | clickDelay = 0; 424 | else 425 | { 426 | //check for open Mouth 427 | if (mouthOpenValue > (float)nudMouthOpenStartThreshold.Value && mouthOpenHistory[mouthOpenHistory.Count - 2] > (float)nudMouthOpenConfirmation.Value && mouthOpenHistory[mouthOpenHistory.Count - 3] > (float)nudMouthOpenConfirmation.Value && mouthOpenHistory[mouthOpenHistory.Count - 4] > (float)nudMouthOpenConfirmation.Value) 428 | { 429 | MouseControl.Move(mousePositionHistory[mousePositionHistory.Count - 4].X, mousePositionHistory[mousePositionHistory.Count - 4].Y); 430 | this.lbAction.Invoke((MethodInvoker)(() => this.lbAction.Items.Add("Left Mouse Down on X: " + mousePositionHistory[mousePositionHistory.Count - 4].X + " Y: " + mousePositionHistory[mousePositionHistory.Count - 4].Y))); 431 | //lbAction.Items.Add("Left Mouse Down on X: " + mousePositionHistory[mousePositionHistory.Count - 4].X + " Y: " + mousePositionHistory[mousePositionHistory.Count - 4].Y); 432 | MouseControl.MouseDownLeft(); 433 | DragnDropActive = true; 434 | clickDelay = 0; 435 | } 436 | } 437 | } 438 | else if (DragnDropActive) 439 | { 440 | if (mouthOpenValue < (float)nudMouthOpenEndThreshold.Value) 441 | { 442 | this.lbAction.Invoke((MethodInvoker)(() => this.lbAction.Items.Add("Left Mouse Up on X: " + smoothedXY.X + " Y: " + smoothedXY.Y))); 443 | MouseControl.MouseUpLeft(); 444 | DragnDropActive = false; 445 | clickDelay = 0; 446 | } 447 | } 448 | MouseControl.Move(smoothedXY.X, smoothedXY.Y); 449 | HandleScrolling(browRaiserValue, browLowererValue); 450 | if (mousePositionHistory.Count > 100) 451 | mousePositionHistory.RemoveAt(0); 452 | mousePositionHistory.Add(new Microsoft.Kinect.Toolkit.FaceTracking.Point(smoothedXY.X, smoothedXY.Y)); 453 | File.AppendAllText("mouseLog.txt", DateTime.Now + " - Face and eyes successfully tracked.\n"); 454 | } 455 | } 456 | } 457 | } 458 | 459 | private System.Drawing.Point CalculateGaussianSmoothedXYPosition(FaceTrackFrame currentFaceFrame) 460 | { 461 | //Method 3: Gauß-Filter: Gewichte die letzten Bilder stärker. 462 | Vector3DF rotationMedium = new Vector3DF(); 463 | rotationMedium.X = currentFaceFrame.Rotation.X * gaussFilter[0]; 464 | rotationMedium.Y = currentFaceFrame.Rotation.Y * gaussFilter[0]; 465 | int i = 0; 466 | while (i < gaussFilter.Count - 1) 467 | { 468 | rotationMedium.X += (headRotationHistory[headRotationHistory.Count - 1 - i].X * gaussFilter[i]); 469 | rotationMedium.Y += (headRotationHistory[headRotationHistory.Count - 1 - i].Y * gaussFilter[i]); 470 | i++; 471 | } 472 | rotationMedium.X = (float)(rotationMedium.X / gaussFactor); 473 | rotationMedium.Y = (float)(rotationMedium.Y / gaussFactor); 474 | return ScaleXY(rotationMedium); 475 | } 476 | 477 | private void HandleScrolling(float browRaiserValue, float browLowererValue) 478 | { 479 | if (browLowererValue > (float)nudBrowLowererStartThreshold.Value) 480 | MouseControl.ScrollDown((int)(-browLowererValue * (int)nudScrollMultiplierDown.Value)); 481 | if (browRaiserValue > (float)nudBrowRaiserStartThreshold.Value) 482 | MouseControl.ScrollDown((int)(browRaiserValue * (int)nudScrollMultiplierUp.Value)); 483 | } 484 | 485 | private void WriteDataToMembers(ColorImageFrame colorImageFrame, DepthImageFrame depthImageFrame, SkeletonFrame skeletonFrame) 486 | { 487 | // Create any buffers to store copies of the data we work with 488 | if (this.depthImage == null) 489 | { 490 | this.depthImage = new short[depthImageFrame.PixelDataLength]; 491 | } 492 | 493 | if (this.colorImage == null) 494 | { 495 | this.colorImage = new byte[colorImageFrame.PixelDataLength]; 496 | } 497 | 498 | 499 | // Get the skeleton information 500 | if (this.SkeletonData == null || this.SkeletonData.Length != skeletonFrame.SkeletonArrayLength) 501 | { 502 | this.SkeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; 503 | } 504 | colorImageFrame.CopyPixelDataTo(this.colorImage); 505 | depthImageFrame.CopyPixelDataTo(this.depthImage); 506 | skeletonFrame.CopySkeletonDataTo(this.SkeletonData); 507 | } 508 | 509 | private void HandlePossibleImageFormatChanges(ColorImageFrame colorImageFrame, DepthImageFrame depthImageFrame) 510 | { 511 | if (this.depthImageFormat != depthImageFrame.Format) 512 | { 513 | this.depthImage = null; 514 | this.depthImageFormat = depthImageFrame.Format; 515 | } 516 | 517 | if (this.colorImageFormat != colorImageFrame.Format) 518 | { 519 | this.colorImage = null; 520 | this.colorImageFormat = colorImageFrame.Format; 521 | } 522 | } 523 | 524 | private Bitmap Convolution(Bitmap original, bool right, out Dictionary angleCount) 525 | { 526 | Bitmap result = new Bitmap(original.Width, original.Height); 527 | angleCount = new Dictionary(); 528 | angleCount.Add("-90--75", 0); 529 | angleCount.Add("-75--50", 0); 530 | angleCount.Add("-50--35", 0); 531 | angleCount.Add("-35--20", 0); 532 | angleCount.Add("-20-0", 0); 533 | angleCount.Add("0-20", 0); 534 | angleCount.Add("20-30", 0); 535 | angleCount.Add("30-45", 0); 536 | angleCount.Add("45-60", 0); 537 | angleCount.Add("60-75", 0); 538 | angleCount.Add("75-90", 0); 539 | angleCount.Add("else", 0); 540 | int[,] sobelMatrixX = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; 541 | int[,] sobelMatrixY = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } }; 542 | int divisor = 8; 543 | double dxGesamt = 0; 544 | double dyGesamt = 0; 545 | double direction = 0; 546 | for (int i = 1; i < original.Height - 1; i++) 547 | { 548 | for (int j = 1; j < original.Width - 1; j++) 549 | { 550 | double sumX = 0; 551 | double sumY = 0; 552 | for (int k = -1; k <= 1; k++) 553 | { 554 | for (int l = -1; l <= 1; l++) 555 | { 556 | double x = sobelMatrixX[k + 1, l + 1] * original.GetPixel(j + l, i + k).B; 557 | double y = sobelMatrixY[k + 1, l + 1] * original.GetPixel(j + l, i + k).B; 558 | sumX += x; 559 | sumY += y; 560 | } 561 | } 562 | sumX = sumX / divisor; 563 | sumY = sumY / divisor; 564 | 565 | direction = (Math.Atan(sumX / sumY)) * 180 / Math.PI; 566 | if (direction >= -90 && direction <= -75) 567 | angleCount["-90--75"]++; 568 | else if (direction > -75 && direction <= -50) 569 | angleCount["-75--50"]++; 570 | else if (direction > -50 && direction <= -35) 571 | angleCount["-50--35"]++; 572 | else if (direction > -35 && direction <= -20) 573 | angleCount["-35--20"]++; 574 | else if (direction > -20 && direction <= 0) 575 | angleCount["-20-0"]++; 576 | else if (direction > 0 && direction <= 20) 577 | angleCount["0-20"]++; 578 | else if (direction > 20 && direction <= 30) 579 | angleCount["20-30"]++; 580 | else if (direction > 30 && direction <= 45) 581 | angleCount["30-45"]++; 582 | else if (direction > 45 && direction <= 60) 583 | angleCount["45-60"]++; 584 | else if (direction > 60 && direction <= 75) 585 | angleCount["60-75"]++; 586 | else if (direction > 75 && direction <= 90) 587 | angleCount["75-90"]++; 588 | else 589 | angleCount["else"]++; 590 | 591 | 592 | int gesamt = (int)Math.Sqrt(Math.Pow(sumX, 2) + Math.Pow(sumY, 2)); 593 | result.SetPixel(j, i, Color.FromArgb(gesamt, gesamt, gesamt)); 594 | 595 | dxGesamt += sumX; 596 | dyGesamt += sumY; 597 | } 598 | } 599 | dxGesamt = dxGesamt / (original.Width * original.Height); 600 | dyGesamt = dyGesamt / (original.Width * original.Height); 601 | return result; 602 | } 603 | 604 | private bool IsEyeClosed(Dictionary angleDistribution) 605 | { 606 | //Eye is closed, if 68% of all Conturpixels have a direction between -20° and +20° 607 | int valueSum = 0; 608 | int inAreaSum = 0; 609 | foreach (KeyValuePair kvp in angleDistribution) 610 | { 611 | valueSum += kvp.Value; 612 | if (kvp.Key == "-20-0" || kvp.Key == "0-20") 613 | { 614 | inAreaSum += kvp.Value; 615 | } 616 | } 617 | if (valueSum == 0) 618 | return false; 619 | double result = (100 * inAreaSum) / valueSum; 620 | if (result >= (int)nudPercentageHorizontalEdgePixels.Value) 621 | return true; 622 | else return false; 623 | 624 | } 625 | 626 | private Bitmap ConvertGrey(Bitmap source) 627 | { 628 | Bitmap bm = new Bitmap(source.Width, source.Height); 629 | for (int y = 0; y < bm.Height; y++) 630 | { 631 | for (int x = 0; x < bm.Width; x++) 632 | { 633 | Color c = source.GetPixel(x, y); 634 | int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11); 635 | bm.SetPixel(x, y, Color.FromArgb(luma, luma, luma)); 636 | } 637 | } 638 | return bm; 639 | } 640 | 641 | private Bitmap EyeExtract(ColorImageFrame colorImageFrame, FaceTrackFrame currentFaceFrame, int minX, int minY, int maxX, int maxY, bool right) 642 | { 643 | if (maxX < minX) 644 | { 645 | int temp = maxX; 646 | maxX = minX; 647 | minX = temp; 648 | } 649 | if (maxY < minY) 650 | { 651 | int temp = maxY; 652 | maxY = minY; 653 | minY = temp; 654 | } 655 | if (maxY > 480 || maxX > 640) 656 | return null; 657 | 658 | //Try to extract picture from area made by the marked points 659 | if (maxX > minX && maxY > minY && minY > 0 && minX > 0) 660 | { 661 | int minPosOneDim = ConvertXYToOneDimensionalCoordinate((int)minX, (int)minY, colorImageFrame.Width); 662 | int maxPosOneDim = ConvertXYToOneDimensionalCoordinate((int)maxX, (int)maxY, colorImageFrame.Width); 663 | 664 | int xLength = maxX - minX + 1; 665 | int yLength = maxY - minY + 1; 666 | //ARGB 667 | object[, ,] eyePic = new object[xLength, yLength, 4]; 668 | for (int xi = minX; xi <= maxX; xi++) 669 | { 670 | for (int yi = minY; yi <= maxY; yi++) 671 | { 672 | int oneDimensional = ConvertXYToOneDimensionalCoordinate(xi, yi, colorImageFrame.Width); 673 | eyePic[xi - minX, yi - minY, 0] = colorImage.GetValue(oneDimensional); 674 | eyePic[xi - minX, yi - minY, 1] = colorImage.GetValue(oneDimensional + 1); 675 | eyePic[xi - minX, yi - minY, 2] = colorImage.GetValue(oneDimensional + 2); 676 | eyePic[xi - minX, yi - minY, 3] = colorImage.GetValue(oneDimensional + 3); 677 | } 678 | } 679 | //Write eyePic to PictureBox 680 | Bitmap eyeBitmap = new Bitmap(xLength, yLength); 681 | for (int i = 0; i < xLength; i++) 682 | { 683 | for (int j = 0; j < yLength; j++) 684 | { 685 | eyeBitmap.SetPixel(i, j, Color.FromArgb(255, Int32.Parse(eyePic[i, j, 0].ToString()), Int32.Parse(eyePic[i, j, 1].ToString()), Int32.Parse(eyePic[i, j, 2].ToString()))); 686 | } 687 | } 688 | return eyeBitmap; 689 | } 690 | return null; 691 | } 692 | 693 | private int ConvertXYToOneDimensionalCoordinate(int x, int y, int width) 694 | { 695 | return ((y - 1) * width * 4 + x * 4); 696 | } 697 | 698 | private void FaceMouseConfig_Load(object sender, EventArgs e) 699 | { 700 | InitializeKinect(); 701 | } 702 | 703 | public System.Drawing.Point ScaleXY(Vector3DF rotation) 704 | { 705 | 706 | double screenWidth = Screen.PrimaryScreen.Bounds.Width; 707 | double screenHeight = Screen.PrimaryScreen.Bounds.Height; 708 | double y = ((screenHeight / (int)nudHeadToScreenRelationYHeight.Value) * -rotation.X) + 709 | (screenHeight / 2); 710 | double x = ((screenWidth / (int)nudHeadToScreenRelationXWidth.Value) * -rotation.Y) + 711 | (screenWidth / 2); 712 | 713 | if (x < 0) 714 | x = 0; 715 | else if (x > screenWidth - 1) 716 | x = screenWidth - 1; 717 | if (y < 0) 718 | y = 0; 719 | else if (y > screenHeight - 1) 720 | y = screenHeight; 721 | return new System.Drawing.Point((int)x, (int)y); 722 | } 723 | 724 | /// 725 | /// Handle mouse click actions according to eye state 726 | /// 727 | /// 728 | private bool HandleMouseClickActions() 729 | { 730 | float meanRightClosed = 0; 731 | float meanLeftClosed = 0; 732 | 733 | for (int i = leftEyeClosedHistory.Count - 1; i >= leftEyeClosedHistory.Count - 1 - nudConvolutionFilterLength.Value; i--) 734 | { 735 | if (leftEyeClosedHistory[i]) 736 | meanLeftClosed++; 737 | if (rightEyeClosedHistory[i]) 738 | meanRightClosed++; 739 | } 740 | int divisor = (leftEyeClosedHistory.Count) - (leftEyeClosedHistory.Count - 1 - (int)nudConvolutionFilterLength.Value); 741 | meanRightClosed = meanRightClosed / divisor; 742 | meanLeftClosed = meanLeftClosed / divisor; 743 | if (mousePositionHistory.Count - 1 - nudConvolutionFilterLength.Value <= 0) 744 | return false; 745 | if ((meanLeftClosed > (float)nudEyeClosedFilterThreshold.Value && meanRightClosed > (float)nudDoubleClickSecondEyeThreshold.Value) || (meanLeftClosed > (float)nudDoubleClickSecondEyeThreshold.Value && meanRightClosed > (float)nudEyeClosedFilterThreshold.Value)) 746 | { 747 | MouseControl.Move(mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].X, mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].Y); 748 | MouseControl.Click(); 749 | MouseControl.Click(); 750 | this.lbAction.Invoke((MethodInvoker)(() => this.lbAction.Items.Add("Double Click on X: "+mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].X+" Y: "+mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].Y))); 751 | return true; 752 | } 753 | else if (meanLeftClosed > (float)nudEyeClosedFilterThreshold.Value) 754 | { 755 | MouseControl.Move(mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].X, mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].Y); 756 | MouseControl.Click(); 757 | this.lbAction.Invoke((MethodInvoker)(() => this.lbAction.Items.Add("Left Click on X: " + mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].X + " Y: " + mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].Y))); 758 | return true; 759 | } 760 | else if (meanRightClosed > (float)nudEyeClosedFilterThreshold.Value) 761 | { 762 | MouseControl.Move(mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].X, mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].Y); 763 | MouseControl.RightClick(); 764 | this.lbAction.Invoke((MethodInvoker)(() => this.lbAction.Items.Add("Right Click on X: " + mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].X + " Y: " + mousePositionHistory[mousePositionHistory.Count - 1 - (int)nudConvolutionFilterLength.Value].Y))); 765 | return true; 766 | } 767 | return false; 768 | 769 | } 770 | 771 | private void btStop_Click(object sender, EventArgs e) 772 | { 773 | StopKinectControl(); 774 | } 775 | 776 | private void StopKinectControl() 777 | { 778 | this.btStop.BeginInvoke((MethodInvoker)(() => this.btStop.Enabled = false)); 779 | if (this.status == StatusEnum.ReadyActivated) 780 | SwitchStatus(StatusEnum.ReadyDeactivated); 781 | else if (this.status == StatusEnum.UnreadyDeactivated) 782 | SwitchStatus(StatusEnum.Initializing); 783 | } 784 | 785 | private void btReset_Click(object sender, EventArgs e) 786 | { 787 | nudClickDelay.Value = 20; 788 | tbSmoothingFilter.Text = "64, 55, 45, 35, 25, 20, 15, 10, 8, 7, 6, 5, 4, 3, 2, 1"; 789 | nudPercentageHorizontalEdgePixels.Value = 68; 790 | nudConvolutionFilterLength.Value = 10; 791 | nudEyeClosedFilterThreshold.Value = 0.5m; 792 | nudDoubleClickSecondEyeThreshold.Value = 0.18m; 793 | nudBrowRaiserStartThreshold.Value = 0.5m; 794 | nudBrowLowererStartThreshold.Value = 0.16m; 795 | nudMouthOpenStartThreshold.Value = 0.75m; 796 | nudMouthOpenConfirmation.Value = 0.5m; 797 | nudMouthOpenEndThreshold.Value = 0.25m; 798 | nudScrollMultiplierUp.Value = 150; 799 | nudScrollMultiplierDown.Value = 250; 800 | nudHeadToScreenRelationXWidth.Value = 35; 801 | nudHeadToScreenRelationYHeight.Value = 25; 802 | } 803 | 804 | private void FaceMouseConfig_FormClosing(object sender, FormClosingEventArgs e) 805 | { 806 | if (Kinect != null) 807 | { 808 | Kinect.AllFramesReady -= this.OnAllFramesReady; 809 | Kinect.DepthStream.Disable(); 810 | Kinect.ColorStream.Disable(); 811 | Kinect.SkeletonStream.Disable(); 812 | btStop.Enabled = false; 813 | btStart.Enabled = true; 814 | Kinect.Stop(); 815 | if (useSpeach) 816 | { 817 | Kinect.AudioSource.Stop(); 818 | } 819 | Kinect = null; 820 | } 821 | 822 | 823 | 824 | if (useSpeach && null != this.speechRecognitionEngine) 825 | { 826 | this.speechRecognitionEngine.SpeechRecognized -= SpeechRecognized; 827 | this.speechRecognitionEngine.SpeechRecognitionRejected -= SpeechRejected; 828 | this.speechRecognitionEngine.RecognizeAsyncStop(); 829 | } 830 | try 831 | { 832 | //Save Values to Settings Object 833 | Settings settingObject = new Settings(); 834 | settingObject.BrowLowererStartthreshold = nudBrowLowererStartThreshold.Value; 835 | settingObject.BrowRaiserStartThreshold = nudBrowRaiserStartThreshold.Value; 836 | settingObject.ClickDelay = nudClickDelay.Value; 837 | settingObject.DoubleClickSecondEyeThreshold = nudDoubleClickSecondEyeThreshold.Value; 838 | settingObject.EyeClosedFilterThreshold = nudEyeClosedFilterThreshold.Value; 839 | settingObject.HeadrotationSmoothingFilterValues = tbSmoothingFilter.Text; 840 | settingObject.HeadToScreenRelationX = nudHeadToScreenRelationXWidth.Value; 841 | settingObject.HeadToScreenRelationY = nudHeadToScreenRelationYHeight.Value; 842 | settingObject.MouthOpenConfirmation = nudMouthOpenConfirmation.Value; 843 | settingObject.MouthOpenEndThreshold = nudMouthOpenEndThreshold.Value; 844 | settingObject.MouthOpenStartThreshold = nudMouthOpenStartThreshold.Value; 845 | settingObject.PercentageHorizontalEdgePixels = nudPercentageHorizontalEdgePixels.Value; 846 | settingObject.ScrollMultiplierDown = nudScrollMultiplierDown.Value; 847 | settingObject.ScrollMultiplierUp = nudScrollMultiplierUp.Value; settingObject.UsedFramesForClosedEyeDetection = nudConvolutionFilterLength.Value; 848 | 849 | 850 | //Try to serialize Object 851 | XmlRootAttribute xRoot = new XmlRootAttribute(); 852 | xRoot.ElementName = "Settings"; 853 | xRoot.IsNullable = true; 854 | XmlSerializer serializer = new XmlSerializer(typeof(Settings)); 855 | TextWriter textWriter = new StreamWriter(@"settings.xml"); 856 | serializer.Serialize(textWriter, settingObject); 857 | textWriter.Close(); 858 | } 859 | catch (Exception) 860 | { 861 | //Do nothing if parameters couldn't be serialized (e.g. due to no File write permission). 862 | } 863 | } 864 | 865 | private void ttClickDelay_Popup(object sender, PopupEventArgs e) 866 | { 867 | 868 | } 869 | 870 | private void tiCheckStatus_Tick(object sender, EventArgs e) 871 | { 872 | if (DateTime.Now - lastFramesReady > TimeSpan.FromSeconds(5)) 873 | { 874 | if (status == StatusEnum.ReadyActivated) 875 | this.SwitchStatus(StatusEnum.UnreadyDeactivated); 876 | else if (status == StatusEnum.ReadyDeactivated) 877 | this.SwitchStatus(StatusEnum.Initializing); 878 | } 879 | } 880 | } 881 | } 882 | -------------------------------------------------------------------------------- /ExpressionMouse/MouseControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Runtime.InteropServices; 5 | using System.Windows.Forms; 6 | 7 | namespace ExpressionMouse 8 | { 9 | 10 | public struct Position 11 | { 12 | public int X; 13 | public int Y; 14 | } 15 | 16 | public class MouseControl 17 | { 18 | [DllImport("user32.dll", EntryPoint = "SendInput", SetLastError = true)] 19 | static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize); 20 | 21 | [DllImport("user32.dll", EntryPoint = "GetMessageExtraInfo", SetLastError = true)] 22 | static extern IntPtr GetMessageExtraInfo(); 23 | 24 | private enum InputType 25 | { 26 | INPUT_MOUSE = 0, 27 | INPUT_KEYBOARD = 1, 28 | INPUT_HARDWARE = 2, 29 | } 30 | 31 | [Flags()] 32 | private enum MOUSEEVENTF 33 | { 34 | MOVE = 0x0001, // mouse move 35 | LEFTDOWN = 0x0002, // left button down 36 | LEFTUP = 0x0004, // left button up 37 | RIGHTDOWN = 0x0008, // right button down 38 | RIGHTUP = 0x0010, // right button up 39 | MIDDLEDOWN = 0x0020, // middle button down 40 | MIDDLEUP = 0x0040, // middle button up 41 | XDOWN = 0x0080, // x button down 42 | XUP = 0x0100, // x button down 43 | WHEEL = 0x0800, // wheel button rolled 44 | VIRTUALDESK = 0x4000, // map to entire virtual desktop 45 | ABSOLUTE = 0x8000, // absolute move 46 | } 47 | 48 | [StructLayout(LayoutKind.Sequential)] 49 | private struct MOUSEINPUT 50 | { 51 | public int dx; 52 | public int dy; 53 | public int mouseData; 54 | public MOUSEEVENTF dwFlags; 55 | public int time; 56 | public IntPtr dwExtraInfo; 57 | } 58 | 59 | [StructLayout(LayoutKind.Sequential)] 60 | private struct INPUT 61 | { 62 | public InputType type; 63 | public MOUSEINPUT mi; 64 | } 65 | /// 66 | /// Diese Funktion bewegt den Mauscursor an einen bestimmten Punkt. 67 | /// 68 | /// X Koordinate der Position als absoluter Pixelwert 69 | /// Y Koordinate der Position als absoluter Pixelwert 70 | /// Liefert 1 bei Erfolg und 0, wenn der Eingabestream schon blockiert war zurück. 71 | public static uint Move(int x, int y) 72 | { 73 | // Bildschirm Auflösung 74 | float ScreenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; 75 | float ScreenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; 76 | 77 | INPUT input_move = new INPUT(); 78 | input_move.type = InputType.INPUT_MOUSE; 79 | 80 | input_move.mi.dx = (int)Math.Round(x * (65535 / ScreenWidth), 0); 81 | input_move.mi.dy = (int)Math.Round(y * (65535 / ScreenHeight), 0); 82 | input_move.mi.mouseData = 0; 83 | input_move.mi.dwFlags = (MOUSEEVENTF.MOVE | MOUSEEVENTF.ABSOLUTE); 84 | input_move.mi.time = 0; 85 | input_move.mi.dwExtraInfo = GetMessageExtraInfo(); 86 | 87 | INPUT[] input = { input_move }; 88 | return SendInput(1, input, Marshal.SizeOf(input_move)); 89 | } 90 | 91 | public static void SmoothMove(int x, int y) 92 | { 93 | // Bildschirm Auflösung 94 | float ScreenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; 95 | float ScreenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; 96 | 97 | Position target = new Position(); 98 | target.X = x; 99 | target.Y = y; 100 | Position currentPos = CurrentMousePos(); 101 | 102 | Position stepSize = new Position(); 103 | Position stepCount = new Position(); 104 | stepCount.Y = Math.Abs(target.Y - currentPos.Y); 105 | stepCount.X = Math.Abs(target.X - currentPos.X); 106 | if (stepCount.X > stepCount.Y) 107 | { 108 | stepSize.Y = 1; 109 | if (stepCount.Y == 0) 110 | stepSize.X = 1; 111 | else 112 | stepSize.X = (stepCount.X / stepCount.Y); 113 | } 114 | else if (stepCount.Y > stepCount.X) 115 | { 116 | stepSize.X = 1; 117 | if (stepCount.X == 0) 118 | stepSize.X = 1; 119 | else 120 | stepSize.Y = (stepCount.Y / stepCount.X); 121 | } 122 | else if (stepCount.X == stepCount.Y) 123 | { 124 | stepSize.X = 1; 125 | stepSize.Y = 1; 126 | } 127 | 128 | while (currentPos.X != target.X && currentPos.Y != target.Y) 129 | { 130 | currentPos.X += stepSize.X; 131 | currentPos.Y += stepSize.Y; 132 | 133 | INPUT input_move = new INPUT(); 134 | input_move.type = InputType.INPUT_MOUSE; 135 | input_move.mi.dx = (int)Math.Round(currentPos.X * (65535 / ScreenWidth), 0); 136 | input_move.mi.dy = (int)Math.Round(currentPos.Y * (65535 / ScreenHeight), 0); 137 | input_move.mi.mouseData = 0; 138 | input_move.mi.dwFlags = (MOUSEEVENTF.MOVE | MOUSEEVENTF.ABSOLUTE); 139 | input_move.mi.time = 0; 140 | input_move.mi.dwExtraInfo = GetMessageExtraInfo(); 141 | INPUT[] input = { input_move }; 142 | SendInput(1, input, Marshal.SizeOf(input_move)); 143 | } 144 | } 145 | 146 | /// 147 | /// Diese Funktion simuliert einen einfach Mausklick mit der linken Maustaste an der aktuellen Cursurposition. 148 | /// 149 | /// Liefert 2 zurück, wenn beide Aktionen (Maus down und Maus up) erfolgreich waren. Andernfalls 1 oder 0. 150 | public static uint Click() 151 | { 152 | INPUT input_down = new INPUT(); 153 | input_down.type = InputType.INPUT_MOUSE; 154 | 155 | input_down.mi.dx = 0; 156 | input_down.mi.dy = 0; 157 | input_down.mi.mouseData = 0; 158 | input_down.mi.dwFlags = MOUSEEVENTF.LEFTDOWN; 159 | input_down.mi.time = 0; 160 | input_down.mi.dwExtraInfo = GetMessageExtraInfo(); 161 | 162 | INPUT input_up = input_down; 163 | input_up.mi.dwFlags = MOUSEEVENTF.LEFTUP; 164 | 165 | INPUT[] input = { input_down, input_up }; 166 | return SendInput(2, input, Marshal.SizeOf(input_down)); 167 | } 168 | 169 | /// 170 | /// Diese Funktion simuliert einen einfach Mausklick mit der linken Maustaste an der aktuellen Cursurposition. 171 | /// 172 | /// Liefert 2 zurück, wenn beide Aktionen (Maus down und Maus up) erfolgreich waren. Andernfalls 1 oder 0. 173 | public static uint RightClick() 174 | { 175 | INPUT input_down = new INPUT(); 176 | input_down.type = InputType.INPUT_MOUSE; 177 | 178 | input_down.mi.dx = 0; 179 | input_down.mi.dy = 0; 180 | input_down.mi.mouseData = 0; 181 | input_down.mi.dwFlags = MOUSEEVENTF.RIGHTDOWN; 182 | input_down.mi.time = 0; 183 | input_down.mi.dwExtraInfo = GetMessageExtraInfo(); 184 | 185 | INPUT input_up = input_down; 186 | input_up.mi.dwFlags = MOUSEEVENTF.RIGHTUP; 187 | 188 | INPUT[] input = { input_down, input_up }; 189 | return SendInput(2, input, Marshal.SizeOf(input_down)); 190 | } 191 | 192 | public static uint MouseDownLeft() 193 | { 194 | 195 | INPUT input_down = new INPUT(); 196 | input_down.type = InputType.INPUT_MOUSE; 197 | 198 | input_down.mi.dx = 0; 199 | input_down.mi.dy = 0; 200 | input_down.mi.mouseData = 0; 201 | input_down.mi.dwFlags = MOUSEEVENTF.LEFTDOWN; 202 | input_down.mi.time = 0; 203 | input_down.mi.dwExtraInfo = GetMessageExtraInfo(); 204 | 205 | INPUT[] input = { input_down }; 206 | return SendInput(1, input, Marshal.SizeOf(input_down)); 207 | } 208 | 209 | public static uint ScrollDown(int amount) 210 | { 211 | 212 | INPUT input_down = new INPUT(); 213 | input_down.type = InputType.INPUT_MOUSE; 214 | 215 | input_down.mi.dx = 0; 216 | input_down.mi.dy = 0; 217 | input_down.mi.mouseData = amount; 218 | input_down.mi.dwFlags = MOUSEEVENTF.WHEEL; 219 | input_down.mi.time = 0; 220 | input_down.mi.dwExtraInfo = GetMessageExtraInfo(); 221 | 222 | INPUT[] input = { input_down }; 223 | return SendInput(1, input, Marshal.SizeOf(input_down)); 224 | } 225 | 226 | public static uint MouseUpLeft() 227 | { 228 | 229 | INPUT input_down = new INPUT(); 230 | input_down.type = InputType.INPUT_MOUSE; 231 | 232 | input_down.mi.dx = 0; 233 | input_down.mi.dy = 0; 234 | input_down.mi.mouseData = 0; 235 | input_down.mi.dwFlags = MOUSEEVENTF.LEFTUP; 236 | input_down.mi.time = 0; 237 | input_down.mi.dwExtraInfo = GetMessageExtraInfo(); 238 | INPUT[] input = { input_down }; 239 | return SendInput(1, input, Marshal.SizeOf(input_down)); 240 | } 241 | 242 | 243 | public static Position CurrentMousePos() 244 | { 245 | int x = System.Windows.Forms.Cursor.Position.X; 246 | int y = System.Windows.Forms.Cursor.Position.Y; 247 | Position result = new Position(); 248 | result.X = x; 249 | result.Y = y; 250 | return result; 251 | } 252 | 253 | public static void DeltaMove(int dx, int dy) 254 | { 255 | Move(CurrentMousePos().X + dx, CurrentMousePos().Y + dy); 256 | } 257 | 258 | public static void SmoothDeltaMove(int dx, int dy) 259 | { 260 | SmoothMove(CurrentMousePos().X + dx, CurrentMousePos().Y + dy); 261 | } 262 | 263 | } 264 | } 265 | -------------------------------------------------------------------------------- /ExpressionMouse/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace ExpressionMouse 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// Der Haupteinstiegspunkt für die Anwendung. 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new ExpressionMouse()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ExpressionMouse/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über die folgenden 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die mit einer Assembly verknüpft sind. 8 | [assembly: AssemblyTitle("FaceMouseConfig")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FaceMouseConfig")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("d0e53480-6914-4939-a59d-c2a787c540a8")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 33 | // übernehmen, indem Sie "*" eingeben: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ExpressionMouse/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Dieser Code wurde von einem Tool generiert. 4 | // Laufzeitversion:4.0.30319.296 5 | // 6 | // Änderungen an dieser Datei können fehlerhaftes Verhalten verursachen und gehen verloren, wenn 7 | // der Code neu generiert wird. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace FaceMouseConfig.Properties 12 | { 13 | 14 | 15 | /// 16 | /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. 17 | /// 18 | // Diese Klasse wurde von der StronglyTypedResourceBuilder-Klasse 19 | // über ein Tool wie ResGen oder Visual Studio automatisch generiert. 20 | // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen 21 | // mit der Option /str erneut aus, oder erstellen Sie Ihr VS-Projekt neu. 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 | /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. 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("FaceMouseConfig.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle 56 | /// Ressourcenlookups, die diese stark typisierte Ressourcenklasse verwenden. 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 | -------------------------------------------------------------------------------- /ExpressionMouse/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 | -------------------------------------------------------------------------------- /ExpressionMouse/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.296 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 FaceMouseConfig.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.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 | -------------------------------------------------------------------------------- /ExpressionMouse/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ExpressionMouse/Settings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | using System.IO; 7 | 8 | namespace ExpressionMouse 9 | { 10 | [XmlRoot("Settings"), XmlType("Settings")] 11 | public class Settings 12 | { 13 | public decimal ClickDelay{get; set;} 14 | public string HeadrotationSmoothingFilterValues { get; set; } 15 | public decimal PercentageHorizontalEdgePixels { get; set; } 16 | public decimal UsedFramesForClosedEyeDetection { get; set; } 17 | public decimal EyeClosedFilterThreshold { get; set; } 18 | public decimal DoubleClickSecondEyeThreshold { get; set; } 19 | public decimal BrowRaiserStartThreshold { get; set; } 20 | public decimal BrowLowererStartthreshold { get; set; } 21 | public decimal MouthOpenStartThreshold { get; set; } 22 | public decimal MouthOpenConfirmation { get; set;} 23 | public decimal MouthOpenEndThreshold { get; set; } 24 | public decimal ScrollMultiplierUp { get; set; } 25 | public decimal ScrollMultiplierDown { get; set; } 26 | public decimal HeadToScreenRelationX { get; set; } 27 | public decimal HeadToScreenRelationY { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ExpressionMouse/bin/Debug/FaceTrackData.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/ExpressionMouse/bin/Debug/FaceTrackData.dll -------------------------------------------------------------------------------- /ExpressionMouse/bin/Debug/FaceTrackLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/ExpressionMouse/bin/Debug/FaceTrackLib.dll -------------------------------------------------------------------------------- /ExpressionMouse/bin/Debug/Microsoft.Kinect.Toolkit.FaceTracking.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/ExpressionMouse/bin/Debug/Microsoft.Kinect.Toolkit.FaceTracking.dll -------------------------------------------------------------------------------- /ExpressionMouse/bin/Debug/Microsoft.Kinect.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/ExpressionMouse/bin/Debug/Microsoft.Kinect.dll -------------------------------------------------------------------------------- /ExpressionMouse/bin/Debug/init.txt: -------------------------------------------------------------------------------- 1 | 23.05.2014 14:43:59 - Error during Kinect initialization. 2 | 23.05.2014 14:45:07 - Kinect sensor initialized successfully. 3 | 17.01.2017 22:44:39 - Error during Kinect initialization. 4 | 09.09.2017 11:58:55 - Kinect sensor initialized successfully. 5 | 09.09.2017 12:09:16 - Kinect sensor initialized successfully. 6 | 09.09.2017 12:26:22 - Kinect sensor initialized successfully. 7 | 09.09.2017 12:33:22 - Kinect sensor initialized successfully. 8 | 09.09.2017 12:53:53 - Kinect sensor initialized successfully. 9 | 09.09.2017 12:58:46 - Kinect sensor initialized successfully. 10 | 09.09.2017 12:59:38 - Kinect sensor initialized successfully. 11 | 11.09.2017 22:29:50 - Kinect sensor initialized successfully. 12 | 11.09.2017 22:31:22 - Kinect sensor initialized successfully. 13 | 11.09.2017 22:33:18 - Kinect sensor initialized successfully. 14 | 14.09.2017 21:52:41 - Kinect sensor initialized successfully. 15 | 14.09.2017 22:06:48 - Kinect sensor initialized successfully. 16 | 15.09.2017 14:24:15 - Kinect sensor initialized successfully. 17 | 15.09.2017 14:37:40 - Kinect sensor initialized successfully. 18 | 15.09.2017 14:49:46 - Kinect sensor initialized successfully. 19 | 15.09.2017 17:58:38 - Error during Kinect initialization. 20 | -------------------------------------------------------------------------------- /ExpressionMouse/bin/Debug/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 4 | 64, 55, 45, 35, 25, 20, 15, 10, 8, 7, 6, 5, 4, 3, 2, 1 5 | 68 6 | 10 7 | 0.5 8 | 0.18 9 | 0.5 10 | 0.16 11 | 0.75 12 | 0.5 13 | 0.25 14 | 150 15 | 250 16 | 35 17 | 25 18 | -------------------------------------------------------------------------------- /ExpressionMouse/lib/FaceTrackData.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/ExpressionMouse/lib/FaceTrackData.dll -------------------------------------------------------------------------------- /ExpressionMouse/lib/FaceTrackLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/ExpressionMouse/lib/FaceTrackLib.dll -------------------------------------------------------------------------------- /ExpressionMouse/lib/Microsoft.Kinect.Toolkit.FaceTracking.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/ExpressionMouse/lib/Microsoft.Kinect.Toolkit.FaceTracking.dll -------------------------------------------------------------------------------- /ExpressionMouse/lib/Microsoft.Kinect.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/ExpressionMouse/lib/Microsoft.Kinect.dll -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExpressionMouse-Kinect 2 | This project utilizes your face as Mouse control via the Kinect for Windows sensor (v1.0). It is written in C# using the Kinect for Windows SDK. Replace your mouse with your face. Control the cursor just by moving your head. Click by winking your eyes, scroll by raising and lowering your eyebrows. 3 | 4 | ## Installation ## 5 | 6 | For usage and development you have to install the Kinect for Windows SDK v1.8 and the Kinect Developer Toolkit v1.8. 7 | Download Kinect SDK: https://www.microsoft.com/en-us/download/details.aspx?id=40278 8 | Download Kinect Toolkit: https://www.microsoft.com/en-us/download/details.aspx?id=40276 9 | 10 | For detailled usage instructions please see my blog: 11 | http://futuretechblog.com?p=71 12 | 13 | Here is a short demo youtube video: 14 | https://www.youtube.com/watch?v=6NFsea7CoxQ 15 | 16 | Unfortunately I have currently no time to maintain this project. So if anybody who is interested to enhance the software (maybe maintain it for newer Kinect versions) is welcome. 17 | 18 | ## Usage ## 19 | 20 | If you want to use ExpressionMouse without Dev environment, just use the exe file within the "executable" folder. 21 | 22 | 23 | Cursor Moving 24 | 25 | It is really easy: Just move your head to control the cursor. Make sure that Kinect can see your face as well as your chest. Sometimes the inital recognition is better when you are waving. It is normal that Kinect needs a few seconds to identify your face correctly. In contrast to KinectMouse, ExpressionMouse Kinect is more precise when you are more close to the sensor (but not too close) as the sensor has a more detailed view on your face this way. One meter should be a sufficient distance. 26 | 27 | Left Click 28 | 29 | Just wink with your right eye about a second. At this point you may ask why you have to use your right eye for a left click and not your left eye. During testing we figured out that the sensor detected our right eyes much more accurate than our left eyes. So we decided to swap left and right. As left clicks are much more frequent than right clicks, we think it is a good idea to use the most sensitive wink for the left click. 30 | 31 | Right Click 32 | 33 | Just wink with your left eye about a second. 34 | 35 | Double Click 36 | 37 | Wink with both of your eyes at the same time. Then a double click will be executed. 38 | 39 | Scrolling 40 | 41 | Raise your eyebrows for scrolling up and lower it for scrolling down. 42 | 43 | Drag & Drop 44 | 45 | Open your mouth for starting drag & drop. Move your head to move the cursor and keep your mouth open. For dropping, just close your mouth. 46 | 47 | Find the correct settings for yourself 48 | 49 | Every face is different. It could be that the preselected settings in ExpressionMouse Kinect are not optimal for you. Just play a bit with the thresholds until you are satisfied. 50 | 51 | ClickDelay: Timespan in frames (Normally Kinect works with 30 fps) which have to elapse between two mouse actions. 52 | Headrotation Smoothing Filter Values: Frameweights for calculating weighted average of your head rotation. Used for smoothing the cursor motion. If you enter the following the cursor will become more precise, but it will also a bit more delayed: “2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1” 53 | 54 | Percentage of horizontal edge Pixels: Used for differentiating between open and closed eye. A higher value means that the closed eye detection is less sensitive. A lower value makes it more sensitive. 55 | 56 | Used frames for closed eye detection: More frames increases accuracy in closed eye detection, but it also increases the timespan between closing the eye and the execution of the mouseclick. 57 | 58 | Eye closed filter threshold: Used for differentiating between open and closed eye. A higher value means that the closed eye detection is less sensitive. A lower value makes it more sensitive. 59 | 60 | Double click second eye threshold: Threshold for differentiating between a normal click and a double click. If doubleclicks are not recognized correctly, you should decrease this value. If normal clicks are recognized as doubleclicks, you should increase this value. 61 | Brow raiser start threshold: Threshold for raising your brow. Decrease value, if raising your brow is not recognized. If your computer is scrolling up, even if you are not raising your brow, increase this value. 62 | 63 | Brow lowerer start threshold: Same as Brow raiser start threshold, but for lowering your brow and scrolling down. 64 | 65 | Mouth open start threshold: Threshold for opening your mouth (executing MouseDown Event). Increase if opening your mouth is not recognized correctly. Decrease if MouseDown is executed, even if your mouth is closed. 66 | 67 | Mouth open confirmation: Decrease this value, if MouseUp is executed, even if your mouth is still open. 68 | 69 | Mouth open end threshold: Threshold for closing your mouth (executing MouseUp Event). Increase if closing your mouth is not recognized correctly. Decrease if MouseUp is executed, even if your mouth is still open. 70 | 71 | Scroll multiplier up: A higher value means that scrolling up is faster. 72 | 73 | Scroll multiplier down: A higher value means that scrolling down is faster. 74 | 75 | Head to Screen relation X – Width: Sensitivity of the mouse cursor in horizontal direction. A higher value means less sensitivity. 76 | 77 | Head to Screen relation Y – Height: Sensitivity of the mouse cursor in vertical direction. A higher value means less sensitivity. 78 | -------------------------------------------------------------------------------- /TestApp/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace TestApp 2 | { 3 | partial class DebugForm 4 | { 5 | /// 6 | /// Erforderliche Designervariable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Verwendete Ressourcen bereinigen. 12 | /// 13 | /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Vom Windows Form-Designer generierter Code 24 | 25 | /// 26 | /// Erforderliche Methode für die Designerunterstützung. 27 | /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.btStart = new System.Windows.Forms.Button(); 32 | this.pbLeftEye = new System.Windows.Forms.PictureBox(); 33 | this.pbRightEye = new System.Windows.Forms.PictureBox(); 34 | this.cbLeftEyeClosed = new System.Windows.Forms.CheckBox(); 35 | this.cbRightEyeClosed = new System.Windows.Forms.CheckBox(); 36 | this.label1 = new System.Windows.Forms.Label(); 37 | this.label2 = new System.Windows.Forms.Label(); 38 | this.tbBrowLowerer = new System.Windows.Forms.TextBox(); 39 | this.tbBrowRaiser = new System.Windows.Forms.TextBox(); 40 | ((System.ComponentModel.ISupportInitialize)(this.pbLeftEye)).BeginInit(); 41 | ((System.ComponentModel.ISupportInitialize)(this.pbRightEye)).BeginInit(); 42 | this.SuspendLayout(); 43 | // 44 | // btStart 45 | // 46 | this.btStart.Location = new System.Drawing.Point(12, 145); 47 | this.btStart.Name = "btStart"; 48 | this.btStart.Size = new System.Drawing.Size(75, 23); 49 | this.btStart.TabIndex = 1; 50 | this.btStart.Text = "Start"; 51 | this.btStart.UseVisualStyleBackColor = true; 52 | this.btStart.Click += new System.EventHandler(this.btStart_Click); 53 | // 54 | // pbLeftEye 55 | // 56 | this.pbLeftEye.Location = new System.Drawing.Point(117, 12); 57 | this.pbLeftEye.Name = "pbLeftEye"; 58 | this.pbLeftEye.Size = new System.Drawing.Size(83, 64); 59 | this.pbLeftEye.TabIndex = 2; 60 | this.pbLeftEye.TabStop = false; 61 | // 62 | // pbRightEye 63 | // 64 | this.pbRightEye.Location = new System.Drawing.Point(12, 12); 65 | this.pbRightEye.Name = "pbRightEye"; 66 | this.pbRightEye.Size = new System.Drawing.Size(75, 64); 67 | this.pbRightEye.TabIndex = 3; 68 | this.pbRightEye.TabStop = false; 69 | // 70 | // cbLeftEyeClosed 71 | // 72 | this.cbLeftEyeClosed.AutoSize = true; 73 | this.cbLeftEyeClosed.Location = new System.Drawing.Point(12, 82); 74 | this.cbLeftEyeClosed.Name = "cbLeftEyeClosed"; 75 | this.cbLeftEyeClosed.Size = new System.Drawing.Size(99, 17); 76 | this.cbLeftEyeClosed.TabIndex = 14; 77 | this.cbLeftEyeClosed.Text = "Left Eye closed"; 78 | this.cbLeftEyeClosed.UseVisualStyleBackColor = true; 79 | // 80 | // cbRightEyeClosed 81 | // 82 | this.cbRightEyeClosed.AutoSize = true; 83 | this.cbRightEyeClosed.Location = new System.Drawing.Point(117, 82); 84 | this.cbRightEyeClosed.Name = "cbRightEyeClosed"; 85 | this.cbRightEyeClosed.Size = new System.Drawing.Size(106, 17); 86 | this.cbRightEyeClosed.TabIndex = 15; 87 | this.cbRightEyeClosed.Text = "Right Eye closed"; 88 | this.cbRightEyeClosed.UseVisualStyleBackColor = true; 89 | // 90 | // label1 91 | // 92 | this.label1.AutoSize = true; 93 | this.label1.Location = new System.Drawing.Point(12, 102); 94 | this.label1.Name = "label1"; 95 | this.label1.Size = new System.Drawing.Size(105, 13); 96 | this.label1.TabIndex = 16; 97 | this.label1.Text = "Brow Lowerer Value:"; 98 | // 99 | // label2 100 | // 101 | this.label2.AutoSize = true; 102 | this.label2.Location = new System.Drawing.Point(117, 102); 103 | this.label2.Name = "label2"; 104 | this.label2.Size = new System.Drawing.Size(97, 13); 105 | this.label2.TabIndex = 17; 106 | this.label2.Text = "Brow Raiser Value:"; 107 | // 108 | // tbBrowLowerer 109 | // 110 | this.tbBrowLowerer.Location = new System.Drawing.Point(12, 119); 111 | this.tbBrowLowerer.Name = "tbBrowLowerer"; 112 | this.tbBrowLowerer.Size = new System.Drawing.Size(100, 20); 113 | this.tbBrowLowerer.TabIndex = 18; 114 | // 115 | // tbBrowRaiser 116 | // 117 | this.tbBrowRaiser.Location = new System.Drawing.Point(118, 118); 118 | this.tbBrowRaiser.Name = "tbBrowRaiser"; 119 | this.tbBrowRaiser.Size = new System.Drawing.Size(100, 20); 120 | this.tbBrowRaiser.TabIndex = 19; 121 | // 122 | // DebugForm 123 | // 124 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 125 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 126 | this.ClientSize = new System.Drawing.Size(266, 181); 127 | this.Controls.Add(this.tbBrowRaiser); 128 | this.Controls.Add(this.tbBrowLowerer); 129 | this.Controls.Add(this.label2); 130 | this.Controls.Add(this.label1); 131 | this.Controls.Add(this.cbRightEyeClosed); 132 | this.Controls.Add(this.cbLeftEyeClosed); 133 | this.Controls.Add(this.pbRightEye); 134 | this.Controls.Add(this.pbLeftEye); 135 | this.Controls.Add(this.btStart); 136 | this.Name = "DebugForm"; 137 | this.Text = "Face Debug Output"; 138 | ((System.ComponentModel.ISupportInitialize)(this.pbLeftEye)).EndInit(); 139 | ((System.ComponentModel.ISupportInitialize)(this.pbRightEye)).EndInit(); 140 | this.ResumeLayout(false); 141 | this.PerformLayout(); 142 | 143 | } 144 | 145 | #endregion 146 | 147 | private System.Windows.Forms.Button btStart; 148 | private System.Windows.Forms.PictureBox pbLeftEye; 149 | private System.Windows.Forms.PictureBox pbRightEye; 150 | private System.Windows.Forms.CheckBox cbLeftEyeClosed; 151 | private System.Windows.Forms.CheckBox cbRightEyeClosed; 152 | private System.Windows.Forms.Label label1; 153 | private System.Windows.Forms.Label label2; 154 | private System.Windows.Forms.TextBox tbBrowLowerer; 155 | private System.Windows.Forms.TextBox tbBrowRaiser; 156 | } 157 | } 158 | 159 | -------------------------------------------------------------------------------- /TestApp/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.IO; 9 | using System.Windows; 10 | using System.Windows.Forms; 11 | using Microsoft.Kinect; 12 | using Microsoft.Kinect.Toolkit; 13 | using Microsoft.Kinect.Toolkit.FaceTracking; 14 | using System.Drawing.Imaging; 15 | using System.Runtime.InteropServices; 16 | using ExpressionMouse; 17 | 18 | namespace TestApp 19 | { 20 | public partial class DebugForm : Form 21 | { 22 | 23 | private const double sigma = 4; 24 | private KinectSensor Kinect = null; 25 | private FaceTracker faceTracker = null; 26 | private byte[] colorImage; 27 | private ColorImageFormat colorImageFormat = ColorImageFormat.Undefined; 28 | private short[] depthImage; 29 | private DepthImageFormat depthImageFormat = DepthImageFormat.Undefined; 30 | public Skeleton[] SkeletonData { get; set; } 31 | private List headRotationHistory = new List(); 32 | //via Pascalsches Dreieck 33 | //int[] gaussFilter = { 92378, 75582, 50388, 27132, 11628, 3876, 969, 171, 19, 1 }; 34 | //int[] gaussFilter = { 155117520, 145422675, 119759850, 86493225, 54627300, 30045015, 14307150, 5852925, 2035800, 593775, 142506, 27405, 4060, 435, 30, 1 }; 35 | int[] gaussFilter = { 64, 55, 45, 35, 25, 20, 15, 10, 8, 7, 6, 5, 4, 3, 2, 1 }; 36 | List relevantDiffKeys = new List(); 37 | private const int filterLength = 16; 38 | double gaussFactor = 0; 39 | int rightCounter = 0; 40 | int leftCounter = 0; 41 | 42 | 43 | public void StartKinectST() 44 | { 45 | foreach (double filterValue in gaussFilter) 46 | gaussFactor += filterValue; 47 | 48 | Kinect = KinectSensor.KinectSensors.FirstOrDefault(s => s.Status == KinectStatus.Connected); // Get first Kinect Sensor 49 | Kinect.SkeletonStream.Enable(); // Enable skeletal tracking 50 | Kinect.ColorStream.Enable(); 51 | Kinect.DepthStream.Enable(); 52 | SkeletonData = new Skeleton[Kinect.SkeletonStream.FrameSkeletonArrayLength]; // Allocate ST data 53 | Kinect.Start(); // Start Kinect sensor 54 | faceTracker = new FaceTracker(Kinect); 55 | Kinect.AllFramesReady += this.OnAllFramesReady; 56 | 57 | //Set Near and Seated Mode 58 | Kinect.SkeletonStream.EnableTrackingInNearRange = true; 59 | Kinect.DepthStream.Range = DepthRange.Near; 60 | Kinect.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated; 61 | 62 | } 63 | 64 | private Bitmap ConvertGrey(Bitmap source) 65 | { 66 | Bitmap bm = new Bitmap(source.Width,source.Height); 67 | for(int y=0;y angleCount = new Dictionary(); 84 | angleCount.Add("-90--75", 0); 85 | angleCount.Add("-75--50", 0); 86 | angleCount.Add("-50--35", 0); 87 | angleCount.Add("-35--20", 0); 88 | angleCount.Add("-20-0", 0); 89 | angleCount.Add("0-20", 0); 90 | angleCount.Add("20-30", 0); 91 | angleCount.Add("30-45", 0); 92 | angleCount.Add("45-60", 0); 93 | angleCount.Add("60-75", 0); 94 | angleCount.Add("75-90", 0); 95 | angleCount.Add("else", 0); 96 | int[,] sobelMatrixX = {{-1,0,1},{-2,0,2},{-1,0,1}}; 97 | int[,] sobelMatrixY = {{-1,-2,-1},{0,0,0},{1,2,1}}; 98 | int divisor = 8; 99 | double dxGesamt = 0; 100 | double dyGesamt = 0; 101 | double direction = 0; 102 | for (int i = 1; i < original.Height-1; i++) 103 | { 104 | for (int j = 1; j < original.Width-1; j++) 105 | { 106 | double sumX = 0; 107 | double sumY = 0; 108 | for (int k = -1; k <= 1; k++) 109 | { 110 | for (int l = -1; l <= 1; l++) 111 | { 112 | double x = sobelMatrixX[k+1,l+1] * original.GetPixel(j+l,i+k).B; 113 | double y = sobelMatrixY[k + 1, l + 1] * original.GetPixel(j + l, i + k).B; 114 | sumX+=x; 115 | sumY += y; 116 | } 117 | } 118 | sumX = sumX / divisor; 119 | sumY = sumY / divisor; 120 | 121 | direction = (Math.Atan(sumX / sumY)) * 180 / Math.PI; 122 | if (direction >= -90 && direction <= -75) 123 | angleCount["-90--75"]++; 124 | else if (direction > -75 && direction <= -50) 125 | angleCount["-75--50"]++; 126 | else if (direction > -50 && direction <= -35) 127 | angleCount["-50--35"]++; 128 | else if (direction > -35 && direction <= -20) 129 | angleCount["-35--20"]++; 130 | else if (direction > -20 && direction <= 0) 131 | angleCount["-20-0"]++; 132 | else if (direction > 0 && direction <= 20) 133 | angleCount["0-20"]++; 134 | else if (direction > 20 && direction <= 30) 135 | angleCount["20-30"]++; 136 | else if (direction > 30 && direction <= 45) 137 | angleCount["30-45"]++; 138 | else if (direction > 45 && direction <= 60) 139 | angleCount["45-60"]++; 140 | else if (direction > 60 && direction <= 75) 141 | angleCount["60-75"]++; 142 | else if (direction > 75 && direction <= 90) 143 | angleCount["75-90"]++; 144 | else 145 | angleCount["else"]++; 146 | 147 | 148 | int gesamt = (int)Math.Sqrt(Math.Pow(sumX, 2) + Math.Pow(sumY, 2)); 149 | result.SetPixel(j, i, Color.FromArgb(gesamt, gesamt, gesamt)); 150 | 151 | dxGesamt += sumX; 152 | dyGesamt += sumY; 153 | } 154 | } 155 | dxGesamt = dxGesamt / (original.Width * original.Height); 156 | dyGesamt = dyGesamt / (original.Width * original.Height); 157 | dx = dxGesamt; 158 | dy = dyGesamt; 159 | 160 | if (IsEyeClosed(angleCount)) 161 | { 162 | if (right) 163 | cbLeftEyeClosed.Checked = true; 164 | else 165 | cbRightEyeClosed.Checked = true; 166 | } 167 | else 168 | { 169 | if (right) 170 | cbLeftEyeClosed.Checked = false; 171 | else 172 | cbRightEyeClosed.Checked = false; 173 | } 174 | return result; 175 | } 176 | 177 | private bool IsEyeClosed(Dictionary angleDistribution) 178 | { 179 | //Eye is closed, if 75% of all Pixels have a direction between -35° and +30° 180 | int valueSum = 0; 181 | int inAreaSum = 0; 182 | foreach(KeyValuePair kvp in angleDistribution) 183 | { 184 | valueSum += kvp.Value; 185 | if ( kvp.Key == "-20-0" || kvp.Key == "0-20") 186 | { 187 | inAreaSum += kvp.Value; 188 | } 189 | } 190 | if (valueSum == 0) 191 | return false; 192 | double result = (100 * inAreaSum) / valueSum; 193 | if (result >= 65) 194 | return true; 195 | else return false; 196 | 197 | } 198 | 199 | private void OnAllFramesReady(object sender, Microsoft.Kinect.AllFramesReadyEventArgs allFramesReadyEventArgs) 200 | { 201 | ColorImageFrame colorImageFrame = null; 202 | DepthImageFrame depthImageFrame = null; 203 | SkeletonFrame skeletonFrame = null; 204 | 205 | try 206 | { 207 | colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame(); 208 | depthImageFrame = allFramesReadyEventArgs.OpenDepthImageFrame(); 209 | skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame(); 210 | 211 | if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null) 212 | { 213 | return; 214 | } 215 | 216 | // Check for image format changes. The FaceTracker doesn't 217 | // deal with that so we need to reset. 218 | if (this.depthImageFormat != depthImageFrame.Format) 219 | { 220 | this.depthImage = null; 221 | this.depthImageFormat = depthImageFrame.Format; 222 | } 223 | 224 | if (this.colorImageFormat != colorImageFrame.Format) 225 | { 226 | this.colorImage = null; 227 | this.colorImageFormat = colorImageFrame.Format; 228 | } 229 | 230 | // Create any buffers to store copies of the data we work with 231 | if (this.depthImage == null) 232 | { 233 | this.depthImage = new short[depthImageFrame.PixelDataLength]; 234 | } 235 | 236 | if (this.colorImage == null) 237 | { 238 | this.colorImage = new byte[colorImageFrame.PixelDataLength]; 239 | } 240 | 241 | // Get the skeleton information 242 | if (this.SkeletonData == null || this.SkeletonData.Length != skeletonFrame.SkeletonArrayLength) 243 | { 244 | this.SkeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; 245 | } 246 | 247 | colorImageFrame.CopyPixelDataTo(this.colorImage); 248 | depthImageFrame.CopyPixelDataTo(this.depthImage); 249 | skeletonFrame.CopySkeletonDataTo(this.SkeletonData); 250 | Skeleton activeSkeleton = null; 251 | activeSkeleton = (from skel in this.SkeletonData where skel.TrackingState == SkeletonTrackingState.Tracked select skel).FirstOrDefault(); 252 | 253 | 254 | //Idea: Separate Eye-Parts of Color Image 255 | //Use learning Algorithm for right and left eye 256 | //Detect blink on separated parts of color Image 257 | 258 | //colorImage is one dimensional array with 640 x 480 x 4 (RGBA) values 259 | 260 | 261 | if (activeSkeleton != null) 262 | { 263 | FaceTrackFrame currentFaceFrame = faceTracker.Track(ColorImageFormat.RgbResolution640x480Fps30, colorImage, depthImageFormat, depthImage, activeSkeleton); 264 | float browRaiserValue = currentFaceFrame.GetAnimationUnitCoefficients()[AnimationUnit.BrowRaiser]; 265 | float browLowererValue = currentFaceFrame.GetAnimationUnitCoefficients()[AnimationUnit.BrowLower]; 266 | tbBrowLowerer.Text = browLowererValue.ToString(); 267 | tbBrowRaiser.Text = browRaiserValue.ToString(); 268 | //Get relevant Points for blink detection 269 | //Left eye 270 | int minX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveOneFourthLeftEyelid].X); 271 | int minY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveOneFourthLeftEyelid].Y); 272 | int maxX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.BelowThreeFourthLeftEyelid].X); 273 | int maxY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.BelowThreeFourthLeftEyelid].Y); 274 | Bitmap leftEye = EyeExtract(colorImageFrame, currentFaceFrame, minX, minY, maxX, maxY, false); 275 | pbLeftEye.Image = leftEye; 276 | 277 | //Right eye 278 | minX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveThreeFourthRightEyelid].X); 279 | minY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.AboveThreeFourthRightEyelid].Y); 280 | maxX = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.OneFourthBottomRightEyelid].X); 281 | maxY = (int)Math.Round(currentFaceFrame.GetProjected3DShape()[FeaturePoint.OneFourthBottomRightEyelid].Y); 282 | 283 | Bitmap rightEye = EyeExtract(colorImageFrame, currentFaceFrame, minX, minY, maxX, maxY, true); 284 | pbRightEye.Image = rightEye; 285 | 286 | //Wende Kantenfilter auf die beiden Augen an. 287 | double dxRight; 288 | double dyRight; 289 | double dxLeft; 290 | double dyLeft; 291 | if (rightEye != null && leftEye != null) 292 | { 293 | Bitmap edgePicRight = Convolution(ConvertGrey(rightEye), true, out dxRight, out dyRight); 294 | Bitmap edgePicLeft = Convolution(ConvertGrey(leftEye), false, out dxLeft, out dyLeft); 295 | 296 | 297 | 298 | //If Face is rotated, move Mouse 299 | if (headRotationHistory.Count > filterLength && currentFaceFrame.TrackSuccessful) 300 | { 301 | int x = 0; 302 | int y = 0; 303 | 304 | //Method 1: Ohne Glättung 305 | //ScaleXY(currentFaceFrame.Rotation, out x, out y); 306 | //MouseControl.Move(x, y); 307 | 308 | ////Method 2: Glättung über die letzten x Bilder: 309 | //int i = 0; 310 | //Vector3DF rotationMedium = new Vector3DF(); 311 | //while (i < 10 && headRotationHistory.Count - 1 > i) 312 | //{ 313 | // i++; 314 | // rotationMedium.X += headRotationHistory[headRotationHistory.Count - 1 - i].X; 315 | // rotationMedium.Y += headRotationHistory[headRotationHistory.Count - 1 - i].Y; 316 | //} 317 | //rotationMedium.X = rotationMedium.X / i; 318 | //rotationMedium.Y = rotationMedium.Y / i; 319 | //ScaleXY(rotationMedium, out x, out y); 320 | //MouseControl.Move(x, y); 321 | 322 | //Method 3: Gauß-Filter: Gewichte die letzten Bilder stärker. 323 | 324 | 325 | 326 | Vector3DF rotationMedium = new Vector3DF(); 327 | rotationMedium.X = currentFaceFrame.Rotation.X * gaussFilter[0]; 328 | rotationMedium.Y = currentFaceFrame.Rotation.Y * gaussFilter[0]; 329 | int i = 0; 330 | while (i < filterLength - 1) 331 | { 332 | i++; 333 | rotationMedium.X += (headRotationHistory[headRotationHistory.Count - 1 - i].X * gaussFilter[i]); 334 | rotationMedium.Y += (headRotationHistory[headRotationHistory.Count - 1 - i].Y * gaussFilter[i]); 335 | } 336 | rotationMedium.X = (float)(rotationMedium.X / gaussFactor); 337 | rotationMedium.Y = (float)(rotationMedium.Y / gaussFactor); 338 | ScaleXY(rotationMedium, out x, out y); 339 | 340 | MouseControl.Move(x, y); 341 | //Method 4: Quadratische Glättung 342 | //double deltaX = ((-currentFaceFrame.Rotation.Y) - (-headRotationHistory.Last().Y)); 343 | //double deltaY = ((-currentFaceFrame.Rotation.X) - (-headRotationHistory.Last().X)); 344 | //if (deltaX < 0) 345 | // deltaX = -Math.Pow(deltaX, 2) * 4; 346 | //else 347 | // deltaX = Math.Pow(deltaX, 2) * 4; 348 | //if (deltaY < 0) 349 | // deltaY = -Math.Pow(deltaY, 2) * 5; 350 | //else 351 | // deltaY = Math.Pow(deltaY, 2) * 5; 352 | //MouseControl.DeltaMove((int)Math.Round(deltaX, 0), (int)Math.Round(deltaY)); 353 | } 354 | 355 | headRotationHistory.Add(currentFaceFrame.Rotation); 356 | if (headRotationHistory.Count >= 100) 357 | headRotationHistory.RemoveAt(0); 358 | } 359 | } 360 | } 361 | catch (Exception e) 362 | { 363 | } 364 | finally 365 | { 366 | if (colorImageFrame != null) 367 | { 368 | colorImageFrame.Dispose(); 369 | } 370 | 371 | if (depthImageFrame != null) 372 | { 373 | depthImageFrame.Dispose(); 374 | } 375 | 376 | if (skeletonFrame != null) 377 | { 378 | skeletonFrame.Dispose(); 379 | } 380 | } 381 | } 382 | 383 | private Bitmap EyeExtract(ColorImageFrame colorImageFrame, FaceTrackFrame currentFaceFrame, int minX, int minY, int maxX, int maxY, bool right) 384 | { 385 | if (maxX < minX) 386 | { 387 | int temp = maxX; 388 | maxX = minX; 389 | minX = temp; 390 | } 391 | if (maxY < minY) 392 | { 393 | int temp = maxY; 394 | maxY = minY; 395 | minY = temp; 396 | } 397 | 398 | //Try to extract picture from area made by the marked points 399 | if (maxX > minX && maxY > minY && minY > 0 && minX > 0) 400 | { 401 | int minPosOneDim = ConvertXYToOneDimensionalCoordinate((int)minX, (int)minY, colorImageFrame.Width); 402 | int maxPosOneDim = ConvertXYToOneDimensionalCoordinate((int)maxX, (int)maxY, colorImageFrame.Width); 403 | 404 | int xLength = maxX - minX + 1; 405 | int yLength = maxY - minY + 1; 406 | //ARGB 407 | object[, ,] eyePic = new object[xLength, yLength, 4]; 408 | for (int xi = minX; xi <= maxX; xi++) 409 | { 410 | for (int yi = minY; yi <= maxY; yi++) 411 | { 412 | int oneDimensional = ConvertXYToOneDimensionalCoordinate(xi, yi, colorImageFrame.Width); 413 | eyePic[xi - minX, yi - minY, 0] = colorImage.GetValue(oneDimensional); 414 | eyePic[xi - minX, yi - minY, 1] = colorImage.GetValue(oneDimensional + 1); 415 | eyePic[xi - minX, yi - minY, 2] = colorImage.GetValue(oneDimensional + 2); 416 | eyePic[xi - minX, yi - minY, 3] = colorImage.GetValue(oneDimensional + 3); 417 | } 418 | } 419 | //Write eyePic to PictureBox 420 | Bitmap eyeBitmap = new Bitmap(xLength, yLength); 421 | for (int i = 0; i < xLength; i++) 422 | { 423 | for (int j = 0; j < yLength; j++) 424 | { 425 | eyeBitmap.SetPixel(i, j, Color.FromArgb(255, Int32.Parse(eyePic[i, j, 0].ToString()), Int32.Parse(eyePic[i, j, 1].ToString()), Int32.Parse(eyePic[i, j, 2].ToString()))); 426 | } 427 | } 428 | 429 | 430 | if (rightCounter % 100 == 0) 431 | rightCounter = 0; 432 | if (leftCounter % 100 == 0) 433 | leftCounter = 0; 434 | return eyeBitmap; 435 | } 436 | return null; 437 | } 438 | 439 | public void ScaleXY(Vector3DF rotation, out int xResult, out int yResult) 440 | { 441 | 442 | double screenWidth = SystemParameters.PrimaryScreenWidth; 443 | double y = ((SystemParameters.PrimaryScreenHeight / 30) * -rotation.X) + 444 | (SystemParameters.PrimaryScreenHeight / 2); 445 | double x = ((SystemParameters.PrimaryScreenWidth / 40) * -rotation.Y) + 446 | (SystemParameters.PrimaryScreenWidth / 2); 447 | 448 | if (x < 0) 449 | { 450 | x = 0; 451 | } 452 | else if (x > screenWidth - 1) 453 | { 454 | x = screenWidth - 1; 455 | } 456 | 457 | if (y < 0) 458 | { 459 | y = 0; 460 | } 461 | else if (y > SystemParameters.PrimaryScreenHeight - 1) 462 | y = SystemParameters.PrimaryScreenHeight; 463 | xResult = (int)x; 464 | yResult = (int)y; 465 | } 466 | 467 | private int ConvertXYToOneDimensionalCoordinate(int x, int y, int width) 468 | { 469 | return ((y-1) * width * 4 + x * 4); 470 | } 471 | 472 | private void ConvertOneDimensionalCoordinateToXY(int value, int width, out int x, out int y) 473 | { 474 | x = value % width; 475 | y = value / width; 476 | } 477 | 478 | public DebugForm() 479 | { 480 | InitializeComponent(); 481 | } 482 | 483 | private void btStart_Click(object sender, EventArgs e) 484 | { 485 | StartKinectST(); 486 | } 487 | 488 | private void label1_Click(object sender, EventArgs e) 489 | { 490 | 491 | } 492 | } 493 | } 494 | -------------------------------------------------------------------------------- /TestApp/Form1.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 | -------------------------------------------------------------------------------- /TestApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace TestApp 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// Der Haupteinstiegspunkt für die Anwendung. 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new DebugForm()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /TestApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über die folgenden 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die mit einer Assembly verknüpft sind. 8 | [assembly: AssemblyTitle("TestApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TestApp")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("2d8193b3-12c8-4ea1-8be5-42bc4fc60089")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 33 | // übernehmen, indem Sie "*" eingeben: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /TestApp/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Dieser Code wurde von einem Tool generiert. 4 | // Laufzeitversion:4.0.30319.296 5 | // 6 | // Änderungen an dieser Datei können fehlerhaftes Verhalten verursachen und gehen verloren, wenn 7 | // der Code neu generiert wird. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TestApp.Properties 12 | { 13 | 14 | 15 | /// 16 | /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. 17 | /// 18 | // Diese Klasse wurde von der StronglyTypedResourceBuilder-Klasse 19 | // über ein Tool wie ResGen oder Visual Studio automatisch generiert. 20 | // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen 21 | // mit der Option /str erneut aus, oder erstellen Sie Ihr VS-Projekt neu. 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 | /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. 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("TestApp.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle 56 | /// Ressourcenlookups, die diese stark typisierte Ressourcenklasse verwenden. 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 | -------------------------------------------------------------------------------- /TestApp/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 | -------------------------------------------------------------------------------- /TestApp/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.296 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 TestApp.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.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 | -------------------------------------------------------------------------------- /TestApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TestApp/TestApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {37EE628D-2409-4A0E-99D4-477733E316CF} 9 | WinExe 10 | Properties 11 | TestApp 12 | TestApp 13 | v4.0 14 | Client 15 | 512 16 | 17 | 18 | x86 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x86 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | ..\FaceMouseConfig\lib\Microsoft.Kinect.dll 39 | 40 | 41 | False 42 | ..\FaceMouseConfig\lib\Microsoft.Kinect.Toolkit.FaceTracking.dll 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Form 60 | 61 | 62 | Form1.cs 63 | 64 | 65 | 66 | 67 | Form1.cs 68 | Designer 69 | 70 | 71 | ResXFileCodeGenerator 72 | Resources.Designer.cs 73 | Designer 74 | 75 | 76 | True 77 | Resources.resx 78 | 79 | 80 | SettingsSingleFileGenerator 81 | Settings.Designer.cs 82 | 83 | 84 | True 85 | Settings.settings 86 | True 87 | 88 | 89 | 90 | 91 | {6E7F533D-F149-42C1-B8BC-44F674EACB35} 92 | ExpressionMouse 93 | 94 | 95 | 96 | 103 | -------------------------------------------------------------------------------- /TestApp/bin/Debug/FaceTrackData.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/TestApp/bin/Debug/FaceTrackData.dll -------------------------------------------------------------------------------- /TestApp/bin/Debug/FaceTrackLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/TestApp/bin/Debug/FaceTrackLib.dll -------------------------------------------------------------------------------- /TestApp/bin/Debug/Microsoft.Kinect.Toolkit.FaceTracking.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/TestApp/bin/Debug/Microsoft.Kinect.Toolkit.FaceTracking.dll -------------------------------------------------------------------------------- /TestApp/bin/Debug/Microsoft.Kinect.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/TestApp/bin/Debug/Microsoft.Kinect.dll -------------------------------------------------------------------------------- /TestApp/bin/Debug/TestApp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/TestApp/bin/Debug/TestApp.exe -------------------------------------------------------------------------------- /TestApp/bin/Debug/TestApp.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/TestApp/bin/Debug/TestApp.vshost.exe -------------------------------------------------------------------------------- /TestApp/bin/Debug/TestApp.vshost.exe.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /executable/ExpressionMouse.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/executable/ExpressionMouse.exe -------------------------------------------------------------------------------- /executable/FaceTrackData.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/executable/FaceTrackData.dll -------------------------------------------------------------------------------- /executable/FaceTrackLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/executable/FaceTrackLib.dll -------------------------------------------------------------------------------- /executable/Microsoft.Kinect.Toolkit.FaceTracking.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/executable/Microsoft.Kinect.Toolkit.FaceTracking.dll -------------------------------------------------------------------------------- /executable/Microsoft.Kinect.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/executable/Microsoft.Kinect.dll -------------------------------------------------------------------------------- /executable/Microsoft.Speech.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/executable/Microsoft.Speech.dll -------------------------------------------------------------------------------- /executable/init.txt: -------------------------------------------------------------------------------- 1 | 15.09.2017 18:01:05 - Error during Kinect initialization. 2 | 15.09.2017 18:02:13 - Error during Kinect initialization. 3 | -------------------------------------------------------------------------------- /executable/mouseLog.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thtemme/ExpressionMouse-Kinect/b0f3c3eda33a09526ca653008bc62a303847c042/executable/mouseLog.txt -------------------------------------------------------------------------------- /executable/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 4 | 64, 55, 45, 35, 25, 20, 15, 10, 8, 7, 6, 5, 4, 3, 2, 1 5 | 68 6 | 10 7 | 0.5 8 | 0.18 9 | 0.5 10 | 0.16 11 | 0.75 12 | 0.5 13 | 0.25 14 | 150 15 | 250 16 | 35 17 | 25 18 | --------------------------------------------------------------------------------