我正在尝试使用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;
}
最佳答案
我猜想当您使用USB摄像头时,会将参数更改为VideoCapture cap(1)而不是cap(0)。 cap(1)是您的USB相机驱动程序,可能需要单独安装。尝试使用cap(2)或cap(3),看看是否通过usb摄像机在imshow上获得了输出。
如果没有帮助,请更换
cap.retrieve(frame);
与
cap>>frame;
关于c++ - 仅适用于USB网络摄像头的imShow上的OpenCV崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35822775/