Ask Your Question
0

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 -0600

navya gravatar image

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

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));
cvtColor(m,hsv,CV_BGR2HSV);
cvtColor(hsv,m,CV_HSV2BGR);//*/
IplImage iplimg(m);
cvNamedWindow("rgb",1);
cvShowImage("rgb",&iplimg);

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
1

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

berak gravatar image

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

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):

namedWindow("rgb",1);
imshow("rgb",rgb);
waitKey(10); // nessecary for imshow to work
edit flag offensive delete link more

Comments

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

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

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

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

Question Tools

Stats

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

Seen: 138 times

Last updated: Jun 12 '14