我开始使用openni和open cv编程我正在使用kinect。 这里是我用来获取数据深度图的代码的一部分(它工作) 现在我的问题是: 我怎么能得到depht地图作为回报? 我的数据是在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();
}
答案 0 :(得分:0)
假设您已将您的依赖项整理出来,以下内容对我来说是有用的
//set up the capture with the correct settings
VideoCapture capture = new VideoCapture;
capture->open(CV_CAP_OPENNI);
capture->set(CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, CV_CAP_OPENNI_VGA_30HZ);
//get an image and display it
Mat image;
capture->grab();
capture->retrieve(image, CV_CAP_OPENNI_DEPTH_MAP);
然后像处理任何其他矩阵一样处理图像。请记住,作为捕获的图像CV_16U以16位无符号整数记录深度。