I'm trying to record a video (640 x 360 MJPEG) with this camera using python and opencv but i can't get to the camera rated FPS.
This is the snippet I'm currently using:
stream = cv2.VideoCapture(1, cv2.CAP_DSHOW)
stream.set(cv2.CAP_PROP_FRAME_HEIGHT, 360)
stream.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
stream.set(cv2.CAP_PROP_FORMAT, cv2.CAP_OPENCV_MJPEG)
t0 = cv2.getTickCount()
while (cv2.getTickCount() - t0)/cv2.getTickFrequency() < 10:
ret, frame = stream.read()
frames.append(frame)
total = (cv2.getTickCount()-t0)/cv2.getTickFrequency()
print("Total time:", total, "# of Frames:", len(frames), "fps:", len(frames)/total)
The output I get is
Total time: 10.0027773 # of Frames: 1874 fps: 187.34796784888934
The camera is rated for 260fps but I can't really get close to that. If I try to print the elapsed time of each frame this is what i get for the first few frames:
1 - 0.3112283
2 - 0.3267393, before+0.015511
3 - 0.3289934, before+0.0022541
4 - 0.3311813, before+0.0021879
5 - 0.3427716, before+0.0115903
As you can see there are two main problems:
- it's not starting from zero
- once every 3 frames the read function takes horribly longer (this goes on for the whole bunch of frames)
Any clue about why and how to overcome this? Thanks in advance