Example #1
0
 private void ProcessBodyFrame(MultiSourceFrame multiSourceFrame)
 {
     // Body
     using (var bodyIndexFrame = multiSourceFrame.BodyIndexFrameReference.AcquireFrame())
     {
         BodyIndexFrame frameBodyIndex = bodyIndexFrame;
         if (bodyIndexFrame != null && this.DepthMetaData != null)
         {
             this.BodyMetaData = new BodyMetaData(frameBodyIndex);
             ProcessDepthColorIR(multiSourceFrame);
         }
     }
 }
Example #2
0
        /// <summary>
        /// updates myDepthMetaData.FrameData
        /// </summary>
        /// <param name="myDepthMetaData"></param>
        /// <param name="myBodyMetaData"></param>
        public int DepthFrameData_RemoveBackground(DepthMetaData myDepthMetaData, BodyMetaData myBodyMetaData)
        {
            if (myBodyMetaData == null || myDepthMetaData == null)
            {
                return(-1);
            }
            int numberOfPixelsRemoved = 0;

            int nCount = myDepthMetaData.FrameData.GetLength(0);

            ushort[] myPixels = new ushort[nCount];

            for (int i = 0; i < nCount; i++)
            {
                myPixels[i] = myDepthMetaData.FrameData[i];
            }


            for (int x = 0; x < DepthMetaData.XDepthMaxKinect; ++x)
            {
                for (int y = 0; y < DepthMetaData.YDepthMaxKinect; ++y)
                {
                    int depthIndex = (y * DepthMetaData.XDepthMaxKinect) + x;

                    byte player = myBodyMetaData.Pixels[depthIndex];

                    if (player != 0xff)
                    {
                    }
                    else
                    {
                        myDepthMetaData.FrameData[depthIndex] = 0;
                        numberOfPixelsRemoved++;
                    }
                }
            }
            return(numberOfPixelsRemoved);
        }
