使用华硕Xtion Pro和OpenCV查看黑框而不是深度图像

See a black frame instead of a depth image with ASUS Xtion Pro and OpenCV

本文关键字:深度 图像 深度图 Xtion 华硕 Pro OpenCV      更新时间:2023-10-16

我实际上可以从我的华硕Xtion获得RGB图像,但无法获得任何深度图像。我看到的是黑色图像,没有出现错误。

OpenNI给出的示例SimpleView有效,所以我想它不是传感器,不是库,OpenCV似乎可以正常工作。

知道吗?

这是我的代码:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char* argv[] )
{
    cout << "Device opening ..." << endl;
    VideoCapture captureStream;
    captureStream.open(CV_CAP_OPENNI_ASUS);

    if( !captureStream.isOpened() ){
        cout << "Can not open capture object." << endl;
        return -1;
    }
    for(;;){
        Mat depth;
        if( !captureStream.grab() ){
            cout << "ASUS Xtion can not grab images." << endl;
            return -1;
        }else
            if( captureStream.retrieve( depth, CV_CAP_OPENNI_DEPTH_MAP) )
                imshow("depth",depth);
        if( waitKey( 30 ) == 27 )   break;
    }
    return 0;
}

谢谢!

OpenCV 示例代码实际上使用以下代码来检索和显示深度图:

Mat depth;
capture.retrieve( depth, CV_CAP_OPENNI_DEPTH_MAP )
const float scaleFactor = 0.05f;
Mat show; 
depth.convertTo( show, CV_8UC1, scaleFactor );
imshow( "depth map", show );