[英]cannot open camera with ubuntu opencv c++
I have a problem I can not open camera 0 of my pc 我有一个问题,我无法打开我的电脑的相机0
here is the code that I use: 这是我使用的代码:
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) { // check if we succeeded
cout << "cannot open camera "<< endl;
return -1;
}
Mat edges;
namedWindow("edges",1);
for(;;){
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, COLOR_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
return 0;
}
it is displaying 它正在显示
can not open camera
无法打开相机
because isOpened returns false 因为isOpened返回false
Please make sure that the camera is correctly detected. 请确保正确检测到相机。 You can do so by executing:
您可以通过执行以下操作:
$ls /dev/video*
I have also found that other programs give you a more detailed output eg ffmpeg with V4L Execute eg 我还发现其他程序为您提供了更详细的输出,例如带有V4L Execute的ffmpeg,例如
ffmpeg -f v4l2 -i /dev/video0 -vf scale=640:480 -r 20 -t 00:00:10 output.mp4
and it will tell you if the source is busy or why the camera can't be opened, while OpenCV just returns false. 它会告诉您源是否忙,或者为什么无法打开摄像机,而OpenCV只是返回false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.