/// <summary> /// カラーイメージが更新された時の処理 /// </summary> /// <param name="color"></param> private void UpdateColorImage(Intel.RealSense.Image colorFrame) { if (colorFrame == null) { return; } //データの取得 ImageData data; //アクセス権の取得 Status ret = colorFrame.AcquireAccess(ImageAccess.ACCESS_READ, Intel.RealSense.PixelFormat.PIXEL_FORMAT_RGB32, out data); if (ret < Status.STATUS_NO_ERROR) { throw new Exception("カラー画像の取得に失敗"); } //ビットマップに変換する //画像の幅と高さ,フォーマットを取得 var info = colorFrame.Info; //1ライン当たりのバイト数を取得し(pitches[0]) 高さをかける (1pxel 3byte) var length = data.pitches[0] * info.height; //画素の色データの取得 //ToByteArrayでは色データのバイト列を取得する. var buffer = data.ToByteArray(0, length); //バイト列をビットマップに変換 imageColor.Source = BitmapSource.Create(info.width, info.height, 96, 96, PixelFormats.Bgr32, null, buffer, data.pitches[0]); //データを解放する colorFrame.ReleaseAccess(data); }
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(); }
private float[] ImageToFloatArray(Intel.RealSense.Image depth) { ImageData ddata; depth.AcquireAccess(ImageAccess.ACCESS_READ, Intel.RealSense.PixelFormat.PIXEL_FORMAT_DEPTH_F32, out ddata); var dwidth = depth.Info.width; var dheight = depth.Info.height; var dPixels = ddata.ToFloatArray(0, dwidth * dheight); depth.ReleaseAccess(ddata); return(dPixels); }