1

I'd like to use two Asus Xtion Pro sensors with OpenCV (2.4.4) and not sure how to initialize both devices.

I can initialize one like so:

VideoCapture capture;
capture.open(CV_CAP_OPENNI);

How can I initialize two VideoCapture instances for two separate sensors ?

George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • I found this statement, but I've not tried the action before: "If multiple sensors are attached to the system, then you should first call OpenNI::getDeviceInfoList() to obtain a list of all active devices. Then, find the desired device in the list, and obtain its URI by calling DeviceInfo:getUri(). Use the output from this function as the calling parameter for Device:open() in order to open that specific device." – Nicholas Pappas Feb 20 '13 at 15:56
  • @EvilClosetMonkey Is this using OpenNI2 or the original/v1 ? – George Profenza Feb 20 '13 at 16:14
  • It appears to be v2. Source: openni.org/openni-programmers-guide ... though I just realized I had a brain-fart -- realizing you're looking to open these streams in OpenCV. My link obviously doesn't help much there. Sorry; first visit SO in the morning with too little coffee. – Nicholas Pappas Feb 20 '13 at 17:07

1 Answers1

2

Turns out it's as simple as this:

VideoCapture sensor1;sensor1.open(CV_CAP_OPENNI_ASUS);
VideoCapture sensor2;sensor2.open(CV_CAP_OPENNI_ASUS+1);

A very basic runnable example is:

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>

using namespace cv;
using namespace std;

int main(){
cout << "opening device(s)" << endl;

VideoCapture sensor1;sensor1.open(CV_CAP_OPENNI_ASUS);
VideoCapture sensor2;sensor2.open(CV_CAP_OPENNI_ASUS+1);

if( !sensor1.isOpened() ){
    cout << "Can not open capture object 1." << endl;
    return -1;
}

for(;;){
    Mat depth1,depth2;

    if( !sensor1.grab() ){
        cout << "Sensor1 can not grab images." << endl;
        return -1;
    }else if( sensor1.retrieve( depth1, CV_CAP_OPENNI_DEPTH_MAP ) ) imshow("depth1",depth1);

    if( !sensor2.grab() ){
        cout << "Sensor2 can not grab images." << endl;
        return -1;
    }else if( sensor2.retrieve( depth2, CV_CAP_OPENNI_DEPTH_MAP ) ) imshow("depth2",depth2);

    if( waitKey( 30 ) == 27 )   break;



   }
}
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • What if you want a specific camera to always be camera one, and another to always be camera 2? – Pototo Sep 06 '16 at 22:55
  • With OpenCV I'm guessing ```CV_CAP_OPENNI_ASUS``` will be first connected sensor and ```CV_CAP_OPENNI_ASUS+1``` will be the second one, but I'd test that first. Also, you might not want to depend on the order in which sensors are connected anyway. Unfortunately OpenCV's VideoCapture doesn't have an API to retrieve the device name/id so you may need go [lower level to list the devices](http://stackoverflow.com/questions/20266743/using-device-name-instead-of-id-in-opencv-method-videocapture-open) and get name/serial number/index/etc. – George Profenza Sep 07 '16 at 15:14