using ofxOpenNI image in opencv

Hi all

I’m using ofxOpenni from gameoverhack with success on ubuntu 11.10 and 12.04 it works very well.

I try to get a part of mask image to do some finger extraction with opencv.
The problem is that my opencv Mat looks a bit crumbled (strange format and strange lines on it) and so my extraction don’t work

I’m still really confuse after reading this thread, especially this one

since I have sort of the same result.

I need opencv CV_8UC1 (8 bit unsigned, on channel) from ofxOpenNIDepthThreshold mask that return ofPixel to extract contours convexHull and so on but since my source image (Mat) is bad, the rest don’t work…

I guess the problem comes from pixel format but can’t figure out how to fix it since I still don’t really understood how pixels are managed in this story.

this is the code

    for (int i = 0; i < openNIDevice.getNumTrackedHands(); i++){  
        ofxOpenNIHand & hand = openNIDevice.getTrackedHand(i);  
        ofPoint & handPosition = hand.getPosition();  
        ofxOpenNIDepthThreshold & depthThreshold = openNIDevice.getDepthThreshold(i);   
		// need one channel to find contours  
		Mat depthMat = Mat(640,480,CV_8UC1,depthThreshold.getMaskPixels().getPixels(), 0);   
//// this one looks weird  
		drawMat(roi, 960, 0);  

please can you help me with best practice snipet that works or some clear explanation on how to go from RGBA ofpixel to one channel unsgned char mat ?

I’d suggest using Kyle McDonald’s ofxCv addon:

It provides a toCv() function that will convert anything with ofpixels to a Mat.