gpt4 book ai didi

opencv - 如何使用 OpenCV 初始化多个 OpenNI 传感器

转载 作者:太空宇宙 更新时间:2023-11-03 22:33:24 26 4
gpt4 key购买 nike

我想将两个 Asus Xtion Pro 传感器与 OpenCV (2.4.4) 一起使用,但不确定如何初始化这两个设备。

我可以这样初始化一个:

VideoCapture capture;
capture.open(CV_CAP_OPENNI);

如何为两个单独的传感器初始化两个 VideoCapture 实例?

最佳答案

其实就是这么简单:

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

一个非常基本的可运行示例是:

#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 - 如何使用 OpenCV 初始化多个 OpenNI 传感器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14983248/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com