I'm using opencv python to do image processing. When I measure the FPS it's not stable. Sometimes FPS is 10 sometimes 12. I want to make FPS stable at 9 frame per second. Is there anyway to do that?
EDIT: I'm using my laptop's webcam. But I also have an Hikvision IP Camera. I need to do that independent from camera. Here is how I'm measuring FPS.
while True:
timer = cv2.getTickCount()
ret, img = cap.read()
fps = cv2.getTickFrequency()/(cv2.getTickCount()-timer)
cv2.putText(img, str(int(fps)), (75, 75),cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
cv2.imshow("Tracking", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
CodePudding user response:
I don't know why you need that but here is your answer:
You can not expect a camera to give always exact/constant fps because of some low level device design configurations. If 30 fps written in a camera spec, its fps can vary 30~33.
What you can do is that you can pull 9 frames from the buffer in a sec and ignore the extra frames which camera feeds.
Here is a good discussion to check.