首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将cv::Mat转换为openni::VideoFrameRef

将cv::Mat转换为openni::VideoFrameRef
EN

Stack Overflow用户
提问于 2015-06-08 12:44:54
回答 1查看 874关注 0票数 2

我在cv::Mat中有一个kinect流数据。我正在尝试运行一些使用OpenNI的示例代码。

我能以某种方式将我的Mat转换成OpenNI格式的图像吗?

我只是需要深度图像,并在与OpenNI战斗了很长时间,已经放弃安装它。

我正在使用OpenCV 3,Visual 2013,Kinect v2 for Windows。

有关守则是:

代码语言:javascript
复制
void CDifodoCamera::loadFrame()
{
    //Read the newest frame
    openni::VideoFrameRef framed; //I assume I need to replace this with my Mat...
    depth_ch.readFrame(&framed);

    const int height = framed.getHeight();
    const int width = framed.getWidth();

    //Store the depth values
    const openni::DepthPixel* pDepthRow = (const openni::DepthPixel*)framed.getData();
    int rowSize = framed.getStrideInBytes() / sizeof(openni::DepthPixel);

    for (int yc = height-1; yc >= 0; --yc)
    {
        const openni::DepthPixel* pDepth = pDepthRow;
        for (int xc = width-1; xc >= 0; --xc, ++pDepth)
        {
            if (*pDepth < 4500.f)
                depth_wf(yc,xc) = 0.001f*(*pDepth);

            else
                depth_wf(yc,xc) = 0.f;
        }

        pDepthRow += rowSize;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-10 11:27:04

首先你需要了解你的数据是怎么来的..。如果它已经在cv::Mat中,您应该接收两个图像,一个用于RGB信息,通常是一个3通道cv::Mat,另一个用于深度信息,通常以毫米波格式保存它(您不能将浮动垫保存为图像,但可以使用opencv保存为yml/xml文件)。

假设要读取和处理包含深度信息的图像,则可以将代码更改为:

代码语言:javascript
复制
void CDifodoCamera::loadFrame()
{
    //Read the newest frame
    //the depth image should be png since it is the one which supports 16 bits and it must have the ANYDEPTH flag
    cv::Mat depth_im = cv::imread("img_name.png",CV_LOAD_IMAGE_ANYDEPTH); 

    const int height = depth_im.rows;
    const int width = depth_im.cols;

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            if (depth_im<unsigned short>(y,x) < 4500)
                depth_wf(y,x) = 0.001f * (float)depth_im<unsigned short>(y,x);

            else
                depth_wf(y,x) = 0.f;
        }
    }
}

希望这能帮到你。如果你有任何问题,只需问:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30709546

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档