Convert OpenCV Mat of a depth image to an ofImage

I’m using a couple of Asus Xtion sensors and need to basic blob detection.
At the moment I’m using OpenCV 2.4.4 built with OpenNI with
Marek’s of64(https://github.com/mazbox/of64) and Kyle McDonald’s ofxCv.

I’ve tried to use ofxCV’s toOf utility:

  
  
toOf(mat1,pix1);  
image1.setFromPixels(pix1.getPixels(), W, H, OF_IMAGE_GRAYSCALE, false);  
  

or

  
  
toOf(mat1,image1.getPixelsRef());  
image1.update();  
  

but I get some strange results:




Any hints on how the conversion should be made ?

Also, I’ve tried ofxCv’s drawMat but that also doesn’t seem to work.

  
  
if( !sensor1.grab() ){  
        cout << "Sensor1 can not grab images." << endl;  
        return -1;  
    }else if( sensor1.retrieve( mat1, CV_CAP_OPENNI_DEPTH_MAP ) ) {  
        imshow("depth1",mat1);  
        //toOf(mat1,pix1);  
		//image1.setFromPixels(pix1.getPixels(), W, H, OF_IMAGE_GRAYSCALE, false);  
        //toOf(mat1,image1.getPixelsRef());  
        //image1.update();  
        drawMat(mat1,0,0);  
    }  
  

I presume it might have something to do about how OpenCV deals with the depth map internally,
but I’m clueless on how to tackle that. Any thoughts ?

Thanks,
George

hi george

hm, …
OPENNI gives unsigned short* as vals for the depth image, maybe theres a problem, because OF wants unsigned char* s ?

greetings ascorbin

Hi ascorbin,

You might be right about this, although I’m not 100% sure.
I’m piggyback riding on OpenCV a lot, including interfacing with OpenNI,
so not sure if OpenCV maintain’s formats after getting data from OpenNI.
I’d asume pixel data would get converted to OpenCV’s (Mat) format for
easier further manipulation.

I’m not super comfortable in c++, how could I convert from short* to char* ?

Thanks,
George

P.S. Just noticed you’re from Frankfurt. Turns out I’ll be there(for the 1st time) mid March :slight_smile:

Hi George

yes, cool lets then meet in frankfurt…

well, for the conversions try to check what ranges the values are getting, just throw some out via console:

  
cout << whatever << endl;  

unsigned char* is from 0 to 255, so you probably have to divide bigger vals, dont know…

greetings