Esempio n. 1
0
 /// <summary>
 /// 深度情報を取得
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void getDepthFrameInfo()
 {
     using (DepthImageFrame dFrame = kinect.DepthStream.OpenNextFrame(1))
     {
         if (dFrame != null)
         {
             CoordinateMapper mapper = new CoordinateMapper(kinect);
             DepthData = new SkeletonPoint[dFrame.PixelDataLength];
             DepthImagePixel[] depthData = new DepthImagePixel[dFrame.PixelDataLength];
             dFrame.CopyDepthImagePixelDataTo(depthData);
             mapper.MapDepthFrameToSkeletonFrame(DepthImageFormat.Resolution640x480Fps30, depthData, DepthData);
         }
     }
 }
Esempio n. 2
0
        //Event Kinect New Frame
        void AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            int          index  = Array.IndexOf(this.sensors, (KinectSensor)sender);
            KinectSensor sensor = (KinectSensor)sender;
            //Console.WriteLine("Sensor" + index + " fired.");

            // Grab frames from stream
            DepthImageFrame imageDepthFrame    = e.OpenDepthImageFrame();
            ColorImageFrame imageColorFrame    = e.OpenColorImageFrame();
            SkeletonFrame   imageSkeletonFrame = e.OpenSkeletonFrame();

            if (imageDepthFrame != null && (!colorOn || imageColorFrame != null) && imageSkeletonFrame != null && Semaphore.glControlLoaded)
            {
                CoordinateMapper  mapper         = new CoordinateMapper(sensor);
                SkeletonPoint[]   skeletonPoints = new SkeletonPoint[imageDepthFrame.PixelDataLength];
                DepthImagePixel[] depthPixels    = new DepthImagePixel[imageDepthFrame.PixelDataLength];

                // Copy the pixel data from the image to a temporary array
                imageDepthFrame.CopyDepthImagePixelDataTo(depthPixels);

                // Map Depth data to Skeleton points.
                // skeletonPoints is being changed as a result of this function call
                mapper.MapDepthFrameToSkeletonFrame(DEPTH_IMAGE_FORMAT, depthPixels, skeletonPoints);

                short[,] vertexData;
                if (colorOn)
                {
                    //Allocate array for color data
                    pixelColorData = new byte[sensor.ColorStream.FramePixelDataLength];
                    imageColorFrame.CopyPixelDataTo(pixelColorData);
                    // Adjust coordinates of skeleton points according to the colour format
                    // skeletonPoints is being changed as a result of this function call
                    mapper.MapColorFrameToSkeletonFrame(COLOR_IMAGE_FORMAT, DEPTH_IMAGE_FORMAT, depthPixels, skeletonPoints);
                    vertexData = new short[(frameHeight * frameWidth), 6];
                }
                else
                {
                    vertexData = new short[(frameHeight * frameWidth), 3];
                }

                // Convert SkeletonPoints data into short[][]
                // [x, y, z, Blue, Green, Red]

                int i = 0;
                for (int row = 0; row < frameHeight * frameWidth; row++)
                {
                    vertexData[row, 0] = (short)(skeletonPoints[row].X * 1000); //Store for X
                    vertexData[row, 1] = (short)(skeletonPoints[row].Y * 1000); //Store for Y
                    vertexData[row, 2] = (short)(skeletonPoints[row].Z * 1000); //Store for Z
                    if (colorOn)
                    {
                        vertexData[row, 3] = (short)pixelColorData[i + 2];
                        vertexData[row, 4] = (short)pixelColorData[i + 1];
                        vertexData[row, 5] = (short)pixelColorData[i];
                        i += 4;
                    }
                }

                // Pass data to write to file
                if (Semaphore.readyForPCD)//change to use semaphore
                {
                    Semaphore.passPCD(vertexData, index);
                }

                // Dispose frames for memory
                imageDepthFrame.Dispose();
                if (colorOn)
                {
                    imageColorFrame.Dispose();
                }
                imageSkeletonFrame.Dispose();
            }
        }