我使用 OpenCV 3.2.1 和 kniect 运行 VS2010。
我正在使用 here 中的教程
int main( int argc, char* argv[] ){
VideoCapture capture(CV_CAP_OPENNI); // or CV_CAP_OPENNI
for(;;)
{
Mat depthMap;
Mat bgrImage;
capture.grab();
capture.retrieve( depthMap, CV_CAP_OPENNI_DEPTH_MAP ); // Depth values in mm (CV_16UC1)
capture.retrieve( bgrImage, CV_CAP_OPENNI_BGR_IMAGE );
cout << "rows: " << depthMap.rows << " cols: " << depthMap.cols << endl;
cout << "depth: " << depthMap.at<int>(0,0) << endl;
imshow("RGB image", bgrImage);
if( waitKey( 30 ) >= 0 )
break;
}h
return 0;
运行代码后,我得到以下结果:
靠近墙壁约一米远:
rows: 480 cols: 640
depth: 1157
rows: 480 cols: 640
depth: 1157
rows: 480 cols: 640
depth: 1157
rows: 480 cols: 640
depth: 1157
(Kinect面向墙壁,距离仅一米多)
rows: 480 cols: 640
depth: 83690629
rows: 480 cols: 640
depth: 83690629
rows: 480 cols: 640
depth: 83690629
rows: 480 cols: 640
depth: 83690629
rows: 480 cols: 640
depth: 83690629
有人告诉我这些值实际上是两个像素?我真的不明白。
到目前为止,这是我的理解:
我抓取了一个深度帧并将其存储在一个名为“深度图”的矩阵中。矩阵的大小现在为 640*480。我使用代码 heightMap.at(0,0) 从第 0 行、第 0 列获取第一个深度值。但我没有返回以毫米为单位的结果,而是返回 83690629!这与我期望的最大值 10000 相差甚远
如何将这些值转换为毫米以便我可以使用它们?谢谢
最佳答案
深度图数据是单 channel 无符号16位。
尝试将 t 中的 替换为
CV_16UC1
关于opencv - 如何使用 Kinect 在 OpenCV 中获取深度值然后转换为毫米?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10354609/