OpenCV在imShow上崩溃仅适用于USB网络摄像头
OpenCV Crashes on imShow only for usb webcam
我正在尝试使用Qt进行openCV设置。 我正在使用Qt creator,尽管我目前只进行C++/opencv调用。 此代码适用于我的集成网络摄像头,但是当我切换到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;
}
我猜当你使用你的USB摄像头时,你会将参数更改为VideoCapture cap(1)而不是cap(0)。 cap(1) 是您的 USB 相机驱动程序,可能需要单独安装。尝试 cap(2) 或 cap(3),看看您是否通过 USB 摄像头在 imshow 上获得输出。
如果这没有帮助,请更换
cap.retrieve(frame);
跟
cap>>frame;
相关文章:
- FLTK 2.0构建和演示,适用于VS2019的2011年左右的代码库
- C++17 - 使用自定义分配器的节点提取/重新插入 - 适用于 clang++/libc++,但不适用于 libstd
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- 适用于 WebView2 旧版本的示例应用程序
- 在 NVIDIA GEFORCE GTX 1050 上下载适用于 Windows 10 的 openCL 1.2
- __attribute__(优化(0))) 是否适用于"recursively"?
- 为什么 std::erase(std::erase_if) 不是适用于<algorithm>任何容器的模板?
- 使用一个参数的模板函数时出错(适用于 2)
- 使用 适用于 Android 和 iOS 的 tf-lite C++ API
- 为什么这适用于 G++ 而不是 CLANG?
- 适用于 macOS 的 Xcode 应用程序。这就是我设置从USB麦克风输入获取音频的方式。一年前工作,现在没有了。为什么
- 适用于 Linux 的 c++ 上的代理脚本
- 为什么我的 SFINAE 表达式不再适用于 GCC 8.2?
- 使输出流式处理运算符适用于 boost::variant<std::vector<int>、int、double 的正确方法是什么>
- 有没有适用于Windows.lib文件的GNU二进制文件描述符(BFD)
- 模板函数仅适用于VS
- 如何在cmake中包含适用于g++或viceversa的库
- 适用于win32、linux、mac的POSIX C包装器
- OpenCV在imShow上崩溃仅适用于USB网络摄像头
- 是否有适用于Windows的iTunes C++库允许访问USB连接的iOS设备的文件系统?