Kinect SDK深度数据(C ++)转换为OpenCV?

5
我一直在使用Kinect SDK(版本1.6)中的DepthBasicsD2D C++示例从Kinect获取深度帧,并希望使用该数据在OpenCV中执行blob检测。
我已经按照示例配置了OpenCV,并了解了示例的基本工作原理。但是,目前似乎没有任何帮助文档,因此很难弄清楚如何从Kinect获取像素数据并传递到OpenCV的IplImage /cv::Mat结构中。
您对这个问题有什么想法吗?
1个回答

2

这可以帮助您将Kinect颜色、深度图像和深度图像转换为OpenCV表示:

// get a CV_8U matrix from a Kinect depth frame 
cv::Mat * GetDepthImage(USHORT * depthData, int width, int height) 
{
    const int imageSize = width * height; 
    cv::Mat * out = new cv::Mat(height, width, CV_8U) ;
    // map the values to the depth range
    for (int i = 0; i < imageSize; i++)
    {
        // get the lower 8 bits
        USHORT depth =  depthData[i];   
        if (depth >= kLower && depth <= kUpper) 
        {
            float y = c * (depth - kLower); 
            out->at<byte>(i) = (byte) y; 
        }
        else
        {
            out->at<byte>(i) = 0; 
        }
    }
    return out; 
};

// get a CV_8UC4 (RGB) Matrix from Kinect RGB frame
cv::Mat * GetColorImage(unsigned char * bytes, int width, int height)
{
    const unsigned int img_size = width * height * 4; 
    cv::Mat * out = new cv::Mat(height, width, CV_8UC4);

    // copy data
    memcpy(out->data, bytes, img_size); 

    return out; 
}

1
没有必要动态分配cv::Mat。 - vinjn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接