2014-01-16 61 views
0

我开始用openni进行编程并打开cv使用kinect工作。 这里是我用来获取数据深度图(它正在工作)的代码的一部分 现在我的问题是: 我怎样才能得到depht地图作为回报图像? 我的数据是DepthPixel * pDepth1,我想显示深度图的图像(因为我想保存她)。 谢谢从深度数据得到深度图kinect openni open cv

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

据我记得,OpenNI提供了16位无符号整数的kinect深度图,所以CV_16U。 尝试'cv :: Mat深度(frame_height,frame_width,CV_16U,reinterpret_cast (pDepth1));'。如果可以的话,你可以将它保存到磁盘上,但记得在保存之前检查OpenCV如何转换图像,也许你必须在(以及松散的精度)之前手动转换为CV_8U,或者必须使用另一个库来保存图像。 – Micka

+0

我不想保存到磁盘上,我只是想显示结果 – user1876275

+0

你知道该怎么做吗? 谢谢! – user1876275

回答

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位无符号整数。