VideoCapture slow on USB Camera

Hello everyone,

The VideoCapture is slow on the USB Camera. Can anybody help?
code is similar to this:

#include <iostream>
#include <opencv2//opencv.hpp>
//#include<windows.h>

using namespace cv;

int main()
{
    Mat frame;
    VideoCapture cap(0, cv::CAP_ANY);
    //Sleep(300)
    cap >> frame;
    imshow("CAMERA 1", frame);
    waitKey(0);
    return 0;
}

so I cannot directly run VideoCapture. I can only run with the Sleep(300) with a USB camera. However, I can run it properly with the computer’s camera. What is the problem?

Ziyue Wang

what do you mean, “slow”? you are reading a single frame.

of course, initializing the camera device takes a bit of time. that’s why you’re supposed to do it once, and then read multiple frames.

please clarify.

VideoCapture cap(0, cv::CAP_ANY);

this will probably default to the MSMF backend, try:

VideoCapture cap(0, cv::CAP_DSHOW);

as well, please, might work better with your hw

If I read a single frame it will read a blank image.
The only solution is to sleep(300) before cap >> frame and it will run normally. That is what I mean “slow”.

I tried, but it does not work.

if the camera needs a moment to deliver useful pictures, opencv can’t do anything about that.