VideoCapture buffer and read time

asked 2016-07-12 01:53:28 -0600

dassgo gravatar image

I am trying to read images from a usb camera with VideoCapture in Python (cap.read() ). Time is really critical.

There is an internal buffer in openCV of 5 frames, so when an image is requested, I have to make 4 cap.grab() and then one cap.read() to reduce time to its minimum.

In the file cap_libv4l.cpp, there is a variable DEFAULT_V4L_BUFFERS (#define DEFAULT_V4L_BUFFERS 4). I have changed it and have recompiled OpenCV. #define DEFAULT_V4L_BUFFERS 0 is not allowed, it gives an error. If I change it to #define DEFAULT_V4L_BUFFERS 1, I just need to make one cap.grab() and one cap.read(). But time doesn't reduce. When you reduce the value of DEFAULT_V4L_BUFFERS then time of cap.read() increase, being the total time the same in both cases: buffer size 4 (4 grabs and 1 read) and buffer size 1 (1 grab and 1 read).

Why does this happen? Is there any way to reduce the capture time besides using threads? I tested threads but then I face the "select timeout" problem capturing images.

edit retag flag offensive close merge delete