ofxCv and kinect ( cvAnd ?)


#1

Hi

I would like to use ofxCv with ofxKinect.
So i am trying to adapt the kinect example to use ofxCv.

2 things:
I do not know how to cast the garyImageMat back in to an ofImage, so i can draw it.

So i left it out right now. It compiles fine, starts running, shows no kinect images and crashes with this message:

OF: OF_VERBOSE: ofxKinect: Context inited
OF: OF_VERBOSE: ofxKinect: Number of devices found: 1
OF: OF_VERBOSE: ofxKinect: Number of available devices: 1
OF: OF_VERBOSE: ofxKinect: Device 0 connection opened
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /Users/theo/Documents/CODE/__OPENFRAMEWORKS/gitOF/__BuildAllLibs/OpenCV-2.2.0/modules/imgproc/src/color.cpp, line 2433
terminate called after throwing an instance of ‘cv::Exception’
what(): /Users/theo/Documents/CODE/__OPENFRAMEWORKS/gitOF/__BuildAllLibs/OpenCV-2.2.0/modules/imgproc/src/color.cpp:2433: error: (-215) scn == 3 || scn == 4 in function cvtColor

  
		  
                Mat grayImageMat;  
		  
		  
		Mat mat = Mat(kinect.height, kinect.width, CV_8UC1, kinect.getDepthPixels(), 0);  
		convertColor(mat, grayImageMat, CV_RGB2GRAY);  
		  
	  
		Mat nearThreshMat = grayImageMat; //toCv(grayImage);  
		Mat farThreshMat = grayImageMat; //toCv(grayImage);  
			  
		threshold(nearThreshMat,nearThreshold);  
		threshold(farThreshMat,farThreshold);  
		  
		//bitwise_and(const Mat& src1, const Scalar& src2, CV_OUT Mat& dst, const Mat& mask=Mat());  
		bitwise_and(nearThreshMat, farThreshMat, grayImageMat);  
  
	  
		contourFinder.setThreshold(contourThreshold);  
		contourFinder.findContours(grayImageMat);  
  


#2

ok the crash was due to this line:

convertColor(mat, grayImageMat, CV_RGB2GRAY);
since the depth image is already gray.

i changed it to this:

Mat grayImageMat = Mat(kinect.height, kinect.width, CV_8UC1, kinect.getDepthPixels(), 0);

but still don’t know how to draw grayImageMat on screen.


#3

Using CV_RGB2GRAY with the Kinect depth image doesn’t seem right, since the depth image isn’t really RGB and especially since you’re declaring the cv::Mat as CV_8UC1 rather than CV_8UC3 (which is right, since the depth image is just unsigned char*). I don’t think you need that call to convertColor at all.

===

Ha! I guess you beat me to it :slight_smile:


#4

Have you checked out ofxCv::drawMat()?

You should be able to just call:

  
 drawMat(mat, 0,0,640,480);  

You can take a look here: https://github.com/kylemcdonald/ofxCv/blob/master/libs/ofxCv/src/Helpers.cpp

Hope that helps.


#5

thanks joshua.

drawMat worked.

also noticed that i have to pass one Mat to the a new one like this:

  
  
		copy(grayImageMat,nearThreshMat);  
		copy(grayImageMat,farThreshMat);  
  

this did not give me correct results:
Mat nearThreshMat = grayImageMat;
Mat farThreshMat = grayImageMat;


#6

I also want to use ofxCv and Kinect. Im not able to make my code work. Can you post your code if you have succeeded?