Question

I can actually get a RGB image from my ASUS Xtion but cannot get any Depth image. I see a black image instead and no error shows up.

The sample SimpleView given with OpenNI works, so I guess it's not the sensor, not the library and OpenCV seems to work correctly.

Any idea?

Here is my code:

#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;
}

Thank you!

Was it helpful?

Solution

The OpenCV sample code actually uses this code to retrieve and display the depth-map:

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 );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top