Browse Source

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/etri-smartspaces

Daniel Kauth 10 years ago
parent
commit
15c43aef47

+ 3 - 5
bbiwarg/Detectors/Palm/PalmDetector.cs

@@ -30,7 +30,6 @@ namespace bbiwarg.Detectors.Palm
 
         private Contour<Point> palmContour;
         private List<MCvConvexityDefect> convexityDefects;
-        private Vector2D wristPoint, wristDirection;
         private LineSegment2DF wristLine, thumbLine;
         private Quadrangle palmQuad;
 
@@ -40,7 +39,7 @@ namespace bbiwarg.Detectors.Palm
         private Vector2D bottomLeft;
         private Vector2D bottomRight;
 
-        public PalmDetector(DepthImage depthImage, EdgeImage edgeImage, FingerDetector fingerDetector, PalmImage palmImage)
+        public PalmDetector(DepthImage depthImage, EdgeImage edgeImage, List<Finger> detectedFingers, PalmImage palmImage)
         {
             width = depthImage.getWidth();
             height = depthImage.getHeight();
@@ -50,7 +49,7 @@ namespace bbiwarg.Detectors.Palm
 
             handImage = depthImage.getImage().Convert<Byte>(delegate(short s) { return (s == depthImage.getMaxDepth()) ? (byte)0 : (byte)1; });
             
-            fingers = getFingersWithoutThumb(fingerDetector);
+            fingers = getFingersWithoutThumb(detectedFingers);
             buildPointingHandMask();
             handImage = handImage.And(pointingHandMask);
 
@@ -77,9 +76,8 @@ namespace bbiwarg.Detectors.Palm
             return palmQuad;
         }
 
-        private List<Finger> getFingersWithoutThumb(FingerDetector fingerDetector)
+        private List<Finger> getFingersWithoutThumb(List<Finger> detectedFingers)
         {
-            List<Finger> detectedFingers = fingerDetector.Fingers;
             Finger leftMost = null;
             float minX = float.MaxValue;
             foreach (Finger f in detectedFingers)

+ 23 - 16
bbiwarg/Graphics/OutputWindow.cs

@@ -21,7 +21,8 @@ namespace bbiwarg.Graphics
         private long timeSpacePressed, timeLeftPressed, timeRightPressed;
         private Stopwatch watch;
 
-        public OutputWindow(VideoHandle videoHandle): base(3 * videoHandle.getWidth(), 2 * videoHandle.getHeight())
+        public OutputWindow(VideoHandle videoHandle)
+            : base(3 * videoHandle.getWidth(), 2 * videoHandle.getHeight())
         {
             this.videoHandle = videoHandle;
             watch = new Stopwatch();
@@ -68,7 +69,7 @@ namespace bbiwarg.Graphics
 
         protected override void OnRenderFrame(FrameEventArgs e)
         {
-            
+
             base.OnRenderFrame(e);
             GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
             Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
@@ -139,9 +140,9 @@ namespace bbiwarg.Graphics
                     Int16 blue = 0;
 
                     //depthTexture
-                    float relDepth = videoHandle.getRelativeDepth(x,y);
+                    float relDepth = videoHandle.getRelativeDepth(x, y);
                     red = green = blue = (Int16)((1.0f - videoHandle.getRelativeDepth(x, y)) * Int16.MaxValue);
-                    
+
                     // palm
                     switch (videoHandle.getPalmImageStateAt(x, y))
                     {
@@ -159,9 +160,11 @@ namespace bbiwarg.Graphics
                             blue = red = 0;
                             break;
                         case PalmImageState.palmGrid:
-                            green = blue = red = Int16.MaxValue;
+                            green = (Int16)(green / 2 + Int16.MaxValue / 2);
+                            blue = (Int16)(blue / 2 + Int16.MaxValue / 2);
+                            red = (Int16)(red / 2 + Int16.MaxValue / 2);
                             break;
-                            
+
 
                     }
 
@@ -184,13 +187,17 @@ namespace bbiwarg.Graphics
                             blue = (Int16)(blue / 2);
                             break;
                         case TouchImageState.touchDetected:
-                            red = blue = 0;
-                            green = Int16.MaxValue;
+                            red = (Int16)(red / 2);
+                            blue = (Int16)(blue / 2);
+                            green = (Int16)(green / 2 + Int16.MaxValue / 2);
                             break;
                         case TouchImageState.touchTracked:
-                            red = Int16.MaxValue;
-                            green = blue = 0;
+                            red = (Int16)(red / 2 + Int16.MaxValue / 2);
+                            green = (Int16)(green / 2);
+                            blue = (Int16)(blue / 2);
                             break;
+                        
+                        
                     }
 
                     depthTextureData[index] = red;
@@ -198,7 +205,7 @@ namespace bbiwarg.Graphics
                     depthTextureData[index + 2] = blue;
 
                     //edgeTexture
-                    FingerImageState fis = videoHandle.getFingerImageStateAt(x,y);
+                    FingerImageState fis = videoHandle.getFingerImageStateAt(x, y);
                     red = green = blue = 0;
                     if (videoHandle.isEdgeAt(x, y)) blue = Int16.MaxValue;
                     else if (fis == FingerImageState.fingerTracked) green = Int16.MaxValue;
@@ -218,7 +225,7 @@ namespace bbiwarg.Graphics
             GL.BindTexture(TextureTarget.Texture2D, depthTextureID);
             GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.getWidth(), videoHandle.getHeight(), 0, PixelFormat.Rgb, PixelType.Short, depthTextureData);
             float size = 0.5f;
-            float size_2 = (float) (size / 2.0f);
+            float size_2 = (float)(size / 2.0f);
             GL.Begin(PrimitiveType.Quads);
             GL.Color3(1.0, 1.0, 1.0);
             GL.TexCoord2(0.0, 0.0); GL.Vertex3(0, size_2, -0.5);
@@ -232,10 +239,10 @@ namespace bbiwarg.Graphics
             GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.getWidth(), videoHandle.getHeight(), 0, PixelFormat.Rgb, PixelType.Short, edgeTextureData);
             GL.Begin(PrimitiveType.Quads);
             GL.Color3(1.0, 1.0, 1.0);
