Browse Source

Made side detection of one hand more stable.

Daniel Kauth 10 years ago
parent
commit
140a0bd4cd
1 changed files with 18 additions and 2 deletions
  1. 18 2
      bbiwarg/Recognition/PalmRecognition/PalmDetector.cs

+ 18 - 2
bbiwarg/Recognition/PalmRecognition/PalmDetector.cs

@@ -29,6 +29,7 @@ namespace bbiwarg.Recognition.PalmRecognition
         private Kalman2DPositionFilter thumbDefectDepthFilter, thumbDefectStartFilter, thumbDefectEndFilter;
         private int numFramesNoHandFound;
         private float lastPalmQuadArea;
+        private List<Hand> hands;
 
         public Quadrangle PalmQuad { get; private set; }
         public  Hand.HandSide PalmHandSide {get; private set; }
@@ -46,6 +47,7 @@ namespace bbiwarg.Recognition.PalmRecognition
         public void findPalmQuad(OutputImage outputImage, List<Hand> hands)
         {
             this.outputImage = outputImage;
+            this.hands = hands;
 
             if (hands.Count == 1 && hands[0].Fingers.Count == 1)
             {
@@ -82,7 +84,7 @@ namespace bbiwarg.Recognition.PalmRecognition
                 findConvexityDefectsSortedByDepth();
                 if (pointingHand != null)
                     removeConvexityDefectsCausedByFingers();
-                findHandPoints(hands.Count);
+                findHandPoints();
             }
 
             if (hands.Count == 0)
@@ -197,7 +199,7 @@ namespace bbiwarg.Recognition.PalmRecognition
             return null;
         }
 
-        private void findHandPoints(int numHands)
+        private void findHandPoints()
         {
             MCvConvexityDefect? thumbDefect = findThumbDefect();
 
@@ -229,11 +231,25 @@ namespace bbiwarg.Recognition.PalmRecognition
                 {
                     handLength = startDepth;
                     longestLineEndpoint = thumbDefectStart;
+                    if (hands.Count == 1)
+                    {
+                        if (thumbDefectStart.X > thumbDefectDepth.X)
+                            hands[0].Side = Hand.HandSide.Left;
+                        else
+                            hands[0].Side = Hand.HandSide.Right;
+                    }
                 }
                 else
                 {
                     handLength = endDepth;
                     longestLineEndpoint = thumbDefectEnd;
+                    if (hands.Count == 1)
+                    {
+                        if (thumbDefectEnd.X > thumbDefectDepth.X)
+                            hands[0].Side = Hand.HandSide.Left;
+                        else
+                            hands[0].Side = Hand.HandSide.Right;
+                    }
                 }
 
                 if (palmHand.Side == Hand.HandSide.Left)