2012-01-19 63 views
0

即时尝试访问深度图的像素值,使用kinect,openni和opencv。 IM使用此代码访问像素值深度图

Mat depth; 
VideoCapture capture1(CV_CAP_OPENNI); 
capture1.grab(); 
capture1.retrieve(depth,CV_CAP_OPENNI_DEPTH_MAP); 
imshow("depth",depth); 

waitKey(0); 
cout << depth.at<unsigned>(20,20); 
system("PAUSE"); 

程序告诉我深度图,但是当我试图acccess的值,产生错误。但如果放:

cout << depth; 

然后显示我的所有值。

+0

哪个版本的OpenCV是这样吗? – Jacob

回答

0

由于你没有指定的错误,我给它一个镜头:这个问题似乎是,您试图访问从另一个Mat元素:创建一个名为depth,但是一个在cout调用中引用的名称为depthshow

0

按照documentationCAP_OPENNI_DEPTH_MAP,您Mat应该有16位无符号整型数据每像素,而不是unsigned int你想使用32位。因此,使用以下代替:

// uint16_t available in C++11 
cout << depth.at<uint16_t>(20,20) << " millimetres"; 

// not 100% sure that all compilers produce 16 bits fields 
cout << depth.at<unsigned short int>(20,20) << " millimetres";