Exemple #1
0
        void UpdatePlayerDepthImage(short[] depthFrame, Byte[, ,] playerMask, Byte[, ,] skinMask,
                                    Rectangle roi)
        {
            // Clear depth image.
            CvInvoke.cvZero(DepthImage.Ptr);
            var data = DepthImage.Data;

            var scale = (float)255 / HandInputParams.MaxDepth;

            var roiWidth  = width;
            var roiHeight = height;

            if (!roi.IsEmpty)
            {
                roiWidth  = roi.Width;
                roiHeight = roi.Height;
            }
            for (int r = roi.Top; r < roi.Top + roiHeight; r++)
            {
                for (int c = roi.Left; c < roi.Left + roiWidth; c++)
                {
                    var   index = r * width + c;
                    short pixel = depthFrame[index];
                    var   depth = DepthUtil.RawToDepth(pixel);
                    if (IsFilteredPixel(playerMask, skinMask, c, r, depth))
                    {
                        data[r, c, 0] = (byte)(Math.Max(0, HandInputParams.MaxDepth - depth) * scale);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="depthImg"></param>
        /// <param name="colorImg">The aligned color image has the same ROI as the depth image.</param>
        /// <param name="depthFrame"></param>
        /// <param name="mapper"></param>
        public static void AlignImageDepthToColor(Image <Gray, Byte> depthImg,
                                                  Image <Gray, Byte> colorImg, short[] depthFrame, CoordinateConverter mapper)
        {
            var width  = colorImg.Width;
            var height = colorImg.Height;

            CvInvoke.cvZero(colorImg.Ptr);
            var depthData  = depthImg.Data;
            var colorData  = colorImg.Data;
            var roiWidth   = width;
            var roidHeight = height;
            var roi        = depthImg.ROI;

            if (!roi.IsEmpty)
            {
                roiWidth   = roi.Width;
                roidHeight = roi.Height;
            }
            for (int r = roi.Top; r < roi.Top + roidHeight; r++)
            {
                for (int c = roi.Left; c < roi.Left + roiWidth; c++)
                {
                    var depthPixel = depthFrame[r * width + c];
                    var depth      = DepthUtil.RawToDepth(depthPixel);
                    var cp         = mapper.MapDepthPointToColorPoint(c, r, depth);
                    if (cp.X >= 0 && cp.X < width && cp.Y >= 0 && cp.Y < height)
                    {
                        colorData[cp.Y, cp.X, 0] = depthData[r, c, 0];
                    }
                }
            }
            CvInvoke.cvMorphologyEx(colorImg.Ptr, colorImg.Ptr, IntPtr.Zero, IntPtr.Zero,
                                    CV_MORPH_OP.CV_MOP_CLOSE, 1);
        }
Exemple #3
0
 public static Image <Gray, Single> CreateCVImage(short[] src, Single[, ,] dst, int width,
                                                  int height)
 {
     for (int r = 0; r < height; r++)
     {
         for (int c = 0; c < width; c++)
         {
             dst[r, c, 0] = DepthUtil.RawToDepth(src[r * width + c]);
         }
     }
     return(new Image <Gray, Single>(dst));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="depthRect"></param>
        /// <param name="depthPixel"></param>
        /// <param name="width">frame width</param>
        /// <param name="height">frame height</param>
        /// <returns></returns>
        public Rectangle MapDepthRectToColorRect(Rectangle depthRect, short[] depthPixel, int width,
                                                 int height)
        {
            var y           = Clip(depthRect.Top, 0, height - 1);
            var x           = Clip(depthRect.Left, 0, width - 1);
            int depth       = DepthUtil.RawToDepth(depthPixel[y * width + x]);
            var cpUpperLeft = MapDepthPointToColorPoint(depthRect.X, depthRect.Y, depth);

            y     = Clip(depthRect.Bottom, 0, height - 1);
            x     = Clip(depthRect.Right, 0, width - 1);
            depth = DepthUtil.RawToDepth(depthPixel[y * width + x]);
            var cpBottomRight = MapDepthPointToColorPoint(depthRect.Right, depthRect.Bottom, depth);

            return(new Rectangle(cpUpperLeft.X, cpUpperLeft.Y, cpBottomRight.X - cpUpperLeft.X,
                                 cpBottomRight.Y - cpUpperLeft.Y));
        }
Exemple #5
0
        public static void ColorPlayers(short[] depthFrame, byte[] colorFrame)
        {
            Array.Clear(colorFrame, 0, colorFrame.Length);
            for (int depthIndex = 0, colorIndex = 0; colorIndex < colorFrame.Length; depthIndex++,
                 colorIndex += Bgr32BytesPerPixel)
            {
                short pixel  = depthFrame[depthIndex];
                int   player = DepthUtil.RawToPlayerIndex(pixel);

                if (player != 0)
                {
                    colorFrame[colorIndex + RedIndex]   = 0xff;
                    colorFrame[colorIndex + GreenIndex] = 0;
                    colorFrame[colorIndex + BlueIndex]  = 0;
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Updates player depth image using the player contour.
        /// </summary>
        /// <param name="depthFrame"></param>
        /// <param name="contour"></param>
        /// <param name="skinMask"></param>
        void UpdatePlayerDepthImage(short[] depthFrame, Seq <Point> contour, Byte[, ,] skinMask)
        {
            CvInvoke.cvZero(DepthImage.Ptr);
            var data = DepthImage.Data;

            var scale = (float)255 / HandInputParams.MaxDepth;

            for (int r = 0; r < height; r++)
            {
                for (int c = 0; c < width; c++)
                {
                    var   index = r * width + c;
                    short pixel = depthFrame[index];
                    var   depth = DepthUtil.RawToDepth(pixel);
                    if (IsPlayerPixel(contour, skinMask, c, r, depth))
                    {
                        data[r, c, 0] = (byte)(Math.Max(0, HandInputParams.MaxDepth - depth) * scale);
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Updates depth player masks.
        /// </summary>
        /// <param name="depthFrame"></param>
        void UpdatePlayerMask(short[] depthFrame)
        {
            CvInvoke.cvZero(DepthPlayerMask.Ptr);
            var data = DepthPlayerMask.Data;

            for (int r = 0; r < height; r++)
            {
                for (int c = 0; c < width; c++)
                {
                    var   index       = r * width + c;
                    short pixel       = depthFrame[index];
                    int   playerIndex = DepthUtil.RawToPlayerIndex(pixel);
                    if (playerIndex > 0)
                    {
                        data[r, c, 0] = 255;
                    }
                }
            }

            CvInvoke.cvMorphologyEx(DepthPlayerMask.Ptr, DepthPlayerMask.Ptr,
                                    IntPtr.Zero, IntPtr.Zero, CV_MORPH_OP.CV_MOP_OPEN, CvOpenIter);
        }