Example #3
0
        public WriteableBitmap Color_Bitmap(ColorMetaData myColorMetaData, DepthMetaData myDepthMetaData, BodyMetaData myBodyMetaData)
        {
            if (myDepthMetaData == null || myBodyMetaData == null || myColorMetaData == null)
            {
                return(null);
            }


            /// <summary>
            /// The RGB pixel values used for the background removal (green-screen) effect.
            /// </summary>
            byte[]            myPixelsColorPlayer = null;
            ColorSpacePoint[] _colorPointsPlayer  = null;
            _colorPointsPlayer = new ColorSpacePoint[DepthMetaData.XDepthMaxKinect * DepthMetaData.YDepthMaxKinect];

            myPixelsColorPlayer = new byte[DepthMetaData.XDepthMaxKinect * DepthMetaData.YDepthMaxKinect * BYTES_PER_PIXEL];

            coordinateMapper.MapDepthFrameToColorSpace(myDepthMetaData.FrameData, _colorPointsPlayer);

            for (int x = 0; x < DepthMetaData.XDepthMaxKinect; ++x)
            {
                for (int y = 0; y < DepthMetaData.YDepthMaxKinect; ++y)
                {
                    int  depthIndex   = (y * DepthMetaData.XDepthMaxKinect) + x;
                    byte player       = myBodyMetaData.Pixels[depthIndex];
                    int  displayIndex = depthIndex * BYTES_PER_PIXEL;

                    if (player != 0xff)
                    {
                        ColorSpacePoint colorPoint = _colorPointsPlayer[depthIndex];

                        //int colorX = (int)Math.Floor(colorPoint.X + 0.5);
                        //int colorY = (int)Math.Floor(colorPoint.Y + 0.5);

                        //EDGAR TO DO _ player


                        if ((colorPoint.X >= 0) && (colorPoint.X < ColorMetaData.XColorMaxKinect) && (colorPoint.Y >= 0) && (colorPoint.Y < ColorMetaData.YColorMaxKinect))
                        {
                            int colorIndex = ((Convert.ToInt32(colorPoint.Y) * ColorMetaData.XColorMaxKinect) + Convert.ToInt32(colorPoint.X)) * BYTES_PER_PIXEL;


                            myPixelsColorPlayer[displayIndex + 0] = myColorMetaData.Pixels[colorIndex];
                            myPixelsColorPlayer[displayIndex + 1] = myColorMetaData.Pixels[colorIndex + 1];
                            myPixelsColorPlayer[displayIndex + 2] = myColorMetaData.Pixels[colorIndex + 2];
                            myPixelsColorPlayer[displayIndex + 3] = 0xff;
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        myPixelsColorPlayer[displayIndex + 3] = 0;//identify later....
                    }
                }
            }

            WriteableBitmap myBitmapColorPlayer = null;

            myBitmapColorPlayer = new WriteableBitmap(DepthMetaData.XDepthMaxKinect, DepthMetaData.XDepthMaxKinect, DPI, DPI, FORMAT, null);


            myBitmapColorPlayer.Lock();

            Marshal.Copy(myPixelsColorPlayer, 0, myBitmapColorPlayer.BackBuffer, myPixelsColorPlayer.Length);
            myBitmapColorPlayer.AddDirtyRect(new Int32Rect(0, 0, DepthMetaData.XDepthMaxKinect, DepthMetaData.YDepthMaxKinect));

            myBitmapColorPlayer.Unlock();

            return(myBitmapColorPlayer);
        }
Example #4
0
        public WriteableBitmap ColorBitmap2(ColorMetaData myColorMetaData, DepthMetaData myDepthMetaData, BodyMetaData myBodyMetaData)
        {
            if (myDepthMetaData == null || myBodyMetaData == null || myColorMetaData == null)
            {
                return(null);
            }
            this.colorArrayWithDepthInfo = new DepthSpacePoint[ColorMetaData.XColorMaxKinect * ColorMetaData.YColorMaxKinect];
            coordinateMapper.MapColorFrameToDepthSpace(myDepthMetaData.FrameData, this.colorArrayWithDepthInfo);

            if (colorArrayWithDepthInfo == null)
            {
                return(null);
            }

            this.colorArrayWithDepthInfo = new DepthSpacePoint[ColorMetaData.XColorMaxKinect * ColorMetaData.YColorMaxKinect];

            // Loop over each row and column of the color image
            // Zero out any pixels that don't correspond to a body index


            myColorMetaData.WriteableBitmapColor.Lock();

            unsafe
            {
                int colorMappedToDepthPointCount = this.colorArrayWithDepthInfo.Length;


                fixed(DepthSpacePoint *colorMappedToDepthPointsPointer = this.colorArrayWithDepthInfo)
                {
                    for (int colorIndex = 0; colorIndex < colorMappedToDepthPointCount; ++colorIndex)
                    {
                        double colorMappedToDepthX = colorMappedToDepthPointsPointer[colorIndex].X;
                        double colorMappedToDepthY = colorMappedToDepthPointsPointer[colorIndex].Y;


                        if (!double.IsNegativeInfinity(colorMappedToDepthX) &&
                            !double.IsNegativeInfinity(colorMappedToDepthY))
                        {
                            // Make sure the depth pixel maps to a valid point in color space
                            int depthX = (int)(colorMappedToDepthX + 0.5f);
                            int depthY = (int)(colorMappedToDepthY + 0.5f);

                            // If the point is not valid, there is no body index there.
                            if ((depthX >= 0) && (depthX < DepthMetaData.XDepthMaxKinect) && (depthY >= 0) && (depthY < DepthMetaData.YDepthMaxKinect))
                            {
                                int depthIndex = (depthY * DepthMetaData.XDepthMaxKinect) + depthX;

                                byte player = myBodyMetaData.Pixels[depthIndex];
                                if (player != 0xff)
                                {
                                    continue;
                                }
                            }
                        }

                        int displayIndex = colorIndex * BYTES_PER_PIXEL;

                        myColorMetaData.Pixels[colorIndex + 1] = 0;
                        myColorMetaData.Pixels[colorIndex + 2] = 0;
                        myColorMetaData.Pixels[colorIndex + 3] = 0xff;
                    }


                    myColorMetaData.WriteableBitmapColor.AddDirtyRect(new Int32Rect(0, 0, myColorMetaData.WriteableBitmapColor.PixelWidth, myColorMetaData.WriteableBitmapColor.PixelHeight));
                }
            }

            myColorMetaData.WriteableBitmapColor.Unlock();
            return(myColorMetaData.WriteableBitmapColor);

            //}
        }
Example #5
0
        public System.Drawing.Image Color_Image(ColorMetaData myColorMetaData, DepthMetaData myDepthMetaData, BodyMetaData myBodyMetaData)
        {
            WriteableBitmap myBitmapColorPlayer = Color_Bitmap(myColorMetaData, myDepthMetaData, myBodyMetaData);

            if (myBitmapColorPlayer != null)
            {
                return(myBitmapColorPlayer.ToImage());
            }
            else
            {
                return(null);
            }
        }
Example #6
0
        private static PointCloud PointCloudBW(CameraSpacePoint[] myRealWorldPoints, DepthMetaData myDepthMetaData, BodyMetaData myBodyMetaData)
        {
            int x = 0;
            int y = 0;
            // int indexVertex = 0;

            List <Vector3> list = new List <Vector3>();

            try
            {
                for (x = 0; x < DepthMetaData.XDepthMaxKinect; x++)
                {
                    for (y = 0; y < DepthMetaData.YDepthMaxKinect; y++)
                    {
                        int depthIndex = (y * DepthMetaData.XDepthMaxKinect) + x;
                        //int depthIndex = ((DepthMetaData.YResDefault - y - 1) * DepthMetaData.XResDefault) + x;

                        if (myDepthMetaData.FrameData[depthIndex] != 0)
                        {
                            int depthIndexColor = depthIndex * MetaDataBase.BYTES_PER_PIXEL;

                            Vector3 vect = new Vector3(myRealWorldPoints[depthIndex].X, myRealWorldPoints[depthIndex].Y, -myRealWorldPoints[depthIndex].Z);
                            list.Add(vect);
                        }
                    }
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("..Debug : " + x.ToString() + " : " + y.ToString() + " : ");
            }
            return(PointCloud.FromListVector3(list));
        }
Example #7
0
        private static PointCloud PointCloudWithColorParallel(ColorSpacePoint[] mycolorPointsInDepthSpace, CameraSpacePoint[] myRealWorldPoints, ColorMetaData myColorMetaData, DepthMetaData myDepthMetaData, BodyMetaData myBodyMetaData)
        {
            Vector3[,] arrV = new Vector3[DepthMetaData.XDepthMaxKinect, DepthMetaData.YDepthMaxKinect];
            Vector3[,] arrC = new Vector3[DepthMetaData.XDepthMaxKinect, DepthMetaData.YDepthMaxKinect];


            try
            {
                System.Threading.Tasks.Parallel.For(0, DepthMetaData.XDepthMaxKinect, x =>
                {
                    for (int y = 0; y < DepthMetaData.YDepthMaxKinect; y++)
                    {
                        int depthIndex = (y * DepthMetaData.XDepthMaxKinect) + x;

                        if (myDepthMetaData.FrameData[depthIndex] != 0)
                        {
                            if (PointCloudScannerSettings.BackgroundRemoved && myBodyMetaData != null)
                            {
                                byte player = myBodyMetaData.Pixels[depthIndex];
                                if (player != 0xff)
                                {
                                    SetPoint(depthIndex, x, y, arrV, arrC, mycolorPointsInDepthSpace, myRealWorldPoints, myColorMetaData);
                                }
                            }
                            else
                            {
                                SetPoint(depthIndex, x, y, arrV, arrC, mycolorPointsInDepthSpace, myRealWorldPoints, myColorMetaData);
                            }
                        }
                    }
                });
                //};
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(" error in PointCloudWithColor " + err.Message);
            }

            List <Vector3> listV = new List <Vector3>();
            List <Vector3> listC = new List <Vector3>();


            for (int x = 0; x < DepthMetaData.XDepthMaxKinect; x++)
            {
                for (int y = 0; y < DepthMetaData.YDepthMaxKinect; y++)
                {
                    if (arrV[x, y] != Vector3.Zero)
                    {
                        listV.Add(arrV[x, y]);
                        listC.Add(arrC[x, y]);
                    }
                }
            }

            PointCloud pc = new PointCloud(listV, listC, null, null, null, null);

            if (GLSettings.ShowPointCloudAsTexture)
            {
                pc.TextureCreateFromColors(DepthMetaData.XDepthMaxKinect, DepthMetaData.YDepthMaxKinect);
            }
            return(pc);
        }
Example #8
0
        /// <summary>
        /// creates color info for all DEPTH pixels (to later e.g. write ply file from it)
        /// </summary>
        /// <param name="myColorMetaData"></param>
        /// <param name="myDepthMetaData"></param>
        /// <param name="myCoordinateMapper"></param>
        /// <returns></returns>
        public static PointCloud ToPointCloud(ColorMetaData myColorMetaData, DepthMetaData myDepthMetaData, BodyMetaData myBodyMetaData, CoordinateMapper myCoordinateMapper)
        {
            if (myColorMetaData == null && myDepthMetaData == null)
            {
                return(null);
            }

            ColorSpacePoint[]  mycolorPointsInDepthSpace = new ColorSpacePoint[DepthMetaData.XDepthMaxKinect * DepthMetaData.YDepthMaxKinect];
            CameraSpacePoint[] myRealWorldPoints         = new CameraSpacePoint[DepthMetaData.XDepthMaxKinect * DepthMetaData.YDepthMaxKinect];
            myCoordinateMapper.MapDepthFrameToCameraSpace(myDepthMetaData.FrameData, myRealWorldPoints);
            myCoordinateMapper.MapDepthFrameToColorSpace(myDepthMetaData.FrameData, mycolorPointsInDepthSpace);


            if (myColorMetaData != null)
            {
                return(PointCloudWithColorParallel(mycolorPointsInDepthSpace, myRealWorldPoints, myColorMetaData, myDepthMetaData, myBodyMetaData));
            }
            else
            {
                return(PointCloudBW(myRealWorldPoints, myDepthMetaData, myBodyMetaData));
            }
        }