Browse Source

Removed KalmanDemo.
Added TouchEventVisualizer.

Daniel Kauth 10 years ago
parent
commit
a13bd3580f

+ 1 - 0
bbiwarg/Detectors/Fingers/FingerDetector.cs

@@ -9,6 +9,7 @@ using bbiwarg.Images;
 using bbiwarg.Utility;
 using Emgu.CV.Structure;
 using Emgu.CV;
+using bbiwarg.Graphics;
 
 namespace bbiwarg.Detectors.Fingers
 {

+ 1 - 0
bbiwarg/Detectors/Fingers/FingerTracker.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using bbiwarg.Images;
+using bbiwarg.Graphics;
 
 namespace bbiwarg.Detectors.Fingers
 {

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

@@ -9,10 +9,9 @@ using Emgu.CV;
 using Emgu.CV.Structure;
 
 using bbiwarg.Utility;
-
 using bbiwarg.Images;
-
 using bbiwarg.Detectors.Fingers;
+using bbiwarg.Graphics;
 
 namespace bbiwarg.Detectors.Palm
 {

+ 1 - 0
bbiwarg/Detectors/Touch/TouchDetector.cs

@@ -10,6 +10,7 @@ using bbiwarg.Images;
 using bbiwarg.Detectors.Fingers;
 using bbiwarg.Detectors.Palm;
 using bbiwarg.Utility;
+using bbiwarg.Graphics;
 
 namespace bbiwarg.Detectors.Touch
 {

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

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using bbiwarg.Images;
+using bbiwarg.Graphics;
 
 namespace bbiwarg.Detectors.Touch
 {

+ 0 - 68
bbiwarg/Graphics/KalmanDemo.cs

@@ -1,68 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-using System.Drawing;
-
-using Emgu.CV;
-using Emgu.CV.Structure;
-
-using bbiwarg.Utility;
-using bbiwarg.Detectors.Touch;
-
-namespace bbiwarg.Graphics
-{
-    class KalmanDemo
-    {
-        private List<Point> points, kalmanPoints;
-        private Kalman2DPositionFilter kalman;
-
-        public KalmanDemo()
-        {
-            points = new List<Point>();
-            kalmanPoints = new List<Point>();
-        }
-
-        public void addPoint(Point p)
-        {
-            if (points.Count == 0)
-                kalman = new Kalman2DPositionFilter(new Vector2D(p));
-
-            Vector2D v = kalman.getCorrectedPosition(new Vector2D(p));
-
-            points.Add(p);
-            kalmanPoints.Add(new Point(v.IntX, v.IntY));
-        }
-
-        public void reset()
-        {
-            points.Clear();
-            kalmanPoints.Clear();
-        }
-
-        public Int16[] getTextureData(int width, int height)
-        {
-            Image<Bgr, short> image = new Image<Bgr, short>(width, height);
-            image.DrawPolyline(points.ToArray(), false, new Bgr(0, Int16.MaxValue, 0), 1);
-            image.DrawPolyline(kalmanPoints.ToArray(), false, new Bgr(0, 0, Int16.MaxValue), 1);
-
-            Int16[] textureData = new Int16[3 * width * height];
-            int index = 0;
-            for (int y = 0; y < height; ++y)
-            {
-                for (int x = 0; x < width; ++x)
-                {
-                    textureData[index + 0] = image.Data[y, x, 2];
-                    textureData[index + 1] = image.Data[y, x, 1];
-                    textureData[index + 2] = image.Data[y, x, 0];
-
-                    index += 3;
-                }
-            }
-
-            return textureData;
-        }
-    }
-}

+ 1 - 1
bbiwarg/Graphics/OutputImage.cs

@@ -9,7 +9,7 @@ using System.Drawing;
 using Emgu.CV;
 using Emgu.CV.Structure;
 
-namespace bbiwarg.Images
+namespace bbiwarg.Graphics
 {
     class OutputImage
     {

+ 2 - 3
bbiwarg/Graphics/OutputWindow.cs

@@ -78,7 +78,7 @@ namespace bbiwarg.Graphics
         protected override void OnRenderFrame(FrameEventArgs e)
         {
             Timer.start("onRenderFrame");
-
+   
             base.OnRenderFrame(e);
             GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
             Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
@@ -133,7 +133,6 @@ namespace bbiwarg.Graphics
             if (videoHandle.sourceIsMovie())
                 Title = "BBIWARG - Output (Frame " + videoHandle.getCurrentMovieFrame() + ")";
 
-
             Timer.start("outputTextures");
             GL.Enable(EnableCap.Texture2D);
                 
@@ -159,7 +158,7 @@ namespace bbiwarg.Graphics
             Timer.stop("outputTextures");
 
             Timer.stop("onRenderFrame");
-
+            
             Timer.outputAll();
         }
 

+ 50 - 0
bbiwarg/Graphics/TouchEventVisualizer.cs

@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using bbiwarg.Detectors.Touch;
+using bbiwarg.Utility;
+
+namespace bbiwarg.Graphics
+{
+    class TouchEventVisualizer
+    {
+        public OutputImage OutputImage { get; private set; }
+        
+        private List<Vector2D> touchPositions;
+        private int width, height;
+
+        public TouchEventVisualizer(int width, int height)
+        {
+            touchPositions = new List<Vector2D>();
+            this.width = width;
+            this.height = height;
+        }
+
+        public void addPalmTouchEvent(PalmTouchEvent e)
+        {
+            Vector2D pos = new Vector2D((int) (e.RelativePalmPosition.X * width), (int) (e.RelativePalmPosition.Y * height));
+            touchPositions.Add(pos);
+        }
+
+        public void updateImage()
+        {
+            OutputImage = new OutputImage(width, height);
+
+            for (int i = 1; i < touchPositions.Count; ++i)
+            {
+                OutputImage.drawLineSegment(new LineSegment2D(touchPositions[i - 1], touchPositions[i]), 255, 255, 255);
+            }
+
+            if (touchPositions.Count != 0)
+                OutputImage.fillCircle(touchPositions.Last<Vector2D>().IntX, touchPositions.Last<Vector2D>().IntY, 3, 255, 0, 0);
+        }
+
+        public void Reset()
+        {
+            touchPositions.Clear();
+            OutputImage = new OutputImage(width, height);
+        }
+    }
+}

+ 1 - 0
bbiwarg/Images/DepthImage.cs

@@ -6,6 +6,7 @@ using System.Text;
 using System.Threading.Tasks;
 using Emgu.CV;
 using Emgu.CV.Structure;
+using bbiwarg.Graphics;
 
 namespace bbiwarg.Images
 {

+ 1 - 0
bbiwarg/Images/EdgeImage.cs

@@ -10,6 +10,7 @@ using bbiwarg.Detectors.Fingers;
 
 using System.Diagnostics;
 using bbiwarg.Utility;
+using bbiwarg.Graphics;
 
 namespace bbiwarg.Images
 {

+ 13 - 1
bbiwarg/VideoHandle.cs

@@ -12,6 +12,7 @@ using bbiwarg.Images;
 using bbiwarg.InputProviders;
 using Emgu.CV;
 using Emgu.CV.Structure;
+using bbiwarg.Graphics;
 
 namespace bbiwarg
 {
@@ -38,6 +39,7 @@ namespace bbiwarg
 
         private OutputImage edgeFingerOutputImage;
         private OutputImage depthPalmTouchOutputImage;
+        private TouchEventVisualizer touchEventVisualizer;
 
         public VideoHandle(IInputProvider inputProvider)
         {
@@ -160,7 +162,17 @@ namespace bbiwarg
             touchTracker.setDetectedTouchEventsThisFrame(touchDetector.TouchEvents, depthPalmTouchOutputImage);
             Timer.stop("touchTracking");
 
-            OutputImages = new OutputImage[] { edgeFingerOutputImage, depthPalmTouchOutputImage };
+            // touch event visualizer
+            if (touchEventVisualizer == null)
+                touchEventVisualizer = new TouchEventVisualizer(Width, Height);
+            if (getCurrentMovieFrame() == 0)
+                touchEventVisualizer.Reset();
+            foreach (PalmTouchEvent e in palmTouchDetector.PalmTouchEvents)
+                touchEventVisualizer.addPalmTouchEvent(e);
+            touchEventVisualizer.updateImage();
+
+            // output images
+            OutputImages = new OutputImage[] { edgeFingerOutputImage, depthPalmTouchOutputImage, touchEventVisualizer.OutputImage};
 
             Timer.stop("processFrameUpdate");
         }

+ 1 - 1
bbiwarg/bbiwarg.csproj

@@ -78,7 +78,7 @@
     <Compile Include="Detectors\Touch\TouchEvent.cs" />
     <Compile Include="Detectors\Touch\TouchTracker.cs" />
     <Compile Include="Graphics\OutputWindow.cs" />
-    <Compile Include="Graphics\KalmanDemo.cs" />
+    <Compile Include="Graphics\TouchEventVisualizer.cs" />
     <Compile Include="Images\DepthImage.cs" />
     <Compile Include="Images\EdgeImage.cs" />
     <Compile Include="Graphics\OutputImage.cs" />