0

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!

Deanie
  • 2,316
  • 2
  • 19
  • 35
KeyMaker00
  • 6,194
  • 2
  • 50
  • 49
  • 1
    Is the depth-buffer actually all zeroes or just very low numbers so it seems like it's black? – littleimp Nov 07 '13 at 12:25
  • 1
    How can I check the depth-buffer? (sorry, for the dumb question) – KeyMaker00 Nov 07 '13 at 12:35
  • Ah sorry I meant just check the contents of the _depth_ Mat at certain points to see what kind of values it contains. The reason for this: The depth-map might be correct, but you might have to scale it to be visible. – littleimp Nov 07 '13 at 12:48
  • Mmmmmh, now I've the following error: OpenNI_OpenCV_TrackingColorObject(4077,0x7fff7658e310) malloc: *** error for object 0x106c08000: pointer being freed was not allocated. – KeyMaker00 Nov 07 '13 at 13:45
  • Oooh and I've got the following: [43, 4, 43] [4, 43, 4] [43, 4, 46] [4, 46, 4] [46, 4, 49] [4, 46, 4] [0, 0, 0] [0, 0, 0] [0, 0, 0] [0, 0, 0] [0, 0, 0] [0, 0, 0] [0, 0, 0] [0, 0, 0] [0, 0, 0] [0, 0, 0] – KeyMaker00 Nov 07 '13 at 13:55
  • Shouldn't the depth only have one channel (CV_16UC1)? This looks like color data. Please see also my answer below with sample code that you can try. – littleimp Nov 07 '13 at 15:06

1 Answers1

1

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 );
littleimp
  • 1,159
  • 9
  • 13