Ask Your Question
1

VideoCapture captures at low fps

asked 2017-05-16 10:34:28 -0600

George Sid. gravatar image

Hello

I have a camera that captures video (according to the specifications) at a resolution of 640x480 at 120fps. I use the script below to check the speed I can capture frames with OpenCV on Python, but unfortunately I can't capture at the same speed, not even close.

import cv2
from time import time

cap = cv2.VideoCapture(2)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

start = time()
for i in range(120):
    _, frame = cap.read()

end = time()

print("FPS: {}".format(120/(end-start)))

cap.release()

By settingCAP_PROP_FRAME_WIDTH and CAP_PROP_FRAME_HEIGHT properties I get a difference of +3 fps. Setting the CAP_PROP_FPS property to any value does not make any difference. The fps I get using the above script is FPS: 31.842164199216985. Without setting anything or just the CAP_PROP_FPS I get: FPS: 28.553502962704776.

I recorded a video with a recorder to see if the camera can actually get that kind of speed and the result, although not close enough to 120, is 50fps. I can see that there is probably a problem with the camera itself, but the difference between the code and the recorder is still at 20 fps.

So the question is: Why I can't get higher fps capture with OpenCV on Python, at least as close as the video I recorded? Can I get high (~120) fps capture at all? If yes, which camera does actually work (with OpenCV)?

Thank you in advance

edit retag flag offensive close merge delete

Comments

1

I think that 120fps is possible with proprietary software or using specific function in driver

I think that CAP_PROP_FPS is for videowriter.

Test your camera a sunny day not the night

LBerger gravatar imageLBerger ( 2017-05-16 15:54:06 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-05-17 02:21:05 -0600

J. Romeo gravatar image

In my experience, to achieve high speeds or to be able to access/modify certain camera config parameters I've always needed the manufacturer's SDK.

My usual approach is to use the manufacturer's SDK to allocate a memory buffer and save the sequence there. When capture of the sequence is finished, then I convert the images to the OpenCV format (or directly create the Mats with the data pointer pointing to this buffer). This is not a real-time process, but I've been able to capture at around 1000 FPS.

edit flag offensive delete link more

Comments

Is there a "more" real-time approach for ~120 fps capture?

George Sid. gravatar imageGeorge Sid. ( 2017-05-18 14:18:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-05-16 10:34:28 -0600

Seen: 10,018 times

Last updated: May 17 '17