Browse Source

changed Intel Parameters to make Hand Detection work

Alexander Hendrich 7 years ago
parent
commit
25275b8548

BIN
.vs/bbiwarg/v14/.suo


+ 2 - 2
bbiwarg/API/Server.cs

@@ -30,12 +30,12 @@ namespace BBIWARG.API
             {
                 Grid.getInctance().Cols = grid.Cols;
                 Grid.getInctance().Rows = grid.Rows;
-                Output.DebugOutput.DebugWindow.palmGridNumColumnsTrackBar.Invoke((MethodInvoker)delegate {
+                /*Output.DebugOutput.DebugWindow.palmGridNumColumnsTrackBar.Invoke((MethodInvoker)delegate {
                     Output.DebugOutput.DebugWindow.palmGridNumColumnsTrackBar.Value = grid.Cols;
                 });
                 Output.DebugOutput.DebugWindow.palmGridNumRowsTrackBar.Invoke((MethodInvoker)delegate {
                     Output.DebugOutput.DebugWindow.palmGridNumRowsTrackBar.Value = grid.Rows;
-                });
+                });*/
                 return "Done!";
             }
             catch(Exception e)

+ 3 - 3
bbiwarg/Images/DepthImage.cs

@@ -48,10 +48,10 @@ namespace BBIWARG.Images
             // threshold min&maxDepth
             MinDepth = findMinDepth(rawDepthImage);
             MaxDepth = (UInt16)(MinDepth + Parameters.DepthImageDepthRange);
-
+            
             // threshold (dst = (src > (MaxDepth - MinDepth)) ? MaxDepth - MinDepth : src)
-            Image = (rawDepthImage - MinDepth).ThresholdTrunc(new Gray(MaxDepth - MinDepth)).Convert<Gray, byte>();
-
+            Image = (rawDepthImage - MinDepth).Convert<Gray, Int16>().ThresholdTrunc(new Gray(MaxDepth - MinDepth)).Convert<Gray, byte>();
+            
             // smooth with median filter
             Image = Image.SmoothMedian(Parameters.DepthImageMedianSize);
         }

+ 2 - 0
bbiwarg/Input/InputHandling/FrameData.cs

@@ -5,6 +5,8 @@ using BBIWARG.Recognition.PalmRecognition;
 using BBIWARG.Recognition.TouchRecognition;
 using BBIWARG.Utility;
 using System.Collections.Generic;
+using Emgu.CV;
+using Emgu.CV.Structure;
 
 namespace BBIWARG.Input.InputHandling
 {

+ 22 - 19
bbiwarg/Input/InputProviding/InputProviderIntel.cs

@@ -31,18 +31,16 @@ namespace BBIWARG.Input.InputProviding
             private set;
         }
 
-        public int ImageHeight
+        public int ImageWidth
         {
-            get;
-            private set;
+            get { return 640; }
         }
 
-        public int ImageWidth
+        public int ImageHeight
         {
-            get;
-            private set;
+            get { return 480; }
         }
-
+        
         public bool IsActive
         {
             get;
@@ -72,13 +70,7 @@ namespace BBIWARG.Input.InputProviding
             PXCMPointF32 fov = senseManager.captureManager.device.QueryDepthFieldOfView();
             FieldOfViewHorizontal = fov.x;
             FieldOfViewVertical = fov.y;
-
-            while (senseManager.AcquireFrame(true).IsError()) { }
-            PXCMImage.ImageInfo info = senseManager.QuerySample().depth.info;
-            ImageWidth = info.width;
-            ImageHeight = info.height;
-            senseManager.ReleaseFrame();
-
+            
             lowConfidenceValue = senseManager.captureManager.device.QueryDepthLowConfidenceValue();
             senseManager.captureManager.device.SetDepthConfidenceThreshold((UInt16)Parameters.ConfidenceImageMinThreshold);
 
@@ -108,16 +100,27 @@ namespace BBIWARG.Input.InputProviding
                     PXCMImage depthImage = sample.depth;
                     PXCMImage.ImageInfo info = depthImage.info;
                     PXCMImage.ImageData imageData;
+                    
                     depthImage.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH, out imageData);
-                    Bitmap dBmp = imageData.ToBitmap(0, info.width, info.height);
+                    ushort[] data = imageData.ToUShortArray(0, info.width * info.height);
+
+                    Image<Gray, UInt16> dImg;
+
+                    unsafe
+                    {
+                        fixed (ushort* d = data)
+                        {
+                            IntPtr ptr = (IntPtr)d;
+                            dImg = new Image<Gray, UInt16>(info.width, info.height, info.width * sizeof(ushort), ptr).Copy();
+                        }
+                    }
+                    
                     depthImage.ReleaseAccess(imageData);
                     depthImage.Dispose();
-
-                    Image<Gray, UInt16> dImg = new Image<Gray, UInt16>(dBmp);
-                    
+                  
                     // confidence filter
                     Image<Gray, byte> mask = dImg.InRange(new Gray(lowConfidenceValue), new Gray(lowConfidenceValue));
-                    dImg.SetValue(new Gray(UInt16.MaxValue), mask);
+                    dImg.SetValue(new Gray(Int16.MaxValue), mask);
 
                     NewFrameEvent(this, new NewFrameEventArgs(CurrentFrameID, dImg));
                 }

