2017-07-08 156 views
0

下面的C++代碼給出其連續地從Kinect的2的Kinect V2閱讀深度問題

#include <Kinect.h> 
#include <cmath> 
#include <cstdio> 
#include <cstdlib> 
#include <Windows.h> 
#include <iostream> 
using namespace std; 

const int width = 512; 
const int height = 424; 
const int colorwidth = 1920; 
const int colorheight = 1080; 
IDepthFrameReader* reader;  // Kinect depth data source 
IKinectSensor* sensor = nullptr; 
int main(int argc, char* argv[]) { 
    if (FAILED(GetDefaultKinectSensor(&sensor))) { 
     return 19; 
    } 
    if (sensor) { 
     sensor->Open(); 
     IDepthFrameSource* framesource = NULL; 
     sensor->get_DepthFrameSource(&framesource); 
     framesource->OpenReader(&reader); 
     if (framesource) { 
      framesource->Release(); 
      framesource = NULL; 
     } 
     IDepthFrame* frame = NULL; 
     if (SUCCEEDED(reader->AcquireLatestFrame(&frame))) { 
      cout << "not bad"; 
      getchar(); 
      return 100; 
     } 
     else{ 
      cout << "not found"; 
      getchar(); 
      return 23; 
     } 
    } 
    else { 
     return -1; 
    } 
} 

獲取最新的框架其實,如果我連Kinect的到我的筆記本電腦或沒有,輸出沒有變化它是:「未找到」。當我連接Kinect並運行程序時,Kinect的燈亮起。在一些現成的代碼中,Kinect可以正常工作。哪裏有問題?

回答

0

您應該查看返回的AcquireLatestFrame的錯誤代碼,也許它可以告訴你什麼是問題。

這裏有一個提示:也許,當您撥打AcquireLatestFrame時,該框架尚未提供。因此,將此調用放入循環中,框架遲早可用。

+0

謝謝。你知道我可以如何在CV :: Mat中複製該幀嗎? – ma98

+0

對不起,我不熟悉OpenCV。試着問一下,也許有人可以幫助你。 – geza