【问题标题】:cannot open camera with ubuntu opencv c++无法用ubuntu opencv c ++打开相机
【发布时间】:2018-02-10 11:20:06
【问题描述】:

我有一个问题,我无法打开我电脑的摄像头 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;
}

正在显示

无法打开相机

因为 isOpened 返回 false

【问题讨论】:

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

标签: c++ opencv ubuntu


【解决方案1】:

请确保正确检测到相机。你可以通过执行:

    $ls /dev/video*

我还发现其他程序可以为您提供更详细的输出,例如ffmpeg 与 V4L 执行例如

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

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

【讨论】:

    猜你喜欢
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 2022-09-29
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多