2012-01-19 104 views
0

即時嘗試訪問深度圖的像素值,使用kinect,openni和opencv。 IM使用此代碼訪問像素值深度圖

Mat depth; 
VideoCapture capture1(CV_CAP_OPENNI); 
capture1.grab(); 
capture1.retrieve(depth,CV_CAP_OPENNI_DEPTH_MAP); 
imshow("depth",depth); 

waitKey(0); 
cout << depth.at<unsigned>(20,20); 
system("PAUSE"); 

程序告訴我深度圖,但是當我試圖acccess的值,產生錯誤。但如果放:

cout << depth; 

然後顯示我的所有值。

+0

哪個版本的OpenCV是這樣嗎? – Jacob

回答

0

由於你沒有指定的錯誤,我給它一個鏡頭:這個問題似乎是,您試圖訪問從另一個Mat元素:創建一個名爲depth,但是一個在cout調用中引用的名稱爲depthshow

0

按照documentationCAP_OPENNI_DEPTH_MAP,您Mat應該有16位無符號整型數據每像素,而不是unsigned int你想使用32位。因此,使用以下代替:

// uint16_t available in C++11 
cout << depth.at<uint16_t>(20,20) << " millimetres"; 

// not 100% sure that all compilers produce 16 bits fields 
cout << depth.at<unsigned short int>(20,20) << " millimetres";