Kinect的作物图像 [英] Kinect crop image

查看:96
本文介绍了Kinect的作物图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图裁剪视频RGB的矩形区域。首先,我发现头关节的坐标以及与此坐标我画一个矩形,在RGB视频。现在我想在另一个视频显示只是是所述第一图像中的rentangle内部的图像。任何帮助将是巨大的。

I'm trying to crop a rectangular region of a video RGB. First i found the coordinates of head joint and with this coordinates i drew a rectangle over the RGB video. Now i want to show in another video just the image that is inside of the rentangle in the first image. Any help would be great.

视频RGB显示在RGBvideo图像控制。
裁剪图像我想在faceImage图像控制显示

video RGB is displayed in a "RGBvideo" Image Control. cropped image i want to display in a "faceImage" Image Control

我已经在网上搜索,但未能找到解决它。我很迷惑。

I've search online but couldn't find a solution to it. I am confuse.

太感谢你了。

推荐答案

欢迎堆栈溢出,请不要多次问同样的问题。随着冷门标签,如Kinect的,它可能需要一些时间的人来回答(标记只有79追随者)。

Welcome to Stack Overflow, please don't ask the same question multiple times. With less popular tags like Kinect, it can take some time for people to answer (the tag only has 79 followers).

为了简单起见,我将假设你要裁剪出一套大小的图像(例如,为60x60像素的淘汰原有的800×600)。在你VideoFrameReady方法,你从事件参数的PlanarImage。这PlanarImage有位字段,它包含了所有的图像RGB数据。随着一点点的数学,你可以切出该数据的小块并把它作为一个更小的图像。

For simplicity, I'm going to assume you want to crop out a set size image (for example, 60x60 pixels out of the original 800x600). In your VideoFrameReady method, you get the PlanarImage from the event args. This PlanarImage has the bits field, which contains all of the RGB data for the image. With a little math, you can cut out a small chunk of that data and use it as a smaller image.

// 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);
}

请确保你理解了code,而不只是复制/粘贴它。这两个for循环的基本阵列复制,每个像素的字节考虑到(4 BGR32)的数量。然后你使用它的原始数据的小的子集来创建一个新的BitmapSource。你需要你可以改变宽度/高度,您认为合适,并确定X和从头部追踪Y坐标。

Please make sure you understand the code, instead of just copy/pasting it. The two for loops are for basic array copying, with the number of bytes per pixel taken into account (4 for BGR32). Then you use that small subset of the original data to create a new BitmapSource. You'll need to you can change the width/height as you see fit, and determine the X and Y coordinates from the head tracking.

这篇关于Kinect的作物图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