C++ 访问像素值深度图

C++ 访问像素值深度图,c++,visual-studio-2010,opencv,kinect,C++,Visual Studio 2010,Opencv,Kinect,我正在尝试使用kinect、openni和opencv访问深度贴图的像素值。我正在使用这个代码 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); sys

我正在尝试使用kinect、openni和opencv访问深度贴图的像素值。我正在使用这个代码

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");
Mat深度;
视频捕获1(CV_CAP_OPENNI);
capture1.grab();
capture1.检索(深度、CV\u CAP\u OPENNI\u深度图);
imshow(“深度”,depth);
等待键(0);

cout由于您没有指定错误,我来试一试:问题似乎是您试图从另一个
Mat
访问元素:您创建的元素名为
depth
,然而,
cout
调用中引用的一个被命名为
depthshow

根据for
CAP\u OPENNI\u DEPTH\u MAP
,你的
Mat
应该每像素有16位无符号整数数据,而不是你试图使用的32位无符号整数。因此,请改用以下方法:

// uint16_t available in C++11
cout << depth.at<uint16_t>(20,20) << " millimetres";
//uint16\t在C++11中可用

这是哪个版本的OpenCV?
// 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";