I have posted about consistent FPS from USB camera before in python. Using gstreamer and opencv I can achieve consistent FPS limited by the exposure time and threading the function. However when I reach a low exposure time and fps goes over about 50 fps the FPS becomes unpredictable and appears to max out from 50-60 fps. Running “v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=MJPG --stream-mmap --stream-count=100 -d /dev/video0” provides the correct FPS displayed in the command line limited by exposure or the max FPS of the camera. Right now in python i am running the following in a thread:
gstr = ‘v4l2src device=/dev/video0 ! video/x-raw, format=(string)UYVY,
num-buffers=500, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1
! videoconvert ! video/x-raw,format=BGR ! appsink’
cap = cv2.VideoCapture(gstr, cv2.CAP_GSTREAMER)
while(True):
ret, frame = cap.read()
Is there any other method besides opencv in python to grab from the camera that might be faster. I think opencv is too slow and is what is causing the unpredictability when I get to 50-60 fps region. Or alterntativley can you set it to grab at a specified fps. I am only interested in sampling at 10 fps, this fps though is not available though in the format I am reading in.
Those pipelines in that post did not work for me. However I found a work around that seems to do the trick. I will call the device in the same manor as my gstreamer command in opencv read thru a terminal command in python. I store the average fps results in a text file and then read out the last average fps. This seems to match the fps read from opencv perfectly. Cheers!