+ 1 - 1
bbiwarg/Output/DebugOutput/DebugImageCreator.cs

@@ -134,7 +134,7 @@ namespace BBIWARG.Output.DebugOutput
 
             HandImage = new OutputImage(frameData.ImageSize);
 
-            foreach (Hand h in frameData.TrackedHands)
+            foreach (Hand h in frameData.DetectedHands)
             {
                 HandImage.drawImage(h.Mask.ThresholdBinary(new Gray(0), new Gray(255)), Parameters.HandColors[h.TrackID % Parameters.HandNumColors]);
                 HandImage.fillCircle(h.Centroid, 5, Parameters.HandCentroidColor);

+ 29 - 28
bbiwarg/Output/DebugOutput/DebugWindow.Designer.cs

@@ -2,9 +2,6 @@
 {
     partial class DebugWindow
     {
-
-        public static System.Windows.Forms.TrackBar palmGridNumRowsTrackBar;
-        public static System.Windows.Forms.TrackBar palmGridNumColumnsTrackBar;
         /// <summary>
         /// Required designer variable.
         /// </summary>
@@ -39,15 +36,13 @@
             this.imageBox6 = new Emgu.CV.UI.ImageBox();
             this.panel1 = new System.Windows.Forms.Panel();
             this.frameLabel = new System.Windows.Forms.Label();
-            palmGridNumColumnsTrackBar = new System.Windows.Forms.TrackBar();
+            this.palmGridNumColumnsTrackBar = new System.Windows.Forms.TrackBar();
             this.palmGridNumColumnsLabel = new System.Windows.Forms.Label();
             this.palmGridNumRowsLabel = new System.Windows.Forms.Label();
             this.palmGridLabel = new System.Windows.Forms.Label();
             this.label2 = new System.Windows.Forms.Label();
             this.videoControlLabel = new System.Windows.Forms.Label();
-
-
-            palmGridNumRowsTrackBar = new System.Windows.Forms.TrackBar();
+            this.palmGridNumRowsTrackBar = new System.Windows.Forms.TrackBar();
             this.previousFrameButton = new System.Windows.Forms.Button();
             this.nextFrameButton = new System.Windows.Forms.Button();
             this.playPauseButton = new System.Windows.Forms.Button();
@@ -58,8 +53,8 @@
             ((System.ComponentModel.ISupportInitialize)(this.palmImageBox)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.imageBox6)).BeginInit();
             this.panel1.SuspendLayout();
-            ((System.ComponentModel.ISupportInitialize)(palmGridNumColumnsTrackBar)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(palmGridNumRowsTrackBar)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.palmGridNumColumnsTrackBar)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.palmGridNumRowsTrackBar)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.touchImageBox)).BeginInit();
             this.SuspendLayout();
             // 
