c++ - OpenCV VideoCapture 有时会返回空白帧

标签 c++ opencv video capture

我正在使用以下代码在 MS VC++ 2012 中使用 openCV3 从 USB 网络摄像头捕获视频帧。但问题是有时我能够以 30 fps 的速度显示捕获的帧,但有时我会得到黑色帧非常低帧率(或高延迟)。换句话说,程序是随机运行的。你知道我怎么解决这个问题吗?我尝试了 stackoverflow 或其他一些地方建议的不同解决方案,但没有一个解决了问题。

VideoCapture v(1);
v.set(CV_CAP_PROP_FRAME_WIDTH, 720);
v.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
if(!v.isOpened()){
   cout << "Error opening video stream or file" << endl;
   return;
}

Mat Image;
namedWindow("win",1);

while(1){
    v >> Image;
    imshow("win", Image);
}

最佳答案

试试这个:

while(1){
    v >> Image;
    imshow("win", Image);
    char c=waitKey(10);//add a 10ms delay per frame to sync with cam fps
    if(c=='b')
       {
            break;//break when b is pressed
       }
}

关于c++ - OpenCV VideoCapture 有时会返回空白帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35586051/

相关文章:

c++ - OpenGl 多边形旋转

python - PyOpenCV 不会使用 Python2.7 在 Raspbian 上构建

jquery - 在一个 fancybox 弹出窗口中使用 vimeo 视频和图像

ios - 使用 GPUImageChromaKeyFilter 的视频在透明 GPUImageView 中播放时有色调吗?

opencv - 我想使用 OpenCV 来检测静态图像中的二维条形码,但文档似乎没有涵盖它

video - YouTube高等教育版的付费支持选项

C++ 将 const char* 指针数组传递给对象

c++ - C++ 中 *& 和 **& 的含义

c++ - 纹理映射问题 OpenGL GLUT

opencv - 如何使两张相机照片看起来相似(亮度、白平衡……)