Alexander Hendrich 11 gadi atpakaļ
vecāks
revīzija
855bb5903e

+ 24 - 7
bbiwarg/Graphics/Output2D.cs

@@ -12,17 +12,18 @@ using bbiwarg.Graphics.GraphicElements2D;
 using bbiwarg.InputProviders;
 using bbiwarg.Images;
 using bbiwarg.Helpers;
+using bbiwarg.VideoHandles;
 
 namespace bbiwarg.Graphics
 {
     class Output2D: GameWindow
     {
-        private IInputProvider input;
+        private IVideoHandle videoHandle;
         private uint textureId;
 
-        public Output2D(IInputProvider input): base(3 * 320, 3 * 240)
+        public Output2D(IVideoHandle videoHandle): base(3 * 320, 3 * 240)
         {
-            this.input = input;
+            this.videoHandle = videoHandle;
         }
 
         protected override void OnLoad(EventArgs e)
@@ -55,12 +56,28 @@ namespace bbiwarg.Graphics
             GL.MatrixMode(MatrixMode.Modelview);
             GL.LoadMatrix(ref modelview);
 
-            input.releaseFrame();
-            input.updateFrame();
+            videoHandle.nextFrame();
 
             Stopwatch sw = new Stopwatch();
             sw.Start();
 
+            short[] textureData = new short[3 * videoHandle.getWidth() * videoHandle.getHeight()];
+            int index = 0;
+            for (int y = 0; y < videoHandle.getHeight(); ++y)
+            {
+                for (int x = 0; x < videoHandle.getWidth(); ++x)
+                {
+                    // 0 --> 0 / 2000 -> short.MaxValue
+                    int depthHand1 = videoHandle.getHand1Image().getDepth(x, y);
+                    int depthHand2 = videoHandle.getHand2Image().getDepth(x, y);
+                    textureData[index] = (short) (depthHand1 * short.MaxValue / 2000);
+                    textureData[index + 1] = (short)(depthHand2 * short.MaxValue / 2000);
+                    textureData[index + 2] = 0;
+                    index += 3;
+                }
+            }
+
+            /*
             DepthImage depthImage = input.getDepthImage();
             depthImage.filterMedian(3);
 
@@ -112,9 +129,9 @@ namespace bbiwarg.Graphics
                     }
                 }
             }
-
+            */
             GL.BindTexture(TextureTarget.Texture2D, textureId);
-            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, depthImage.getWidth(), depthImage.getHeight(), 0,
+            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.getWidth(), videoHandle.getHeight(), 0,
                           PixelFormat.Rgb, PixelType.Short, textureData);
 
             float size_2 = 0.5f / 2.0f;

+ 6 - 0
bbiwarg/Images/DepthImage.cs

@@ -88,5 +88,11 @@ namespace bbiwarg.Images
             }
             return result;
         }
+
+        public void floodFill(int x, int y)
+        {
+            Emgu.CV.Structure.MCvConnectedComp comp = new MCvConnectedComp();
+            Emgu.CV.CvInvoke.cvFloodFill(image.Ptr, new Point(x, y), new MCvScalar(155), new MCvScalar(5), new MCvScalar(5), out comp, Emgu.CV.CvEnum.CONNECTIVITY.FOUR_CONNECTED, 0, IntPtr.Zero); //, out comp,Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT,mask.Ptr)
+        }
     }
 }

+ 2 - 2
bbiwarg/Main/OutputTest.cs

@@ -13,10 +13,10 @@ namespace bbiwarg.Main
     {
         static void Main(string[] args)
         {
-            IInputProvider inputProvider = new IisuInputProvider("..\\..\\videos\\1.skv");
+            IInputProvider inputProvider = new IisuInputProvider();//"..\\..\\videos\\4.skv");
             IVideoHandle videoHandle = new VideoHandle(inputProvider);
 
-            Output2D output = new Output2D(inputProvider);
+            Output2D output = new Output2D(videoHandle);
             output.Run(30);
         }
     }

