Explorar el Código

minor changes to touchDetection, removed helperfunctions

Alexander Hendrich hace 10 años
padre
commit
ea6f66f86c

+ 1 - 0
bbiwarg/Constants.cs

@@ -21,6 +21,7 @@ namespace bbiwarg
 
         public static readonly Color TouchEventDetectedColor = ColorDetected;
         public static readonly Color TouchEventTrackedColor = ColorTracked;
+        public static readonly Color TouchEventTipColor = Color.CornflowerBlue;
         public static readonly Color TouchEventAreaMatchedSubtractColor = Color.DarkOrange;
         public static readonly Color TouchEventAreaNonMatchedSubtractColor = Color.DarkSlateGray;
         public static readonly Color TouchEventStatusBarColor = Color.Green;

+ 3 - 6
bbiwarg/Detectors/Fingers/FingerDetector.cs

@@ -224,13 +224,10 @@ namespace bbiwarg.Detectors.Fingers
             int maxFingerSize = 35;
 
             Vector2D direction = (end - start).normalize();
-            Vector2D beforeStart = start - direction;
-            Vector2D behindEnd = end + direction;
+            Vector2D beforeStart = (start - direction).moveInBound(0,0,maxX,maxY);
+            Vector2D behindEnd = (end + direction).moveInBound(0, 0, maxY, maxY);
 
-            start = beforeStart.isWithin(0, 0, maxX, maxY) ? beforeStart : start;
-            end = behindEnd.isWithin(0, 0, maxX, maxY) ? behindEnd : end;
-
-            FingerSlice slice = new FingerSlice(start, end);
+            FingerSlice slice = new FingerSlice(beforeStart, behindEnd);
             if (slice.Length >= minFingerSize && slice.Length <= maxFingerSize && fingerSliceDepthTest(slice))
                 return slice;
 

+ 2 - 2
bbiwarg/Detectors/Palm/PalmDetector.cs

@@ -138,8 +138,8 @@ namespace bbiwarg.Detectors.Palm
             if (finger == null)
                 return new Point(0, 0);
             Vector2D direction = (finger.Hand - finger.Tip).normalize();
-            Vector2D pos = finger.Hand + 20 * direction;
-            return new Point(HelperFunctions.thresholdRange<int>(0, width - 1, pos.IntX), HelperFunctions.thresholdRange<int>(0, height - 1, pos.IntY));
+            Vector2D pos = (finger.Hand + 20 * direction).moveInBound(0,0,width-1,height-1);
+            return pos;
         }
 
         //public OutputImage i1, i2, i3, i4, i5, i6, i7, i8, i9;

+ 4 - 5
bbiwarg/Detectors/Touch/TouchDetector.cs

@@ -33,16 +33,15 @@ namespace bbiwarg.Detectors.Touch
             {
                 Vector2D tipPoint = finger.Tip;
 
+                outputImage.fillCircle(tipPoint.IntX, tipPoint.IntY, 3, Constants.TouchEventTipColor);
+
                 float floodValue = getFloodValue(tipPoint);
                 if (floodValue > floodValueThreshold)
                 {
                     //correct touchEvent position
                     Vector2D direction = finger.LineSegment.Line.Direction;
-                    float directionFactor = 10;
-                    float x = HelperFunctions.thresholdRange<float>(0, depthImage.Width - 1, tipPoint.X + directionFactor * direction.X);
-                    float y = HelperFunctions.thresholdRange<float>(0, depthImage.Height - 1, tipPoint.Y + directionFactor * direction.Y);
-                    Vector2D tep = new Vector2D(x, y);
-
+                    Vector2D tep = (tipPoint + 5 * direction).moveInBound(0,0,depthImage.Width-1,depthImage.Height-1);
+                    
                     outputImage.fillCircle(tep.IntX, tep.IntY, 5, Constants.TouchEventDetectedColor);
                     TouchEvent touchEvent = new TouchEvent(tep, floodValue, finger);
                     TouchEvents.Add(touchEvent);

+ 0 - 20
bbiwarg/Utility/HelperFunctions.cs

@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace bbiwarg.Utility
-{
-    public static class HelperFunctions
-    {
-        public static T thresholdRange<T>(T min, T max, T value)
-        {
-            if (Comparer<T>.Default.Compare(min, value) > 0)
-                return min;
-            if (Comparer<T>.Default.Compare(value, max) > 0)
-                return max;
-            return value;
-        }
-    }
-}

+ 7 - 0
bbiwarg/Utility/Vector2D.cs

@@ -86,6 +86,13 @@ namespace bbiwarg.Utility
             return (X >= minX && Y >= minY && X <= maxX && Y <= maxY);
         }
 
+        public Vector2D moveInBound(float minX, float minY, float maxX, float maxY)
+        {
+            float x = Math.Min(maxX, Math.Max(minX, X));
+            float y = Math.Min(maxY, Math.Max(minY, Y));
+            return new Vector2D(x, y);
+        }
+
         public Vector2D getOrthogonal(bool side)
         {
             if (side)