【问题标题】:OpenCV Crashes on imShow only for usb webcamimShow 上的 OpenCV 崩溃仅适用于 USB 网络摄像头
【发布时间】:2016-06-19 18:22:40
【问题描述】:

我正在尝试使用 Qt 设置 openCV。尽管我目前只进行 C++/opencv 调用,但我正在使用 Qt creator。此代码适用于我的集成网络摄像头,但是当我切换到我的 USB 摄像头时,我收到一个 Windows 错误,告诉我 opencv.exe 已崩溃,Qt 告诉我我的程序意外完成。有趣的是,如果我将 imshow 更改为 imwrite,我会在一个文件中从网络摄像头获取输出,因此捕获似乎可以正常工作,我只是无法显示。

#include <opencv2/core/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>

using namespace cv;
int main(int argc, char *argv[])
{
    VideoCapture cap(0);

    // open the default camera, use something different from 0 otherwise;
    // Check VideoCapture documentation.
    if(!cap.isOpened())
        return 1;

    for(;;)
    {
          Mat frame;
          cap.retrieve(frame);
          if( frame.empty() ) break; // end of video stream

          imshow("this is you, smile! :)", frame);
          if( waitKey(1) == 27 ) break; // stop capturing by pressing ESC
    }
    // the camera will be closed automatically upon exit
    // cap.close();
    return 0;
}  

【问题讨论】:

    标签: c++ qt opencv window video-capture


    【解决方案1】:

    我猜当您使用 USB 摄像头时,您将参数更改为 VideoCapture cap(1) 而不是 cap(0)。 cap(1) 是您的 USB 摄像头驱动程序,可能需要单独安装。试试 cap(2) 或 cap(3),看看你是否通过 USB 摄像头在 imshow 上得到输出。

    如果没有帮助,请更换

    cap.retrieve(frame);
    

    cap>>frame;
    

    【讨论】:

    • 是的,忘了提到我确实从 cap(0) 更改为 cap(1)。实际上取决于当我启动它的 cap(0) 并且我的集成摄像头是 cap(1) 时 USB 摄像头是否在里面。没有运气更改为 2 或 3 他们在 !cap.isOpened() 调用中退出。生病尝试重新安装驱动程序。虽然我认为他们正在工作,因为我可以将帧写入文件
    猜你喜欢
    • 2018-03-24
    • 2012-12-20
    • 2016-03-05
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多