Ask Your Question

What Modification in the code by Microsoft Kinect D2D sample has to be made to connect it with openCV?

asked 2014-06-12 05:05:56 -0500

navya gravatar image

updated 2014-06-12 05:15:39 -0500

berak gravatar image

I got this code from a site.....

cvSetData(img,(BYTE*) pBuffer, img->widthStep);
Mat &m = Mat(img);
Mat &hsv = Mat();
vector<Mat> mv = vector<Mat>(3,Mat(cvSize(640,480),CV_8UC1));
IplImage iplimg(m);

But here it is not told how to initialize the "img".... Help!!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-06-12 05:24:24 -0500

berak gravatar image

updated 2014-06-12 05:46:14 -0500

please try to avoid the outdated c-api calls, IplImage, cv* functions, stick with Mat and the cv:: namespace.

you should be able to create a Mat directly from pBuffer:

Mat img = Mat(height,width,CV_8UC3, (uchar*)pBuffer);

now if pBuffer goes out of scope before img does, you have to clone it (above is just a shallow copy):

Mat rgb = img.clone();

then you can just show it (no further IplImage required):

waitKey(10); // nessecary for imshow to work
edit flag offensive delete link more


I tried this code.... But it says height and width are uninitialized...

navya gravatar imagenavya ( 2014-06-12 05:54:51 -0500 )edit

there must be a way to retrieve it , where pBuffer was coming from

berak gravatar imageberak ( 2014-06-12 06:14:49 -0500 )edit

Question Tools


Asked: 2014-06-12 05:05:56 -0500

Seen: 87 times

Last updated: Jun 12 '14