C++ 无法使用ubuntu opencv c+;打开相机+;

C++ 无法使用ubuntu opencv c+;打开相机+;,c++,opencv,ubuntu,C++,Opencv,Ubuntu,我有一个问题,我无法打开电脑的摄像头0 以下是我使用的代码: #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 suc

我有一个问题,我无法打开电脑的摄像头0

以下是我使用的代码:

#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;
}
#包括“opencv2/opencv.hpp”
#包括
使用名称空间cv;
使用名称空间std;
int main(int,char**)
{
VideoCapture cap(0);//打开默认摄像机
如果(!cap.isOpened()){//检查我们是否成功
cout-frame;//从摄影机获取新帧
CVT颜色(边框、边缘、颜色为灰色);
高斯模糊(边,边,大小(7,7),1.5,1.5);
Canny(边,边,0,30,3);
imshow(“边”,边);
如果(等待键(30)>=0)中断;
}
返回0;
}
它正在展示

无法打开相机


由于Ispened返回false,请确保正确检测到相机。您可以通过执行以下命令来执行此操作:

    $ls /dev/video*
我还发现其他程序提供了更详细的输出,例如带有V4L的ffmpeg 执行

     ffmpeg -f v4l2 -i /dev/video0 -vf scale=640:480 -r  20 -t 00:00:10 output.mp4

它会告诉您源是否正忙,或者为什么相机无法打开,而OpenCV只返回false。

您有什么相机?网络摄像头?我的摄像头是网络摄像头您安装了V4L吗?是的,我安装了V4L,但问题没有解决