【问题标题】:OpenCV 2.2 Does not open CameraOpenCV 2.2 不打开相机
【发布时间】:2012-05-03 01:27:28
【问题描述】:

我想使用相机并对输入流执行图像处理,但是在执行程序时会出现一个窗口询问“捕获源”,然后当“确定”或“应用”时没有任何反应。

但如果我使用视频文件而不是相机,程序运行得非常好。

代码如下:

int MainWindow::on_CameraOpen_triggered()
{
// programming done in Qt and using Opencv 2.2.
// all the variables are defined & declared in private of header file
// there is no compilation error
// return type of the function is 'int'
// Following program works fine if name of video file is mentioned 
// instead of '0' is the line below
VideoCapture capture(0);

if(!capture.isOpened())
    return 1;

    bool stop(false);
    double rate = capture.get(CV_CAP_PROP_FPS);
    namedWindow("Extracted Frame");
    int delayVideo = 1000/rate;

    while(!stop)
    {
        if(!capture.read(frame))
        {
            break;
        }
        imshow("Extracted frame", frame);
        if(waitKey(delayVideo)>=0)
        {
            stop = true;
        }
    }

capture.release();
}

我已尝试删除已在以下链接中纠正的错误: https://code.ros.org/trac/opencv/changeset/4400

https://code.ros.org/trac/opencv/browser/trunk/opencv/modules/highgui/src/precomp.hpp?rev=4400

相机在 gtalk 和其他相机软件上运行良好。

请建议/指导可以做什么。

非常感谢。

问候, 数据库

【问题讨论】:

    标签: c++ qt opencv camera


    【解决方案1】:

    试试这个代码:

    # include <opencv2/highgui/highgui.hpp>
    
    CvCapture *_capture;
    
    
    _capture = cvCaptureFromCAM(-1);
    //_capture = cvCaptureFromFile("test1.mp4");
    if (!_capture)
    {
        //"Unable capture video"
        return 1;
    }
    
    double rate = cvGetCaptureProperty(_capture, CV_CAP_PROP_FPS);
    
    //...
    
    cv::Mat = cvQueryFrame(_capture);
    
    //...
    

    【讨论】:

    • 嗨,您能否解释/澄清一下您提到的代码的“//...”部分应该包含哪些内容?到我的代码。在 2.2 之前我从未使用过任何版本的 opencv
    【解决方案2】:

    这是另一个最小的示例,您可以使用它来检查 OpenCV 是否一切正常:

    #include <opencv2/opencv.hpp>
    #include <opencv2/highgui/highgui.hpp>
    
    int main () {
        cv::VideoCapture cam = cv::VideoCapture(0);
        cv::Mat frame;
        cv::namedWindow ("Demo", CV_WINDOW_AUTOSIZE);
    
        while (1) {
            cam >> frame;
            imshow ("Demo", frame);
        }
    
        cam.release();
        return 0;
    }
    

    试试看问题出在 OpenCV 还是你的 Qt 程序上。

    【讨论】:

      猜你喜欢
      • 2019-01-07
      • 2019-06-16
      • 1970-01-01
      • 2021-07-31
      • 2013-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-01
      相关资源
      最近更新 更多