1

我目前正在使用Orbbec Astra Mini深度传感器。我下载并安装了Astra 驱动程序和 OpenNI2包。一旦我将深度传感器连接到 USB 端口,它就会显示在我的 Windows 10 的设备管理器中。到目前为止一切都很好。

我的目标是阅读RGB imagesdepth map使用 OpenCV 并使用imshow.

以下代码在 Visual Studio 2015 中编译良好,但出现此错误:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\build\master_winpack-build-win64-vc14\opencv\modules\highgui\src\window.cpp

...所以我猜 OpenCV 无法打开设备,因此我的 cv::Mat 一直是空的。

我在某处读到我需要使用 OpenNI 标志编译 OpenCV - 这是真的吗?如果是这样,任何有用的链接可能会帮助我取得一些进展?有什么我可能错过的想法吗?

#include<iostream>
#include<algorithm>
#include<fstream>
#include<System.h>
#include<time.h>
#include<opencv2/core/core.hpp>

using namespace std;

int main(int argc, char **argv) {

    cv::VideoCapture cap;
    cap.open(CV_CAP_OPENNI);
    cap.set(CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, CV_CAP_OPENNI_VGA_30HZ);
    cap.set(CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION, 1);

    cv::Mat im, dm;     // rgb image, depth map

    while (true)
    {

        if (cap.grab()) {
            cap.retrieve(im, CV_CAP_OPENNI_BGR_IMAGE);
            cap.retrieve(dm, CV_CAP_OPENNI_DEPTH_MAP);
        } else {
            cout << "ERROR: Could not grab image data." << endl;
        }

        if (!im.data) {
            cout << "ERROR: RGB not retrieved." << endl;
        }

        if (!dm.data) {
            cout << "ERROR: Depth map not retrieved." << endl;
        }

        cv::imshow("Image", im);
        cv::imshow("Depth", dm);

        if (cv::waitKey(1) >= 0)
            break;
    }

    cap.release();

    return 0;
}

更新 19.02.18:

通过使用此处所述的 OpenNI 标志编译 OpenCV 库来解决问题。谢谢德米特里!

但是,深度图像仍然很弱。任何想法/如何调整参数?虽然,在运行 Orbbec Astra SDK 的示例应用程序时,深度图像非常稳定(使用 OpenGL)。所以我想问题出在 OpenCV 的某个地方?

这是深度图的屏幕截图(反转为白色,共振非常弱):

在此处输入图像描述

4

2 回答 2

0

为了将我的Orbbec Astra 相机用作深度传感器,我编写了一份综合指南,如何使用包括OpenNI2的OpenCV编译ORB SLAM 2(这是我的初步目标) 。希望其他绊倒这个线程的人可以使用它。

于 2018-02-20T15:04:23.337 回答
0

您问:

但是,深度图像仍然很弱。任何想法/如何调整参数?虽然,在运行 Orbbec Astra SDK 的示例应用程序时,深度图像非常稳定(使用 OpenGL)。所以我想问题出在 OpenCV 的某个地方?

尝试对深度图像实施假彩色图。不同的深度像素具有密切变化的值,因此如果直接观察就不容易辨别。

 // Holds the colormap version of the image:
 Mat img_color;
 // Apply the colormap:
 applyColorMap(img_in, img_color, COLORMAP_JET);
 // Show the result:
 imshow("colorMap", img_color);

https://docs.opencv.org/3.4.1/d3/d50/group__imgproc__colormap.html

于 2018-05-23T18:04:06.480 回答