Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

kinect - How to initialize multiple OpenNI sensors with OpenCV

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;



   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...