public VisionImage ProcessImage(Bitmap bmp, ToteDetectionType detectionType, bool detectBins, DepthMap depthMap = null)
        {
            LastDepthMap = depthMap;

            //processing depth image
            Bitmap processedBitmap = (Bitmap)ProcessColorImage(bmp, detectionType, detectBins);
            return new VisionImage(processedBitmap, depthMap);

        }
        protected void stream_NewDepthFrame(object sender, Bitmap colorImage, DepthMap depthMap)
        {
            //Restart The Stopwatch To Calculate How Much Time Does It Take To Process The Image
            delayStopWatch.Restart();

            Image depthImage = depthMap.GetImage();
            Thread.Sleep(20);
            OriginalCurrentFrame = new VisionImage(colorImage, depthMap);
            ProccessedCurrentFrame = imgProcessor.ProcessImage((Bitmap)OriginalCurrentFrame.colorImage.Clone(), ToteDetectionMethod, detectBins, OriginalCurrentFrame.depthMap.Copy());

            updateGuiFunction(OriginalCurrentFrame.colorImage, ProccessedCurrentFrame.colorImage,
                depthImage);

            newData = true;
            fpsCounter++;
            delayStopWatch.Stop();
            delayCounter += (int)delayStopWatch.ElapsedMilliseconds;
        }
 public VisionImage(Image colorImage, DepthMap depthMap)
 {
     this.colorImage = colorImage;
     this.depthMap = depthMap;
 }
        private DepthMap SliceVisionImage(DepthImageFrame image, int min = MinDepthDistance, int max = MaxDepthDistance)
        {
            int width = image.Width;
            int height = image.Height;

            //var depthFrame = image.Image.Bits;
            short[] rawDepthData = new short[image.PixelDataLength];

            image.CopyPixelDataTo(rawDepthData);

            var pixels = new byte[height * width * 4];
            int usage = 0;
            const int BlueIndex = 0;
            const int GreenIndex = 1;
            const int RedIndex = 2;
            for (int depthIndex = 0, colorIndex = 0;
                depthIndex < rawDepthData.Length && colorIndex < pixels.Length;
                depthIndex++, colorIndex += 4)
            {

                // Calculate the distance represented by the two depth bytes
                int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;
                if (depthIndex == rawDepthData.Length - 1)
                {
                    usage = depth;
                }
                // Map the distance to an intesity that can be represented in RGB

                if (depth > min && depth < max)
                {
                    // Apply the intensity to the color channels
                    pixels[colorIndex + BlueIndex] =  this.CalculateIntensityFromDistance(depth); //blue - depth precentage out of 255. 255 - 800mm 0 - 4000mm
                    pixels[colorIndex + GreenIndex] = (byte)(255 - ((depth & 0x000FF0) / 0x000010)); //green - depth divided by 16, used to save the depth
                    pixels[colorIndex + RedIndex] = (byte)((depth & 0x00000F) / 0x000001); //red                    
                }
            }

            BitmapSource src = BitmapSource.Create(width, height, 96, 96, PixelFormats.Bgr32, null, pixels, width * 4);
            DepthMap map = new DepthMap(BitmapFromSource(src));
            return map;

        }
 public DepthMap Copy()
 {
     DepthMap copy = new DepthMap(depthMap);
     return copy;
 }