public void SetImage(ColorDepthImage image) { const float MM_UNITY_CONV = 800.0f; //Creates the projection and array to populate imageProj = SMInstance.CaptureManager.Device.CreateProjection(); depthArray = new Point3DF32[image.DepthImage.height * image.DepthImage.width]; //Iterates through each of the pixels and places them in the appropriate array var dImageArray = image.DepthImage.GetPixels(); for (int i = 0; i < depthArray.Length; i++) { depthArray[i].x = i % WIDTH; depthArray[i].y = i / WIDTH; depthArray[i].z = dImageArray[i].grayscale; } //Performs the conversion pointArray = new Point3DF32[WIDTH * HEIGHT]; imageProj.ProjectDepthToCamera(depthArray, pointArray); //Scales the units for (int i = 0; i < pointArray.Length; i++) { pointArray[i].x *= MM_UNITY_CONV; pointArray[i].y *= MM_UNITY_CONV; pointArray[i].z *= MM_UNITY_CONV; } //Releases resources imageProj.Dispose(); }
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(); }
/// <summary> /// 終了処理 /// </summary> private void Uninitialize() { if (senseManager != null) { senseManager.Dispose(); senseManager = null; } if (projection != null) { projection.Dispose(); projection = null; } }
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)); }