Browse Source

added confidenceImage

Alexander Hendrich 10 năm trước cách đây
mục cha
commit
f8a806ee4d

+ 8 - 5
bbiwarg/Constants.cs

@@ -10,7 +10,14 @@ namespace bbiwarg
     class Constants
     {
         // BBIWARG
-        public static readonly bool TimerOutputAll = true;
+        public static readonly bool OutputTimerEnabled = true;
+        public static readonly int OutputNumImages = 5;
+        public static readonly int OutputNumImagesPerRow = 3;
+        public static readonly float OutputScaleFactor = 1f; // output window size is scaled by this factor (from necessary size for images)
+
+
+        // confidence image
+        public static readonly int ConfidenceImageMinThreshold = 500;
 
         // depth image
         public static readonly int DepthImageMedianSize = 3;
@@ -57,10 +64,6 @@ namespace bbiwarg
         public static readonly int TouchEventAreaSize = 30;
         public static readonly int TouchEventNumFramesUntilTracked = 2;
 
-        // output window
-        public static readonly int NumImagesPerRow = 3;
-        public static readonly float WindwoSizeFactor = 1f; // output window size is scaled by this factor (from necessary size for images)
-
 
 
 

+ 7 - 7
bbiwarg/Graphics/OutputWindow.cs

@@ -25,8 +25,8 @@ namespace bbiwarg.Graphics
         private Stopwatch watch;
 
         public OutputWindow(VideoHandle videoHandle)
-            : base((int) (Constants.WindwoSizeFactor * Math.Max(1, Math.Min(Constants.NumImagesPerRow, videoHandle.OutputImages.Length)) * videoHandle.Width), 
-                   (int) (Constants.WindwoSizeFactor * (1 + (videoHandle.OutputImages.Length - 1) / Constants.NumImagesPerRow) * videoHandle.Height))
+            : base((int) (Constants.OutputScaleFactor * Math.Max(1, Math.Min(Constants.OutputNumImagesPerRow, videoHandle.OutputImages.Length)) * videoHandle.Width), 
+                   (int) (Constants.OutputScaleFactor * (1 + (videoHandle.OutputImages.Length - 1) / Constants.OutputNumImagesPerRow) * videoHandle.Height))
         {
             this.videoHandle = videoHandle;
             watch = new Stopwatch();
@@ -67,8 +67,8 @@ namespace bbiwarg.Graphics
             float imageAspectRatio = (float)imageWidth / (float)imageHeight;
 
             int numImages = videoHandle.OutputImages.Length;
-            int numRows = 1 + (numImages - 1) / Constants.NumImagesPerRow;
-            int numCols = Math.Min(videoHandle.OutputImages.Length, Constants.NumImagesPerRow);
+            int numRows = 1 + (numImages - 1) / Constants.OutputNumImagesPerRow;
+            int numCols = Math.Min(videoHandle.OutputImages.Length, Constants.OutputNumImagesPerRow);
             int heightForWidth = (int)((float)screenWidth / ((float)numCols * imageAspectRatio) * (float)numRows);
             
             GL.Viewport(0, (screenHeight - heightForWidth) / 2, screenWidth, heightForWidth);
@@ -143,8 +143,8 @@ namespace bbiwarg.Graphics
             int imageIndex = 0;
             foreach (OutputImage image in videoHandle.OutputImages)
             {
-                int x = imageIndex % Constants.NumImagesPerRow;
-                int y = imageIndex / Constants.NumImagesPerRow;
+                int x = imageIndex % Constants.OutputNumImagesPerRow;
+                int y = imageIndex / Constants.OutputNumImagesPerRow;
                 GL.BindTexture(TextureTarget.Texture2D, textureId);
                 GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, videoHandle.Width, videoHandle.Height, 0, PixelFormat.Rgb, PixelType.UnsignedByte, image.Image.MIplImage.imageData);
                 GL.Begin(PrimitiveType.Quads);
@@ -165,7 +165,7 @@ namespace bbiwarg.Graphics
 
             Timer.stop("onRenderFrame");
             
-            if(Constants.TimerOutputAll)
+            if(Constants.OutputTimerEnabled)
                 Timer.outputAll();
         }
 

+ 26 - 0
bbiwarg/Images/ConfidenceImage.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using bbiwarg.Images;
+using bbiwarg.Graphics;
+using Emgu.CV;
+using Emgu.CV.Structure;
+
+namespace bbiwarg.Images
+{
+    class ConfidenceImage
+    {
+        public Image<Gray, Int16> Image { get; private set; }
+        public Image<Gray, byte> Mask { get; private set; }
+        private OutputImage outputImage;
+
+        public ConfidenceImage(Image<Gray, Int16> image)
+        {
+            Image = image;
+
+            Mask = (Image.ThresholdBinary(new Gray(Constants.ConfidenceImageMinThreshold), new Gray(1))).Convert<Gray, byte>();
+        }
+    }
+}

+ 1 - 4
bbiwarg/Images/DepthImage.cs

@@ -15,7 +15,6 @@ namespace bbiwarg.Images
 {
     class DepthImage
     {
-        private OutputImage outputImage;
         public Image<Gray, byte> Image { get; private set; }
         public Image<Gray, byte> BackgroundMask { get; private set; }
         public int Width { get; private set; }
@@ -23,10 +22,8 @@ namespace bbiwarg.Images
         public Int16 MinDepth { get; private set; }
         public Int16 MaxDepth { get; private set; }
 
-        public DepthImage(Image<Gray, Int16> image, OutputImage outputImage)
+        public DepthImage(Image<Gray, Int16> image)
         {
-            this.outputImage = outputImage;
-
             Width = image.Width;
             Height = image.Height;
 

+ 4 - 5
bbiwarg/InputProvider/IisuInputProvider.cs

@@ -24,6 +24,7 @@ namespace bbiwarg.InputProviders
 
         //data
         private IDataHandle<Iisu.Data.IImageData> depthImage;
+        private IDataHandle<Iisu.Data.IImageData> confidenceImage;
 
         public IisuInputProvider(String moviePath = "")
         {
@@ -60,10 +61,6 @@ namespace bbiwarg.InputProviders
                 playStep = device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayStep");
                 currentMovieFrame = device.RegisterParameterHandle<int>("SOURCE.MOVIE.CurrentFrame");
             }
-            else
-            {
-                device.RegisterParameterHandle<int>("SOURCE.DEPTHSENSE.AmplitudeThreshold").Value = 100; // confidence-threshhold
-            }
 
             frameRate = device.RegisterParameterHandle<float>("SOURCE.FrameRate");
             hfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.HFOV");
@@ -74,6 +71,7 @@ namespace bbiwarg.InputProviders
 
             // data
             depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
+            confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
         }
 
         private void onDeviceStatusChanged(string eventName, DeviceStatus status)
@@ -131,8 +129,9 @@ namespace bbiwarg.InputProviders
             int width = (int)imageInfos.Width;
             int height = (int)imageInfos.Height;
             IntPtr rawDepthData = depthImage.Value.Raw;
+            IntPtr rawConfidenceData = confidenceImage.Value.Raw;
 
-            return new InputFrame(width, height, rawDepthData);
+            return new InputFrame(width, height, rawDepthData, rawConfidenceData);
         }
 
         // other

+ 3 - 1
bbiwarg/InputProvider/InputFrame.cs

@@ -14,11 +14,13 @@ namespace bbiwarg.InputProviders
         public int Width { get; private set; }
         public int Height { get; private set; }
         public IntPtr RawDepthData { get; private set; }
+        public IntPtr RawConfidenceData { get; private set; }
 
-        public InputFrame(int width, int height, IntPtr rawDepthData) {
+        public InputFrame(int width, int height, IntPtr rawDepthData, IntPtr rawConfidenceData) {
             this.Width = width;
             this.Height = height;
             this.RawDepthData = rawDepthData;
+            this.RawConfidenceData = rawConfidenceData;
         }
     }
 }

+ 15 - 9
bbiwarg/VideoHandle.cs

@@ -42,6 +42,7 @@ namespace bbiwarg
         
         private DepthImage depthImage;
         private EdgeImage edgeImage;
+        private ConfidenceImage confidenceImage;
         
         private FingerDetector fingerDetector;
         private HandDetector handDetector;
@@ -133,20 +134,25 @@ namespace bbiwarg
 
             //create output images
             Timer.start("createOutputImages");
-            int numImages = 5;
-            OutputImages = new OutputImage[numImages];
-            for (int i = 0; i < numImages; i++) {
+            OutputImages = new OutputImage[Constants.OutputNumImages];
+            for (int i = 0; i < Constants.OutputNumImages; i++) {
                 OutputImages[i] = new OutputImage(Width, Height);
                     
             }
             Timer.stop("createOutputImages");
 
+            //create confidenceImage
+            Timer.start("createConfidenceImage");
+            Image<Gray, Int16> rawConfidenceImage = new Image<Gray, Int16>(Width, Height, Width * 2, inputFrame.RawConfidenceData);
+            confidenceImage = new ConfidenceImage(rawConfidenceImage);
+            Timer.stop("createConfidenceImage");
+
             //create depthImage
             Timer.start("createDepthImage");
-            Image<Gray, Int16> image = new Image<Gray, Int16>(Width, Height, Width * 2, inputFrame.RawDepthData);
-            depthImage = new DepthImage(image, OutputImages[0]);
-            Image<Gray, byte> tmpDepth = (depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image;
-            OutputImages[0].Image[0] = OutputImages[0].Image[1] = OutputImages[0].Image[2] = tmpDepth;
+            Image<Gray, Int16> rawDepthImage = new Image<Gray, Int16>(Width, Height, Width * 2, inputFrame.RawDepthData);
+            rawDepthImage = rawDepthImage.Or((1 - confidenceImage.Mask).Convert<Gray, Int16>().Mul(Int16.MaxValue));
+            depthImage = new DepthImage(rawDepthImage);
+            OutputImages[0].Image[0] = OutputImages[0].Image[1] = OutputImages[0].Image[2] = (depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image;
             Timer.stop("createDepthImage");
 
             // create edge image
@@ -208,13 +214,13 @@ namespace bbiwarg
             }
 
             // add borders
-            for (int i = 0; i < numImages; i++)
+            for (int i = 0; i < Constants.OutputNumImages; i++)
             {
                 OutputImages[i].drawRectangle(0, 0, Width - 1, Height - 1, Color.White);
 
             }
 
-            OutputImages = new OutputImage[] {OutputImages[0], OutputImages[1], OutputImages[2], OutputImages[3], OutputImages[4]};
+            //OutputImages = new OutputImage[] {OutputImages[0], OutputImages[1], OutputImages[2], OutputImages[3], OutputImages[4]};
             
             //palmDetector.i1, palmDetector.i2, palmDetector.i3, palmDetector.i5, palmDetector.i6, palmDetector.i7, palmDetector.i8, palmDetector.i9};
 

+ 1 - 0
bbiwarg/bbiwarg.csproj

@@ -82,6 +82,7 @@
     <Compile Include="Detectors\TouchDetection\TouchTracker.cs" />
     <Compile Include="Graphics\OutputWindow.cs" />
     <Compile Include="Graphics\TouchEventVisualizer.cs" />
+    <Compile Include="Images\ConfidenceImage.cs" />
     <Compile Include="Images\DepthImage.cs" />
     <Compile Include="Images\EdgeImage.cs" />
     <Compile Include="Graphics\OutputImage.cs" />