Пример #1
0
        private void ProcessImages()
        {
            Sample sample = reader.Sample;

            Intel.RealSense.Image color = sample.Color;
            Intel.RealSense.Image depth = projection.CreateDepthImageMappedToColor(sample.Depth, color); //create depth mapped to color image

            ImageData colorData;
            ImageData depthData;

            color.AcquireAccess(ImageAccess.ACCESS_READ, colorPixelFormat, out colorData);
            depth.AcquireAccess(ImageAccess.ACCESS_READ, depthPixelFormat, out depthData);

            // Update the user interface
            UpdateUI(colorData, color.Info, ImageType.COLOR);
            UpdateUI(depthData, depth.Info, ImageType.DEPTH);

            if ((captureImage || captureSeries) && !pauseSave)
            {
                int          cwidth       = color.Info.width;
                int          cheight      = color.Info.height;
                int          dwidth       = depth.Info.width;
                int          dheight      = depth.Info.height;
                float[]      depthPixels  = ImageToFloatArray(depth);
                PointF32[]   invuvmap     = GetInvUVMap(color, depth);
                Point3DF32[] mappedPixels = GetMappedPixels(cwidth, cheight, dwidth, dheight, invuvmap, depthPixels);

                Bitmap depthBitmap = depthBitmap = GetDepthF32Bitmap(depth.Info.width, depth.Info.height, mappedPixels, allLandmarks);
                Bitmap colorBitmap = colorBitmap = colorData.ToBitmap(0, cwidth, cheight);


                //save image
                if (captureImage)
                {
                    SaveSingleRgbdToDisk(colorBitmap, depthBitmap, mappedPixels);
                }
                else if (captureSeries)
                {
                    SaveSeriesRgbdToDisk(dirName, colorBitmap, depthBitmap, mappedPixels);
                }

                depthBitmap.Dispose();
                colorBitmap.Dispose();
            }

            //release access
            color.ReleaseAccess(colorData);
            depth.ReleaseAccess(depthData);
            color.Dispose();
            depth.Dispose();
            projection.Dispose();
        }
Пример #2
0
        public ColorDepthImage GetImage()
        {
            //Checks to make sure that the camera has been properly initialized
            if (Status == CameraStatus.Stopped)
            {
                throw new InvalidOperationException("The camera cannot produce data unless it is running");
            }

            //Acquires the frame
            Status acquisitionResult = SMInstance.AcquireFrame(true);

            if (acquisitionResult.IsError())
            {
                throw new Exception("Unable to capture frame: " + acquisitionResult);
            }

            Texture2D colorTex = new Texture2D(WIDTH, HEIGHT, TextureFormat.RGBA32, false);
            Texture2D depthTex = new Texture2D(WIDTH, HEIGHT, TextureFormat.RGBA32, false);

            //Extract the color image
            Image     colorImage = SampleStream.Sample.Color;
            ImageData colorImageData;

            colorImage.AcquireAccess(ImageAccess.ACCESS_READ, PixelFormat.PIXEL_FORMAT_RGB32, out colorImageData);
            colorImageData.ToTexture2D(0, colorTex);

            //Extract and map the depth image
            Image      initialDepthImage = SampleStream.Sample.Depth;
            Projection proj       = SMInstance.CaptureManager.Device.CreateProjection();
            Image      depthImage = proj.CreateDepthImageMappedToColor(initialDepthImage, colorImage);
            ImageData  depthImageData;

            depthImage.AcquireAccess(ImageAccess.ACCESS_READ, PixelFormat.PIXEL_FORMAT_RGB32, out depthImageData);
            depthImageData.ToTexture2D(0, depthTex);

            //Clean up resources
            colorImage.Dispose();
            depthImage.Dispose();
            initialDepthImage.Dispose();
            proj.Dispose();
            colorImage.ReleaseAccess(colorImageData);
            depthImage.ReleaseAccess(depthImageData);

            //Release the acquired frame
            SMInstance.ReleaseFrame();

            return(new ColorDepthImage(colorTex, depthTex));
        }