I’ve recently built OpenCV (on Windows 10) and wanted to try the rgbd examples, but ran into OpenNI 2 related errors:
example_rgbd_dynafu_demo.exe
[ERROR:0] global C:\Users\george.profenza\Downloads\gp\opencv\modules\videoio\src\cap.cpp (246) cv::VideoCapture::open VIDEOIO(OPENNI2): raised OpenCV exception:
OpenCV(4.5.1-pre) C:\Users\george.profenza\Downloads\gp\opencv\modules\videoio\src\cap_openni2.cpp:378: error: (-2:Unspecified error) CvCapture_OpenNI2::CvCapture_OpenNI2 : Couldn't start IR stream: in function 'CvCapture_OpenNI2::toggleStream'
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.5.1-pre) Error: Unspecified error (CvCapture_OpenNI2::CvCapture_OpenNI2 : Couldn't start IR stream: ) in CvCapture_OpenNI2::toggleStream, file C:\Users\george.profenza\Downloads\gp\opencv\modules\videoio\src\cap_openni2.cpp, line 378
How would I go about fixing/getting around this issue ?
(I remember successfully using OpenCV with OpenNI 1 back in 2012 and that worked like a charm. I can see the WITH_OPENNI in CMake however the configuration Video I/O only lists OpenNI2, but no OpenNI (1). Is there a way to try OpenNI 1 if OpenNI 2 doesn’t work?)
Did you try to start the camera using OpenNI 2 (try the SDK examples)? The error clearly says that the problem isn’t with OpenCV or OpenNI, but by starting the IR camera.
Otherwise you can use OpenNI (or the SDK of any other camera) without the OpenCV binding. It’s a bit more complicated, but I prefer this solution as it gives much better control of the camera. Then, convert the grabbed buffer to OpenCV Mat for further processing.
Here is a little pseudocode:
uchar *buffer;
Camera mycam;
if(!mycam.open())printf("Camera not opened!!!");
int W,H;
W = mycam.getWidth(); H = mycam.getHeight();
mycam.start();
mycam.grab(buffer);
Mat img(W,H,CV_8UC3,buffer);
cvtColor(img,img,COLOR_RGB2BGR);
//...process img in OpenCV...