@@ -70,6 +65,7 @@
             this.depthImageBox.Margin = new System.Windows.Forms.Padding(0);
             this.depthImageBox.Name = "depthImageBox";
             this.depthImageBox.Size = new System.Drawing.Size(320, 240);
+            this.depthImageBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
             this.depthImageBox.TabIndex = 2;
             this.depthImageBox.TabStop = false;
             // 
@@ -80,6 +76,7 @@
             this.fingerImageBox.Margin = new System.Windows.Forms.Padding(0);
             this.fingerImageBox.Name = "fingerImageBox";
             this.fingerImageBox.Size = new System.Drawing.Size(320, 240);
+            this.fingerImageBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
             this.fingerImageBox.TabIndex = 2;
             this.fingerImageBox.TabStop = false;
             // 
@@ -90,6 +87,7 @@
             this.handImageBox.Margin = new System.Windows.Forms.Padding(0);
             this.handImageBox.Name = "handImageBox";
             this.handImageBox.Size = new System.Drawing.Size(320, 240);
+            this.handImageBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
             this.handImageBox.TabIndex = 2;
             this.handImageBox.TabStop = false;
             // 
@@ -100,6 +98,7 @@
             this.palmImageBox.Margin = new System.Windows.Forms.Padding(0);
             this.palmImageBox.Name = "palmImageBox";
             this.palmImageBox.Size = new System.Drawing.Size(320, 240);
+            this.palmImageBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
             this.palmImageBox.TabIndex = 2;
             this.palmImageBox.TabStop = false;
             // 
@@ -115,13 +114,13 @@
             // panel1
             // 
             this.panel1.Controls.Add(this.frameLabel);
-            this.panel1.Controls.Add(palmGridNumColumnsTrackBar);
+            this.panel1.Controls.Add(this.palmGridNumColumnsTrackBar);
             this.panel1.Controls.Add(this.palmGridNumColumnsLabel);
             this.panel1.Controls.Add(this.palmGridNumRowsLabel);
             this.panel1.Controls.Add(this.palmGridLabel);
             this.panel1.Controls.Add(this.label2);
             this.panel1.Controls.Add(this.videoControlLabel);
-            this.panel1.Controls.Add(palmGridNumRowsTrackBar);
+            this.panel1.Controls.Add(this.palmGridNumRowsTrackBar);
             this.panel1.Controls.Add(this.previousFrameButton);
             this.panel1.Controls.Add(this.nextFrameButton);
             this.panel1.Controls.Add(this.playPauseButton);
@@ -142,13 +141,13 @@
             // 
             // palmGridNumColumnsTrackBar
             // 
-            palmGridNumColumnsTrackBar.Location = new System.Drawing.Point(56, 148);
-            palmGridNumColumnsTrackBar.Minimum = 1;
-           palmGridNumColumnsTrackBar.Name = "palmGridNumColumnsTrackBar";
-            palmGridNumColumnsTrackBar.Size = new System.Drawing.Size(247, 45);
-            palmGridNumColumnsTrackBar.TabIndex = 4;
-            palmGridNumColumnsTrackBar.Value = 1;
-            palmGridNumColumnsTrackBar.Scroll += new System.EventHandler(this.palmGridTrackBar_Scroll);
+            this.palmGridNumColumnsTrackBar.Location = new System.Drawing.Point(56, 148);
+            this.palmGridNumColumnsTrackBar.Minimum = 1;
+            this.palmGridNumColumnsTrackBar.Name = "palmGridNumColumnsTrackBar";
+            this.palmGridNumColumnsTrackBar.Size = new System.Drawing.Size(247, 45);
+            this.palmGridNumColumnsTrackBar.TabIndex = 4;
+            this.palmGridNumColumnsTrackBar.Value = 1;
+            this.palmGridNumColumnsTrackBar.Scroll += new System.EventHandler(this.palmGridTrackBar_Scroll);
             // 
             // palmGridNumColumnsLabel
             // 
