Browse Source

improved touchEvent localisation (fingerTip + 10*fingerDirection)

Alexander Hendrich 11 years ago
parent
commit
900ab8218b

+ 12 - 7
bbiwarg/Detectors/Fingers/Finger.cs

@@ -19,14 +19,14 @@ namespace bbiwarg.Detectors.Fingers
         private PointF pointOnLine;
         private PointF start;
         private PointF end;
-        private bool startEndUpToDate;
+        private bool lineUpToDate;
 
         public Finger(FingerPoint fingerPoint)
         {
             fingerPoints = new List<FingerPoint>();
             nearest = fingerPoint;
             farthest = fingerPoint;
-            startEndUpToDate = false;
+            lineUpToDate = false;
             addFingerPoint(fingerPoint);
         }
 
@@ -42,16 +42,21 @@ namespace bbiwarg.Detectors.Fingers
 
         public PointF getStart()
         {
-            if (!startEndUpToDate) updateStartEnd();
+            if (!lineUpToDate) updateLine();
             return start;
         }
 
         public PointF getEnd()
         {
-            if (!startEndUpToDate) updateStartEnd();
+            if (!lineUpToDate) updateLine();
             return end;
         }
 
+        public PointF getDirection() {
+            if (!lineUpToDate) updateLine();
+            return direction;
+        }
+
         public void addFingerPoint(FingerPoint fingerPoint)
         {
             fingerPoints.Add(fingerPoint);
@@ -62,7 +67,7 @@ namespace bbiwarg.Detectors.Fingers
             //update farthest
             if (fingerPoint.getDepth() > farthest.getDepth()) farthest = fingerPoint;
 
-            startEndUpToDate = false;
+            lineUpToDate = false;
         }
 
         public float getMinDistance(FingerPoint fingerPoint)
@@ -101,7 +106,7 @@ namespace bbiwarg.Detectors.Fingers
             return new PointF(ox + q * dx, oy + q * dy);
         }
 
-        private void updateStartEnd() {
+        private void updateLine() {
             //update direction+pointonline
             PointF[] pointArray = new PointF[fingerPoints.Count];
             int i = 0;
@@ -116,7 +121,7 @@ namespace bbiwarg.Detectors.Fingers
             start = projectToLine(new PointF(farthest.getX(), farthest.getY()));
             end = projectToLine(new PointF(nearest.getX(), nearest.getY()));
 
-            startEndUpToDate = true;
+            lineUpToDate = true;
         }
     }
 }

+ 9 - 3
bbiwarg/Detectors/Touch/TouchDetector.cs

@@ -18,10 +18,10 @@ namespace bbiwarg.Detectors.Touch
         private List<Finger> fingers;
         private List<TouchEvent> touchEvents;
 
-        public TouchDetector(DepthImage depthImage, List<Finger> fingers, TouchImage touchImage) {
+        public TouchDetector(List<Finger> fingers, DepthImage depthImage, TouchImage touchImage) {
             this.depthImage = depthImage;
-            this.fingers = fingers;
             this.touchImage = touchImage;
+            this.fingers = fingers;
             this.touchEvents = new List<TouchEvent>();
             float touchValueThreshold = 0.5f;
 
@@ -39,7 +39,13 @@ namespace bbiwarg.Detectors.Touch
                 float touchValue = getTouchValueAt(fp.getX(), fp.getY());
                 if (touchValue > touchValueThreshold)
                 {
-                    TouchEvent touchEvent = new TouchEvent(fp.getX(), fp.getY(), touchValue, finger);
+                    PointF direction = finger.getDirection();
+                    float directionFactor = -10;
+                    PointF tep = new PointF(fp.getX() + directionFactor*direction.X, fp.getY() + directionFactor*direction.Y);
+                    
+
+                    touchImage.setTouchAt((int)tep.X, (int)tep.Y, TouchImageState.touchDetected);
+                    TouchEvent touchEvent = new TouchEvent((int)tep.X, (int)tep.Y, touchValue, finger);
                     touchEvents.Add(touchEvent);
                 }
             }

+ 6 - 1
bbiwarg/Detectors/Touch/TouchTracker.cs

@@ -3,11 +3,13 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using bbiwarg.Images;
 
 namespace bbiwarg.Detectors.Touch
 {
     class TouchTracker
     {
+        private TouchImage touchImage;
         private List<TouchEvent>[] detectedTouchEvents;
         private List<TouchEvent> trackedTouchEvents;
         private int framesUntilTracked;
@@ -25,7 +27,9 @@ namespace bbiwarg.Detectors.Touch
             return trackedTouchEvents;
         }
 
-        public void setDetectedTouchEventsThisFrame(List<TouchEvent> touchEventsThisFrame) {
+        public void setDetectedTouchEventsThisFrame(List<TouchEvent> touchEventsThisFrame, TouchImage touchImage) {
+            this.touchImage = touchImage;
+
             for (int i = (framesUntilTracked-1); i > 0; i--) {
                 detectedTouchEvents[i] = detectedTouchEvents[i - 1]; 
             }
@@ -45,6 +49,7 @@ namespace bbiwarg.Detectors.Touch
                 }
                 if (tracked)
                 {
+                    touchImage.setTouchAt(te.getX(), te.getY(), TouchImageState.touchTracked);
                     trackedTouchEvents.Add(te);
                     Console.WriteLine("touch tracked at x:" + te.getX() + " y:" + te.getY() + " [touchValue:" + te.getTouchValue() + "]");
                 }

+ 12 - 2
bbiwarg/Graphics/OutputWindow.cs

@@ -91,15 +91,15 @@ namespace bbiwarg.Graphics
                     TouchImageState tis = videoHandle.getTouchImageStateAt(x,y);
                     if (tis == TouchImageState.touchArea)
                     {
-                        red = Int16.MaxValue;
+                        red = (Int16) (red/2);
                         green = (Int16) (green / 2);
                         blue = (Int16) (blue / 2);
                     }
                     else if (tis == TouchImageState.touchAreaMatched)
                     {
                         red = (Int16) (red / 2);
+                        green = (Int16)(green / 2);
                         blue = Int16.MaxValue;
-                        green = (Int16) (green / 2);
                         
                     }
                     else if (tis == TouchImageState.touchAreaStatusBar)
@@ -108,6 +108,16 @@ namespace bbiwarg.Graphics
                         green = Int16.MaxValue;
                         blue = (Int16)(blue / 2); ;
                     }
+                    else if (tis == TouchImageState.touchDetected)
+                    {
+                        red = blue = 0;
+                        green = Int16.MaxValue;
+                    }
+                    else if (tis == TouchImageState.touchTracked)
+                    {
+                        red = Int16.MaxValue;
+                        green = blue = 0;
+                    }
 
                     depthTextureData[index] = red;
                     depthTextureData[index + 1] = green;

+ 2 - 2
bbiwarg/VideoHandle.cs

@@ -120,10 +120,10 @@ namespace bbiwarg
             touchImage = new TouchImage(depthImage);
 
             //detect touchEvents
-            touchDetector = new TouchDetector(depthImage, fingerDetector.getFingers(), touchImage);
+            touchDetector = new TouchDetector(fingerDetector.getFingers(), depthImage, touchImage);
 
             //track touchEvents
-            touchTracker.setDetectedTouchEventsThisFrame(touchDetector.getTouchEvents());
+            touchTracker.setDetectedTouchEventsThisFrame(touchDetector.getTouchEvents(), touchImage);
         }
     }
 }