opencv打开双目摄像头

xiaoxiao2021-02-28  53

最近朋友请教了我一些双目摄像头的问题,小编在这里经过查阅资料给出一段程序,,有人说用directshow来实现,有人说直接可以用opencv读取多个摄像头。那么,既然opencv能实现,为什么还要装其他的库呢?我现在就来介绍使用opencv读取并显示双目摄像头。另外我的双目摄像头仅仅只是两个合在一起的只有一条USB线的。 运行环境: 笔记本 树莓派 操作系统:unbuntu 库:opencv g++等 至于如何移植如何敲代码,小编不在重复,请参照我小、小编前些日子发的帖子http://www.oucteam.com/forum.php … id=2&extra=page=1 OK,下面我们贴出代码:

#include <opencv2/opencv.hpp> using namespace std; int main() { //initialize and allocate memory to load the video stream from camera cv::VideoCapture camera0(1); camera0.set(CV_CAP_PROP_FRAME_WIDTH,320); camera0.set(CV_CAP_PROP_FRAME_HEIGHT,240); cv::VideoCapture camera1(0); camera1.set(CV_CAP_PROP_FRAME_WIDTH,320); camera1.set(CV_CAP_PROP_FRAME_HEIGHT,240); if( !camera0.isOpened() ) return 1; if( !camera1.isOpened() ) return 1; while(true) { //grab and retrieve each frames of the video sequentially cv::Mat frame0; camera0 >> frame0; cv::Mat frame1; camera1 >> frame1; cv::imshow("left", frame0); cv::imshow("right", frame1); // std::cout << frame1.rows() << std::endl; //wait for 40 milliseconds int c = cvWaitKey(40); //exit the loop if user press "Esc" key (ASCII value of "Esc" is 27) if(27 == char(c)) break; } return 0; }

编译之后直接运行即可,若有两个以上摄像头,只需要修改摄像头对应参数即可。

转载请注明原文地址: https://www.6miu.com/read-85244.html

最新回复(0)