@@ -198,13 +197,13 @@
             // 
             // palmGridNumRowsTrackBar
             // 
-            palmGridNumRowsTrackBar.Location = new System.Drawing.Point(56, 108);
-            palmGridNumRowsTrackBar.Minimum = 1;
-            palmGridNumRowsTrackBar.Name = "palmGridNumRowsTrackBar";
-            palmGridNumRowsTrackBar.Size = new System.Drawing.Size(247, 45);
-            palmGridNumRowsTrackBar.TabIndex = 3;
-            palmGridNumRowsTrackBar.Value = 1;
-            palmGridNumRowsTrackBar.Scroll += new System.EventHandler(this.palmGridTrackBar_Scroll);
+            this.palmGridNumRowsTrackBar.Location = new System.Drawing.Point(56, 108);
+            this.palmGridNumRowsTrackBar.Minimum = 1;
+            this.palmGridNumRowsTrackBar.Name = "palmGridNumRowsTrackBar";
+            this.palmGridNumRowsTrackBar.Size = new System.Drawing.Size(247, 45);
+            this.palmGridNumRowsTrackBar.TabIndex = 3;
+            this.palmGridNumRowsTrackBar.Value = 1;
+            this.palmGridNumRowsTrackBar.Scroll += new System.EventHandler(this.palmGridTrackBar_Scroll);
             // 
             // previousFrameButton
             // 
@@ -246,6 +245,7 @@
             this.touchImageBox.Margin = new System.Windows.Forms.Padding(0);
             this.touchImageBox.Name = "touchImageBox";
             this.touchImageBox.Size = new System.Drawing.Size(320, 240);
+            this.touchImageBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
             this.touchImageBox.TabIndex = 2;
             this.touchImageBox.TabStop = false;
             // 
@@ -275,8 +275,8 @@
             ((System.ComponentModel.ISupportInitialize)(this.imageBox6)).EndInit();
             this.panel1.ResumeLayout(false);
             this.panel1.PerformLayout();
-            ((System.ComponentModel.ISupportInitialize)(palmGridNumColumnsTrackBar)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(palmGridNumRowsTrackBar)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.palmGridNumColumnsTrackBar)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.palmGridNumRowsTrackBar)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.touchImageBox)).EndInit();
             this.ResumeLayout(false);
 
@@ -300,6 +300,7 @@
         private System.Windows.Forms.Label palmGridNumColumnsLabel;
         private System.Windows.Forms.Label frameLabel;
         private Emgu.CV.UI.ImageBox touchImageBox;
-        
+        public System.Windows.Forms.TrackBar palmGridNumRowsTrackBar;
+        public System.Windows.Forms.TrackBar palmGridNumColumnsTrackBar;
     }
 }

+ 8 - 8
bbiwarg/Parameters.cs

@@ -44,7 +44,7 @@ namespace BBIWARG
         /// <summary>
         /// the input source type
         /// </summary>
-        public static readonly InputType InputSource = InputType.DS325;
+        public static readonly InputType InputSource = InputType.RS300;
 
         #endregion input
 
@@ -138,7 +138,7 @@ namespace BBIWARG
         /// <summary>
         /// the depth range which is considered important (in mm) (must be smaller than 255)
         /// </summary>
-        public static readonly int DepthImageDepthRange = 200;
+        public static readonly int DepthImageDepthRange = 254;
 
         /// <summary>
         /// the size of the median filter used to filter the depth image
@@ -200,17 +200,17 @@ namespace BBIWARG
         /// <summary>
         /// the maximum slice length difference of two consecutive slices (used to drop outliers)
         /// </summary>