+ 4 - 0
bbiwarg/VideoHandle/IVideoHandle.cs

@@ -4,6 +4,7 @@ using System.Drawing;
 using MathNet.Numerics.LinearAlgebra.Single;
 using bbiwarg.Detectors;
 using bbiwarg.InputProviders;
+using bbiwarg.Images;
 
 namespace bbiwarg.VideoHandles
 {
@@ -15,6 +16,9 @@ namespace bbiwarg.VideoHandles
         short getConfidence(int x, int y);
         Color getColor(int x, int y);
 
+        DepthImage getHand1Image();
+        DepthImage getHand2Image();
+
         // TODO: implement properly
         void createVertexArray(IntPtr vertexBuffer);
         Vector pixel2VertexPosition(Vector pixelPosition);

+ 46 - 1
bbiwarg/VideoHandle/VideoHandle.cs

@@ -8,20 +8,25 @@ using MathNet.Numerics.LinearAlgebra.Single;
 using bbiwarg.Images;
 using bbiwarg.InputProviders;
 using bbiwarg.Detectors;
+using bbiwarg.Helpers;
 
 namespace bbiwarg.VideoHandles
 {
     class VideoHandle : IVideoHandle
     {
+        private IInputProvider inputProvider;
+
         private ForeFingerDetection foreFingerDetection;
         private PalmDetection palmDetection;
 
-        private IInputProvider inputProvider;
         private DepthImage depthImage;
         private ConfidenceImage confidenceImage;
         private UVImage uvImage;
         private ColorImage colorImage;
 
+        private DepthImage hand1Image;
+        private DepthImage hand2Image;
+
         private float maxU;
         private float maxV;
 
@@ -72,6 +77,36 @@ namespace bbiwarg.VideoHandles
             confidenceImage = inputProvider.getConfidenceImage();
             uvImage = inputProvider.getUVImage();
             colorImage = inputProvider.getColorImage();
+
+            hand1Image = inputProvider.getDepthImage();
+            hand2Image = inputProvider.getDepthImage();
+
+            int maxHandSize = 150; // mm Wieviel Pixel sind das?
+
+            //hand1
+            Vector palm1Origin = inputProvider.getPalmPosition2D(1);
+            int palmX = (int)palm1Origin.x();
+            int palmY = (int)palm1Origin.y();
+            int palmDepth = depthImage.getDepth(palmX, palmY);
+
+            if (palmX != 0 && palmY != 0)
+            {
+                //hand1Image.floodFill(palmX, palmY);
+                hand1Image.thresholdDepth(palmDepth - 10, palmDepth + 30);
+                hand1Image.thresholdPosition(palmX - maxHandSize / 2, palmX + maxHandSize / 2, palmY - maxHandSize / 2, palmY + maxHandSize / 2);
+            }
+
+            //hand2
+            Vector palm2Origin = inputProvider.getPalmPosition2D(2);
+            palmX = (int)palm2Origin.x();
+            palmY = (int)palm2Origin.y();
+            palmDepth = depthImage.getDepth(palmX, palmY);
+
+            if (palmX != 0 && palmY != 0)
+            {
+                hand2Image.thresholdDepth(palmDepth - 10, palmDepth + 30);
+                hand2Image.thresholdPosition(palmX - maxHandSize / 2, palmX + maxHandSize / 2, palmY - maxHandSize / 2, palmY + maxHandSize / 2);
+            }
         }
 
         public short getDepth(int x, int y)
@@ -100,6 +135,16 @@ namespace bbiwarg.VideoHandles
             return colorImage.getColor(xInColorImage, yInColorImage);
         }
 
+        public DepthImage getHand1Image()
+        {
+            return hand1Image;
+        }
+
+        public DepthImage getHand2Image()
+        {
+            return hand2Image;
+        }
+
         public DetectionStatus[] getFingerStatus(uint handIndex)
         {
             return inputProvider.getFingerStatus(handIndex);