Kinect裁剪图像

我正在尝试裁剪videoRGB的矩形区域。 首先,我找到了头部关节的坐标,在这个坐标上我在RGBvideo上画了一个矩形。 现在我想在另一个video中显示第一张图片中租金角内的图像。 任何帮助都会很棒。

videoRGB显示在“RGBvideo”图像控件中。 裁剪图像我想在“faceImage”图像控件中显示

我在网上搜索但找不到解决方案。 我很困惑。

非常感谢

欢迎使用Stack Overflow,请不要多次提出同样的问题。 对于像Kinect这样不太流行的标签,人们可能需要一些时间来回答(标签只有79个粉丝)。

为简单起见,我假设您要裁剪出一组尺寸的图像(例如,原始800×600中的60×60像素)。 在VideoFrameReady方法中,您可以从事件args获取PlanarImage。 此PlanarImage具有位字段,其中包含图像的所有RGB数据。 通过一些数学运算,您可以删除一小部分数据并将其用作较小的图像。

// update video feeds void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e) { PlanarImage image = e.ImageFrame.Image; // Large video feed video.Source = BitmapSource.Create(image.Width, image.Height, 96, 96, PixelFormats.Bgr32, null, image.Bits, image.Width * image.BytesPerPixel); // X and Y coordinates of the smaller image, and the width and height of smaller image int xCoord = 100, yCoord = 150, width = 60, height = 60; // Create an array to copy data into byte[] bytes = new byte[width * height * image.BytesPerPixel]; // Copy over the relevant bytes for (int i = 0; i < height; i++) { for (int j = 0; j < width * image.BytesPerPixel; j++) { bytes[i * (width * image.BytesPerPixel) + j] = image.Bits[(i + yCoord) * (image.Width * image.BytesPerPixel) + (j + xCoord * image.BytesPerPixel)]; } } // Create the smaller image smallVideo.Source = BitmapSource.Create(width, height, 96, 96, PixelFormats.Bgr32, null, bytes, width * image.BytesPerPixel); } 

请确保您了解代码,而不是仅仅复制/粘贴代码。 两个for循环用于基本数组复制,每个像素的字节数被考虑在内(BGR32为4)。 然后使用原始数据的这个小子集来创建新的BitmapSource。 您需要根据需要更改宽度/高度,并确定头部跟踪的X和Y坐标。