-        public static readonly int FingerMaxSliceLengthDifferencePerStep = 5;
+        public static int FingerMaxSliceLengthDifferencePerStep { get { return InputSource == InputType.RS300 ? 10 : 5; } }
 
         /// <summary>
         /// maximum finger slice length (in pixels)
         /// </summary>
-        public static readonly int FingerMaxWidth2D = 30;
+        public static int FingerMaxWidth2D { get { return InputSource == InputType.RS300 ? 60 : 30; } }
 
         /// <summary>
         /// maximum finger slice length (in mm)
         /// </summary>
-        public static readonly float FingerMaxWidth3D = 35f;
+        public static float FingerMaxWidth3D { get { return InputSource == InputType.RS300 ? 50.0f : 35.0f; } }
 
         /// <summary>
         /// the minimum number of slices a finger must have
@@ -300,12 +300,12 @@ namespace BBIWARG
         /// <summary>
         /// maximum downwards depth difference between a pixel and a neighboring pixel belonging to the same hand
         /// </summary>
-        public static readonly int HandFloodFillDownDiff = 2;
+        public static int HandFloodFillDownDiff { get { return InputSource == InputType.RS300 ? 1 : 2;}}
 
         /// <summary>
         /// maximum upwards depth difference between a pixel and a neighboring pixel belonging to the same hand
         /// </summary>
-        public static readonly int HandFloodFillUpDiff = 2;
+        public static int HandFloodFillUpDiff { get { return InputSource == InputType.RS300 ? 1 : 2; } }
 
         /// <summary>
         /// maximum size of a hand relative to the whole image
@@ -493,7 +493,7 @@ namespace BBIWARG
         /// <summary>
         /// the size of the quadrant around the touch positions that is used to determine the touch value
         /// </summary>
-        public static readonly int TouchAreaSize = 30;
+        public static int TouchAreaSize { get { return InputSource == InputType.RS300 ? 60 : 30; }}
 
         /// <summary>
         /// the maximum downwards difference for the flood fill operation

+ 3 - 2
bbiwarg/Recognition/HandRecognition/HandDetector.cs

@@ -48,7 +48,7 @@ namespace BBIWARG.Recognition.HandRecognition
         {
             depthImage = frameData.DepthImage;
             fingers = frameData.TrackedFingers;
-
+            
             createModifiedHandEdgeImage();
             findHands();
             fixOverlappingFingers();
@@ -186,7 +186,8 @@ namespace BBIWARG.Recognition.HandRecognition
                 {
                     Image<Gray, byte> handMask = getHandMask(finger.HandPoint);
 
-                    int numPixels = handMask.CountNonzero()[0];
+
+                    int numPixels = handMask.CountNonzero()[0];                    
                     if (numPixels > Parameters.HandMaxSize * depthImage.Size.NumPixels)
                     {
                         assignedFingers.Add(finger);

+ 5 - 2
bbiwarg/Recognition/TouchRecognition/TouchDetector.cs

@@ -5,6 +5,7 @@ using BBIWARG.Recognition.PalmRecognition;
 using BBIWARG.Utility;
 using Emgu.CV;
 using Emgu.CV.Structure;
+using Emgu.CV.UI;
 using System;
 using System.Collections.Generic;
 using System.Drawing;
@@ -77,19 +78,21 @@ namespace BBIWARG.Recognition.TouchRecognition
                 if (palm.isInside(tipPointOutside))
                 {
                     Image<Gray, byte> touchMask = getTouchMask(tipPointInside);
-
+                    
                     int touchPixels = touchMask.CountNonzero()[0];
                     int numPixels = touchMask.Width * touchMask.Height;
                     float touchValue = touchPixels / (float)numPixels;
-
+                    
                     if (touchValue > Parameters.TouchMinTouchValue)
                     {
                         Touch touch = new Touch(tipPointOutside, finger, palm);
                         return touch;
                     }
+
                 }
             }
 
+
             return null;
         }