Opencv and orbbec astra

Good afternoon,

I’m trying to get frames from my orbbec astra through opencv with openni2, the code I’m testing is as follows:
#include
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
    VideoCapture cam(CAP_OPENNI2);

    Mat color, depth, depC;

    while(true)
    {
        //Grab frames
        cout << cam.grab();
    }
}

However, I always get the following error on VideoCapture:

OpenCV Error: Unspecified error (Failed to initialize:) in CvCapture_OpenNI2, file /home/bruno/opencv/modules/videoio/src/cap_openni2.cpp, line 222
VIDEOIO(cvCreateCameraCapture_OpenNI2(index)): raised OpenCV exception:

/home/bruno/opencv/modules/videoio/src/cap_openni2.cpp:222: error: (-2) Failed to initialize: in function CvCapture_OpenNI2

however, I can run openni2’s simpleviewer … Any suggestions?

Thank you
Bruno Barbosa

Without seeing your exact setup - for starters make sure the orbbec openNi driver folder and the openni ini files are in the same directory as your compiled executable - otherwise the system will never find and initialise your camera device.

1 Like

Thank you! you help me to solve the problem.