【发布时间】:2014-01-16 14:23:58
【问题描述】:
我开始使用 openni 和 open cv 进行编程,我正在使用 kinect 。 这是我用来获取数据深度图的一部分代码(它正在工作) 现在我的问题是: 我怎样才能将深度图作为图像作为回报? 我的数据在 DepthPixel* pDepth1 上,我想显示深度图的图像(因为我想保存她)。 谢谢你
VideoFrameRef frame;
DepthPixel* pDepth1 = NULL;
DepthPixel* pDepth2 = NULL;
for (int i = 0; i < 2; i++)
{
int changedStreamDummy;
VideoStream* pStream = &depth;
rc = OpenNI::waitForAnyStream(&pStream, 1, &changedStreamDummy, SAMPLE_READ_WAIT_TIMEOUT);
if (rc != STATUS_OK)
{
printf("Wait failed! (timeout is %d ms)\n%s\n", SAMPLE_READ_WAIT_TIMEOUT, OpenNI::getExtendedError());
continue;
}
rc = depth.readFrame(&frame);
if (rc != STATUS_OK)
{
printf("Read failed!\n%s\n", OpenNI::getExtendedError());
continue;
}
if (frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_1_MM && frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_100_UM)
{
printf("Unexpected frame format\n");
continue;
}
if (i == 0){
int dummy;
cout << "Press any key to take first pic: ";
cin >> dummy;
pDepth1 = (DepthPixel*)frame.getData();
}
else{
int dummy;
cout << "Press any key to take second pic: ";
cin >> dummy;
pDepth2 = (DepthPixel*)frame.getData();
}
【问题讨论】:
-
据我记得,OpenNI 提供了 kinect 深度图,它是 16 位无符号整数,所以 CV_16U。试试
cv::Mat depth(frame_height, frame_width, CV_16U, reinterpret_cast<void*>(pDepth1));。如果可行,您可以将其保存到磁盘,但请记住在保存之前检查 OpenCV 如何转换图像,也许您必须在之前手动转换为 CV_8U(并且精度不高),或者必须使用另一个库来保存图像。 -
我不想保存到磁盘我只想显示结果
-
你知道怎么做吗?谢谢!
-
没有将kinect与openCV一起使用,所以我不知道如何在那个界面中获取深度数据。但是你可以试试这个
cv::Mat depthImage(frame_height, frame_width, CV_16U, reinterpret_cast<void*>(pDepth1));`cv::namedWindow("depth"); cv::imshow("深度", depthImage); cv::waitKey(-1);'但我不确定你在深度图中得到什么样的数据。很可能它应该是一个 16 位无符号整数数组,但这不能保证。也看看这两个链接:docs.opencv.org/doc/user_guide/ug_highgui.htmlgithub.com/Itseez/opencv/blob/master/samples/cpp/…