如何使用OpenCV初始化多个OpenNI传感器 [英] How to initialize multiple OpenNI sensors with OpenCV
本文介绍了如何使用OpenCV初始化多个OpenNI传感器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在OpenCV(2.4.4)中使用两个Asus Xtion Pro传感器,但不确定如何初始化两个设备.
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);
如何为两个单独的传感器初始化两个VideoCapture实例?
How can I initialize two VideoCapture instances for two separate sensors ?
推荐答案
原来如此简单:
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;
}
}
这篇关于如何使用OpenCV初始化多个OpenNI传感器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文