Exemplo n.º 1
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 byte[] ColorInfoForDepth(ColorMetaData myColorMetaData, DepthMetaData myDepthMetaData, CoordinateMapper myCoordinateMapper)
        {
            //Test_GetCameraPoints(myDepthMetaData, myCoordinateMapper);

            byte[] mydisplayPixels = new byte[DepthMetaData.XDepthMaxKinect * DepthMetaData.YDepthMaxKinect * MetaDataBase.BYTES_PER_PIXEL];
            //mapped data
            int numberOfPoints  = 0;
            int notMappedPixels = -1;

            if (myColorMetaData != null)
            {
                ColorSpacePoint[] mycolorPointsInDepthSpace = new ColorSpacePoint[DepthMetaData.XDepthMaxKinect * DepthMetaData.YDepthMaxKinect];

                myCoordinateMapper.MapDepthFrameToColorSpace(myDepthMetaData.FrameData, mycolorPointsInDepthSpace);


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

                        if (myDepthMetaData.FrameData[depthIndex] != 0)
                        {
                            ColorSpacePoint colorPoint = mycolorPointsInDepthSpace[depthIndex];


                            int xColor          = Convert.ToInt32(colorPoint.X);
                            int yColor          = Convert.ToInt32(colorPoint.Y);
                            int depthIndexColor = depthIndex * MetaDataBase.BYTES_PER_PIXEL;

                            if ((xColor >= 0) && (xColor < ColorMetaData.XColorMaxKinect) && (yColor >= 0) && (yColor < ColorMetaData.YColorMaxKinect))
                            {
                                int colorIndex = ((yColor * ColorMetaData.XColorMaxKinect) + xColor) * MetaDataBase.BYTES_PER_PIXEL;

                                mydisplayPixels[depthIndexColor + 0] = myColorMetaData.Pixels[colorIndex];
                                mydisplayPixels[depthIndexColor + 1] = myColorMetaData.Pixels[colorIndex + 1];
                                mydisplayPixels[depthIndexColor + 2] = myColorMetaData.Pixels[colorIndex + 2];
                                mydisplayPixels[depthIndexColor + 3] = 0xff;
                                numberOfPoints++;
                            }
                            else
                            {
                                notMappedPixels++;
                                mydisplayPixels[depthIndexColor + 0] = 255;
                                mydisplayPixels[depthIndexColor + 1] = 255;
                                mydisplayPixels[depthIndexColor + 2] = 255;
                                mydisplayPixels[depthIndexColor + 3] = 0xff;
                            }
                        }
                    }
                }
            }
            //System.Diagnostics.Debug.WriteLine("---------> Number of Depth points: " + numberOfPoints.ToString());


            return(mydisplayPixels);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
        //private static PointCloud PointCloudWithColorParallel(ColorSpacePoint[] mycolorPointsInDepthSpace, CameraSpacePoint[] myRealWorldPoints, ColorMetaData myColorMetaData, DepthMetaData myDepthMetaData, BodyMetaData myBodyMetaData)
        //{

        //    VectorColor[,] arrVectors = Helper_CreateArray(mycolorPointsInDepthSpace, myRealWorldPoints, myColorMetaData, myDepthMetaData);
        //    PointCloud pc = new PointCloud();
        //    List<Vector3> vecList = new List<Vector3>();
        //    List<Vector3> colList = new List<Vector3>();


        //    int indV = -1;
        //    for (int x = 0; x < DepthMetaData.XDepthMaxKinect; x++)
        //    {
        //        for (int y = 0; y < DepthMetaData.YDepthMaxKinect; y++)
        //        {
        //            indV++;
        //            if (arrVectors[x, y].Vector != Vector3.Zero)
        //            {
        //                vecList.Add(arrVectors[x, y].Vector);
        //                colList.Add(arrVectors[x, y].Color);


        //            }


        //        }
        //    }

        //    pc.Vectors = vecList.ToArray();
        //    pc.Colors = colList.ToArray();



        //    return pc;
        //}
        private static VectorColor[,] Helper_CreateArray(ColorSpacePoint[] mycolorPointsInDepthSpace, CameraSpacePoint[] myRealWorldPoints, ColorMetaData myColorMetaData, DepthMetaData myDepthMetaData)
        {
            VectorColor[,] arrVectors = new VectorColor[DepthMetaData.XDepthMaxKinect, DepthMetaData.YDepthMaxKinect];

            try
            {
                //for (int x = 0; x < DepthMetaData.XResDefault; x++)
                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)
                        {
                            ColorSpacePoint colorPoint = mycolorPointsInDepthSpace[depthIndex];


                            int xColor          = Convert.ToInt32(colorPoint.X);
                            int yColor          = Convert.ToInt32(colorPoint.Y);
                            int depthIndexColor = depthIndex * MetaDataBase.BYTES_PER_PIXEL;

                            if ((xColor >= 0) && (xColor < ColorMetaData.XColorMaxKinect) && (yColor >= 0) && (yColor < ColorMetaData.YColorMaxKinect))
                            {
                                int colorIndex          = ((yColor * ColorMetaData.XColorMaxKinect) + xColor) * MetaDataBase.BYTES_PER_PIXEL;
                                Vector3 vect            = new Vector3(myRealWorldPoints[depthIndex].X, myRealWorldPoints[depthIndex].Y, myRealWorldPoints[depthIndex].Z);
                                Vector3 col             = new Vector3(myColorMetaData.Pixels[colorIndex] / 255f, myColorMetaData.Pixels[colorIndex + 1] / 255f, myColorMetaData.Pixels[colorIndex + 2] / 255f);
                                arrVectors[x, y].Vector = vect;

                                arrVectors[x, y].Color = col;
                            }
                        }
                    }
                });
                //};
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(" error in PointCloudWithColor " + err.Message);
            }

            return(arrVectors);
        }
