欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 高考 > 虚拟机ubnatu18.04 使用USB摄像头碰见问题

虚拟机ubnatu18.04 使用USB摄像头碰见问题

2024/10/24 4:29:38 来源:https://blog.csdn.net/m0_63893772/article/details/140609404  浏览:    关键词:虚拟机ubnatu18.04 使用USB摄像头碰见问题

1.虚拟机用指令打开USB摄像头及使用cheese工具

参考:虚拟机内Ubuntu如何打开摄像头+解决cheese工具黑屏问题_ubuntu cheese-CSDN博客

2.在代码中同时使用两个摄像头时遇到 can't open camera by index

VideoCapture camera0(0);
if( !camera0.isOpened() )
{cout << "camera0 Open failed \n";return 1;
} VideoCapture camera1(1);
// camera1.set(CAP_PROP_FRAME_WIDTH,320);
// camera1.set(CAP_PROP_FRAME_HEIGHT,240);
if( !camera1.isOpened() )
{cout << "camera1 Open failed \n";return 1;
} 

在上述代码中把 VideoCapture camera1(1);改成VideoCapture camera1(2);就不会出现这样的问题;至于是什么原因还未得知(猜测:1个USB摄像头对应2个/dev/videox,第二个摄像头开始正好是/dev/video2);

3.从两个摄像头中取出画面帧,组合两个帧画面并显示出来

代码:

#include <opencv2/opencv.hpp>
#include<iostream>using namespace cv;
using namespace std;int main()
{VideoCapture camera0(0);if( !camera0.isOpened() ){cout << "camera0 Open failed \n";return 1;} VideoCapture camera1(2);if( !camera1.isOpened() ){cout << "camera1 Open failed \n";return 1;} while(true) {//grab and retrieve each frames of the video sequentiallyMat frame1,frame0,blended_img;bool bSuccess0 , bSuccess1;//camera1 >> frame1;bSuccess1 = camera1.read(frame1);if (!bSuccess1){cout << "111 不能从视频文件读取帧" << endl;break;}//camera0 >> frame0;bSuccess0 = camera0.read(frame0);if (!bSuccess0){cout << "000 不能从视频文件读取帧" << endl;break;}addWeighted(frame0, 0.3, frame1, 0.7, 0.0, blended_img);imshow("Video0", frame0);imshow("Video1", frame1);imshow("blended_img", blended_img);int c = waitKey(27);if(27 == char(c)) break;} return 0; 
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com