-            GL.TexCoord2(0.0, 0.0); GL.Vertex3(0, -size/2.0, -0.5);
-            GL.TexCoord2(-1.0, 0.0); GL.Vertex3(-size, -size/2.0, -0.5);
-            GL.TexCoord2(-1.0, -1.0); GL.Vertex3(-size, size/2.0, -0.5);
-            GL.TexCoord2(0.0, -1.0); GL.Vertex3(0, size/2.0, -0.5);
+            GL.TexCoord2(0.0, 0.0); GL.Vertex3(0, -size / 2.0, -0.5);
+            GL.TexCoord2(-1.0, 0.0); GL.Vertex3(-size, -size / 2.0, -0.5);
+            GL.TexCoord2(-1.0, -1.0); GL.Vertex3(-size, size / 2.0, -0.5);
+            GL.TexCoord2(0.0, -1.0); GL.Vertex3(0, size / 2.0, -0.5);
             GL.End();
 
 

+ 30 - 5
bbiwarg/Images/TouchImage.cs

@@ -5,9 +5,13 @@ using System.Text;
 using System.Threading.Tasks;
 using Emgu.CV;
 using Emgu.CV.Structure;
+
+using bbiwarg.Utility;
+
 namespace bbiwarg.Images
 {
-    public enum TouchImageState {
+    public enum TouchImageState
+    {
         none = 0,
         touchArea = 1,
         touchAreaMatched = 2,
@@ -19,16 +23,37 @@ namespace bbiwarg.Images
     class TouchImage
     {
         private Image<Gray, byte> image;
+        private List<Vector2D> oldTouches;
 
-        public TouchImage(int width, int height) {
+        public TouchImage(int width, int height)
+        {
             image = new Image<Gray, byte>(width, height);
+            oldTouches = new List<Vector2D>();
         }
 
-        public void setTouchAt(int x, int y, TouchImageState tis) {
-            image.Data[y, x, 0] = (byte) tis;
+        public void setTouchAt(int x, int y, TouchImageState tis)
+        {
+            image.Data[y, x, 0] = (byte)tis;
+
+            int size = 5;
+            if (tis == TouchImageState.touchTracked || tis == TouchImageState.touchDetected)
+            {
+                for (int i = x - size; i < x + size; i++)
+                {
+                    for (int j = y - size; j < y + size; j++)
+                    {
+                        if (i >= 0 && j >= 0 && i <= image.Width && j <= image.Height && Math.Sqrt(((x - i) * (x - i)) + ((y - j) * (y - j))) <= size)
+                        {
+                            image.Data[j, i, 0] = (byte)tis;
+                        }
+                    }
+                }
+            }
         }
 
-        public TouchImageState getStateAt(int x, int y) {
+
+        public TouchImageState getStateAt(int x, int y)
+        {
             return (TouchImageState)image.Data[y, x, 0];
         }
     }

+ 1 - 1
bbiwarg/VideoHandle.cs

@@ -150,7 +150,7 @@ namespace bbiwarg
             fingerTracker.setDetectedTouchEventsThisFrame(fingerDetector.Fingers, fingerImage);
 
             //detect palm
-            palmDetector = new PalmDetector(depthImage, edgeImage, fingerDetector, palmImage);
+            palmDetector = new PalmDetector(depthImage, edgeImage, fingerDetector.Fingers, palmImage);
 
             //detect+track touchEvents
             touchDetector = new TouchDetector(fingerTracker.getFingers(), depthImage, touchImage);