Exemplo n.º 5
0
        private static PointCloud PointCloudWithColorParallel_AllPoints(ColorSpacePoint[] mycolorPointsInDepthSpace, CameraSpacePoint[] myRealWorldPoints, ColorMetaData myColorMetaData, DepthMetaData myDepthMetaData)
        {
            VectorColor[,] arrVectors = Helper_CreateArray_AllPoints(mycolorPointsInDepthSpace, myRealWorldPoints, myColorMetaData, myDepthMetaData);
            PointCloud pc = new PointCloud();

            pc.Vectors = new Vector3[arrVectors.Length];
            pc.Colors  = new Vector3[arrVectors.Length];

            int indV = -1;

            for (int x = 0; x < DepthMetaData.XDepthMaxKinect; x++)
            {
                for (int y = 0; y < DepthMetaData.YDepthMaxKinect; y++)
                {
                    indV++;
                    pc.Vectors[indV] = arrVectors[x, y].Vector;
                    pc.Colors[indV]  = arrVectors[x, y].Color;
                }
            }


            return(pc);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);

            //}
        }
Exemplo n.º 8
0
        private static void SetPoint(int depthIndex, int x, int y, Vector3[,] arrV, Vector3[,] arrC, ColorSpacePoint[] mycolorPointsInDepthSpace, CameraSpacePoint[] myRealWorldPoints, ColorMetaData myColorMetaData)
        {
            ColorSpacePoint colorPoint = mycolorPointsInDepthSpace[depthIndex];


            int xColor          = Convert.ToInt32(colorPoint.X);
            int yColor          = Convert.ToInt32(colorPoint.Y);
            int depthIndexColor = depthIndex * MetaDataBase.BYTES_PER_PIXEL;

            if ((xColor >= 0) && (xColor < ColorMetaData.XColorMaxKinect) && (yColor >= 0) && (yColor < ColorMetaData.YColorMaxKinect))
            {
                int     colorIndex = ((yColor * ColorMetaData.XColorMaxKinect) + xColor) * MetaDataBase.BYTES_PER_PIXEL;
                Vector3 vect       = new Vector3(myRealWorldPoints[depthIndex].X, myRealWorldPoints[depthIndex].Y, myRealWorldPoints[depthIndex].Z);
                Vector3 col        = new Vector3(myColorMetaData.Pixels[colorIndex + 2] / 255f, myColorMetaData.Pixels[colorIndex + 1] / 255f, myColorMetaData.Pixels[colorIndex] / 255f);

                //System.Drawing.Color c = System.Drawing.Color.FromArgb(myColorMetaData.Pixels[colorIndex + 3], myColorMetaData.Pixels[colorIndex + 2], myColorMetaData.Pixels[colorIndex + 1], myColorMetaData.Pixels[colorIndex]);

                //Vertex v = new Vertex(0, vect, c);
                arrV[x, y] = vect;

                arrC[x, y] = col;
            }
        }
Exemplo n.º 9
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);
        }