Explorar o código

added tolerance for palm.Isinside() (-0,1 up to 1.1)

Alexander Hendrich %!s(int64=10) %!d(string=hai) anos
pai
achega
5a579b5c81

+ 2 - 1
bbiwarg/Parameters.cs

@@ -108,6 +108,7 @@ namespace bbiwarg
 
         // palm detection
         public static readonly int PalmNumPositionsForPalmWidth = 5;
+        public static readonly float PalmInsideTolerance = 0.1f;
 
         // palm tracker
         public static readonly int PalmTrackerNumFramesDetectedUntilTracked = 5;
@@ -172,7 +173,7 @@ namespace bbiwarg
         public static readonly Color TouchEventVisualizerPointColor = Color.Red;
         public static readonly Color TouchEventVisualizerGridColor = Color.White;
         public static readonly Color TouchEventVisualizerTextColor = Color.White;
-        public static readonly Color TouchEventVisualizerActiveBlockColor = Color.DarkSlateGray;
+        public static readonly Color TouchEventVisualizerActiveBlockColor = Color.DarkSlateGray; 
 
         public static readonly Color PalmQuadColor = Color.Blue;
         public static readonly Color PalmGridColor = Color.CornflowerBlue;

+ 7 - 2
bbiwarg/Recognition/PalmRecognition/Palm.cs

@@ -44,12 +44,17 @@ namespace bbiwarg.Recognition.PalmRecognition
 
         public Vector2D getRelativePosition(Vector2D absolutePosition)
         {
-            return Quad.getRelativePosition(absolutePosition);
+            Vector2D relativePosition = Quad.getRelativePosition(absolutePosition);
+            float x = Math.Max(0, Math.Min(1, relativePosition.X));
+            float y = Math.Max(0, Math.Min(1, relativePosition.Y));
+            Console.WriteLine(x + "\t" + y);
+
+            return new Vector2D(x, y);
         }
 
         public bool isInside(Vector2D position)
         {
-            return Quad.isInside(position);
+            return Quad.isInside(position, Parameters.PalmInsideTolerance);
         }
 
         private void createQuad()

+ 5 - 2
bbiwarg/Utility/Quadrangle.cs

@@ -55,10 +55,13 @@ namespace bbiwarg.Utility
             return new Vector2D(u, v);
         }
 
-        public bool isInside(Vector2D point)
+        public bool isInside(Vector2D point, float tolerance=0.0f)
         {
             Vector2D relativePos = getRelativePosition(point);
-            return (relativePos.X >= 0 && relativePos.X <= 1.0 && relativePos.Y >= 0 && relativePos.Y <= 1.0);
+            float min = 0 - tolerance;
+            float max = 1 + tolerance;
+
+            return (relativePos.X >= min && relativePos.X <= max) && (relativePos.Y >= min && relativePos.Y <= max);
         }
     }
 }