Reputation: 67
Hello I am trying to get disparity maps from a Microsoft kinect for xbox 360. I have opencv 3.0.0 and openni2 with libfreenect installed. When I run my code
#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;
}
My kinect starts projecting the IR pattern but then I get a bunch of errors
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
Upvotes: 0
Views: 938
Reputation: 11
libfreenect a bug fixed required.
cd OpenNI2-FreenectDriver/src vim DepthStream.hpp
In line 173, the check for XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE expects a pDataSize of size unsigned long long. However, OpenNI2 expects an int32_t (size 8 vs size 4) so an error is in order. This error does not appear if if you use OpenNI2 or NiTE2 alone, since they don't ask for this property. However, if you use OpenCV+OpenNI2, the said property will be queried.
Fix. Change the case XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE with:
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;
}
see here
Upvotes: 1