您好我正在尝试从Microsoft kinect for xbox 360获取视差图。我安装了libfreenect的opencv 3.0.0和openni2。当我运行我的代码时
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**){
VideoCapture capture( CAP_OPENNI2 );
namedWindow("win",1);
for(;;){
Mat depthMap;
capture >> depthMap;
imshow("win",depthMap);
if( waitKey( 30 ) >= 0 ) break;
}
return 0;
}
我的kinect开始投射红外模式,但后来又出现了一堆错误
OpenNI2-FreenectDriver: Using libfreenect v0.5.3
OpenNI2-FreenectDriver: Found device freenect://0
OpenNI2-FreenectDriver: Opening device freenect://0
[Stream 70] Negotiated packet size 1920
write_register: 0x0105 <= 0x00
write_register: 0x0006 <= 0x00
write_register: 0x0012 <= 0x03
write_register: 0x0013 <= 0x01
write_register: 0x0014 <= 0x1e
write_register: 0x0006 <= 0x02
write_register: 0x0017 <= 0x00
[Stream 80] Negotiated packet size 1920
write_register: 0x000c <= 0x00
write_register: 0x000d <= 0x01
write_register: 0x000e <= 0x1e
write_register: 0x0005 <= 0x01
[Stream 70] Lost 2 total packets in 0 frames (inf lppf)
[Stream 70] Lost 5 total packets in 0 frames (inf lppf)
write_register: 0x0047 <= 0x00
OpenNI2-FreenectDriver: (ERROR) Unexpected size for XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE
OpenCV Error: Unspecified error (CvCapture_OpenNI2::readCamerasParams : Could not read virtual plane distance! ) in readCamerasParams, file /home/ubuntu/opencv-3.0.0/modules/videoio/src/cap_openni2.cpp, line 379 terminate called after throwing an instance of 'cv::Exception' what(): /home/ubuntu/opencv-3.0.0/modules/videoio/src/cap_openni2.cpp:379: error: (-2) CvCapture_OpenNI2::readCamerasParams : Could not read virtual plane distance! in function readCamerasParams
Aborted
答案 0 :(得分:1)
libfreenect需要修复的错误。
cd OpenNI2-FreenectDriver / src vim DepthStream.hpp
在第173行中,检查XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE需要大小为unsigned long long的pDataSize。 但是,OpenNI2需要一个int32_t(大小为8,大小为4),因此错误是有序的。如果,则不会出现此错误 如果你单独使用OpenNI2或NiTE2,因为他们不要求这个属性。但是,如果您使用OpenCV + OpenNI2, 上述财产将被查询。
修正。将案例XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE更改为:
case XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE: // unsigned long long or unsigned int (for OpenNI2/OpenCV)
if ( *pDataSize != sizeof(unsigned long long) && *pDataSize != sizeof(unsigned int) )
{
LogError("Unexpected size for XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE!!!");
return ONI_STATUS_ERROR;
} else {
if( *pDataSize == sizeof(unsigned long long) ) {
*(static_cast<unsigned long long*>(data)) = ZERO_PLANE_DISTANCE_VAL;
} else {
*(static_cast<unsigned int*>(data)) = (unsigned int) ZERO_PLANE_DISTANCE_VAL;
}
return ONI_STATUS_OK;
}
请参阅here