【问题标题】:Display Color and Depth using OpenNI and OpenCV使用 OpenNI 和 OpenCV 显示颜色和深度
【发布时间】:2017-01-17 13:41:38
【问题描述】:

我最近发布了很多关于使用 OpenNI 和 OpenCV 从 Kinect 相机访问深度图像的帖子。

根据其他一些帖子的一些教程和建议,我已经能够编写这个脚本来显示相机的 2D 颜色流(如果第二部分被注释掉)和深度流,这还没有工作:

#include <opencv2/opencv.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <OpenNI.h>

int main()
{
    openni::Device device;

    openni::VideoStream  color;
    openni::VideoStream depth;

    openni::VideoFrameRef depthFrame;
    openni::VideoFrameRef colorFrame;

    openni::Status rc = openni::STATUS_OK;

    rc = openni::OpenNI::initialize();
    rc = device.open(openni::ANY_DEVICE);

    rc = color.create(device, openni::SENSOR_COLOR);
    rc = color.start();
    rc = depth.create(device, openni::SENSOR_DEPTH);
    rc = depth.start();

    cv::Mat framecolor;
    cv::Mat framedepth;

    while (true)
    {
        color.readFrame(&colorFrame);
        const openni::RGB888Pixel* imageBuffer = (const openni::RGB888Pixel*)colorFrame.getData();

        framecolor.create(colorFrame.getHeight(), colorFrame.getWidth(), CV_8UC3);
        memcpy(framecolor.data, imageBuffer, 3 * colorFrame.getHeight()*colorFrame.getWidth() * sizeof(uint8_t));

        cv::cvtColor(framecolor, framecolor, CV_BGR2RGB); //this will put colors right
        cv::imshow("framecolor", framecolor);
        ////////////////////////////Second Part/////////////////////////////////////
        depthFrame.getVideoMode();
        const openni::DepthPixel* imageBuffer2 = (const openni::DepthPixel*)depthFrame.getData();

        framedepth.create(depthFrame.getHeight(), depthFrame.getWidth(), CV_16U);
        memcpy(framecolor.data, imageBuffer2, 3 * depthFrame.getHeight()*depthFrame.getWidth() * sizeof(uint16_t));
        framedepth.convertTo(framedepth, CV_8U);
        cv::imshow("framedepth", framedepth);

        if (cvWaitKey(30)>=0)
        {
            break;
        }
    }
    cv::destroyAllWindows();
    return 0;
}

我遇到的错误将我带到 openNI.g 文件,其中包含以下内容:

我猜这与文件类型或像素格式有关。然而,有很多选择,我什至不确定这种方法是否会奏效。

任何人都可以帮助处理所需的文件类型或过程吗?

【问题讨论】:

    标签: c++ opencv openni depth-testing


    【解决方案1】:

    代码有错误,

    framedepth.create(depthFrame.getHeight(), depthFrame.getWidth(), CV_16U);
    memcpy(**framecolor.data**, imageBuffer2, 3 * depthFrame.getHeight()*depthFrame.getWidth() * sizeof(uint16_t));
    framedepth.convertTo(framedepth, CV_8U)
    

    应该是

    framedepth.create(depthFrame.getHeight(), depthFrame.getWidth(), CV_16U);
    memcpy(**framedepth.data**, imageBuffer2, 3 * depthFrame.getHeight()*depthFrame.getWidth() * sizeof(uint16_t));
    framedepth.convertTo(framedepth, CV_8U)
    

    【讨论】:

      猜你喜欢
      • 2013-01-26
      • 2023-03-04
      • 2017-02-16
      • 1970-01-01
      • 2011-02-27
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 2013-04-02
      相关资源
      最近更新 更多