Преглед изворни кода

Fixed getRelativePosition() for quad on the right hand.

Daniel Kauth пре 10 година
родитељ
комит
2bfd2c4873

+ 3 - 0
bbiwarg/Recognition/PalmRecognition/PalmDetector.cs

@@ -31,6 +31,7 @@ namespace bbiwarg.Recognition.PalmRecognition
         private float lastPalmQuadArea;
 
         public Quadrangle PalmQuad { get; private set; }
+        public  Hand.HandSide PalmHandSide {get; private set; }
 
         public PalmDetector()
         {
@@ -101,6 +102,7 @@ namespace bbiwarg.Recognition.PalmRecognition
             thumbDefectEndFilter.reset();
             palmContour = null;
             PalmQuad = null;
+            PalmHandSide = Hand.HandSide.Left;
             numFramesNoHandFound = 0;
             lastPalmQuadArea = 0.0f;
         }
@@ -249,6 +251,7 @@ namespace bbiwarg.Recognition.PalmRecognition
                     (quad.Area / lastPalmQuadArea >= Constants.PalmMinAreaQuotient && quad.Area / lastPalmQuadArea <= Constants.PalmMaxAreaQuotient))
                 {
                     PalmQuad = quad;
+                    PalmHandSide = palmHand.Side;
                     lastPalmQuadArea = PalmQuad.Area;
                 }
             }

+ 4 - 2
bbiwarg/Recognition/TouchRecognition/PalmTouchDetector.cs

@@ -7,19 +7,21 @@ using bbiwarg.Recognition.FingerRecognition;
 using bbiwarg.Recognition.PalmRecognition;
 using bbiwarg.Utility;
 
+using bbiwarg.Recognition.HandRecognition;
+
 namespace bbiwarg.Recognition.TouchRecognition
 {
     class PalmTouchDetector
     {
         public List<PalmTouchEvent> PalmTouchEvents { get; private set; }
 
-        public PalmTouchDetector(List<TouchEvent> touchEvents, Quadrangle palmQuad)
+        public PalmTouchDetector(List<TouchEvent> touchEvents, Quadrangle palmQuad, Hand.HandSide side)
         {
             PalmTouchEvents = new List<PalmTouchEvent>();
 
             foreach (TouchEvent touchEvent in touchEvents)
             {
-                Vector2D relativePos = palmQuad.getRelativePosition(touchEvent.Position);
+                Vector2D relativePos = palmQuad.getRelativePosition(touchEvent.Position, side);
                 if (relativePos.X >= 0 && relativePos.X <= 1.0 && relativePos.Y >= 0 && relativePos.Y <= 1.0)
                 {
                     PalmTouchEvent pte = new PalmTouchEvent(touchEvent.Position, relativePos, touchEvent.FloodValue, touchEvent.Finger);

+ 19 - 5
bbiwarg/Utility/Quadrangle.cs

@@ -6,6 +6,8 @@ using System.Threading.Tasks;
 
 using System.Drawing;
 
+using bbiwarg.Recognition.HandRecognition;
+
 using Emgu.CV;
 
 namespace bbiwarg.Utility
@@ -35,12 +37,24 @@ namespace bbiwarg.Utility
         }
 
 
-        public Vector2D getRelativePosition(Vector2D p)
+        public Vector2D getRelativePosition(Vector2D p, Hand.HandSide side)
         {
-            Vector2D a = BottomLeft;
-            Vector2D b = TopLeft;
-            Vector2D c = TopRight;
-            Vector2D d = BottomRight;
+            Vector2D a, b, c, d;
+
+            if (side == Hand.HandSide.Left)
+            {
+                a = BottomLeft;
+                b = TopLeft;
+                c = TopRight;
+                d = BottomRight;
+            }
+            else
+            {
+                a = BottomRight;
+                b = TopRight;
+                c = TopLeft;
+                d = BottomLeft;
+            }
 
             float C = (a.Y - p.Y) * (d.X - p.X) - (a.X - p.X) * (d.Y - p.Y);
             float B = (a.Y - p.Y) * (c.X - d.X) + (b.Y - a.Y) * (d.X - p.X) - (a.X - p.X) * (c.Y - d.Y) - (b.X - a.X) * (d.Y - p.Y);

+ 1 - 2
bbiwarg/VideoHandle.cs

@@ -201,7 +201,7 @@ namespace bbiwarg
             Timer.start("touchDetection");
             touchDetector = new TouchDetector(fingerTracker.TrackedFingers, depthImage, OutputImages[0]);
             if (palmDetector.PalmQuad != null)
-                palmTouchDetector = new PalmTouchDetector(touchDetector.TouchEvents, palmDetector.PalmQuad);
+                palmTouchDetector = new PalmTouchDetector(touchDetector.TouchEvents, palmDetector.PalmQuad, palmDetector.PalmHandSide);
             Timer.stop("touchDetection");
 
             //track touchEvents
@@ -209,7 +209,6 @@ namespace bbiwarg
             touchTracker.setDetectedTouchEventsThisFrame(touchDetector.TouchEvents, OutputImages[3]);
             Timer.stop("touchTracking");
 
-
             Timer.start("sending touchEvents");
             //send touchevent
             if (palmTouchDetector != null)