how can i control webcam fps
I have difficulty handling fps in real-time webcam, not video file.
Currently my code always give 30 fps in any resolution like 640 x 480 or 1280 x 720. And I'm using logitech c922 which says it supports 60 fps in 720p (1280 x 720)
And I tried 'cap.set(cv2.CAP_PROP_FPS, 60)' where cap is, for example, 'cv2.VideoCapture(0)'. (it's written in python by the way). But It didn't work for me and someone even said CAP_PROP_FPS can be only used in video.
Thus, I don't know how i can figure this out. Please help me.
my codes as follows.
import cv2
import time
cap = cv2.VideoCapture(1)
frame_size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print(frame_size)
print(cv2.CAP_PROP_FPS)
prevTime = 0
while True:
retval, frame = cap.read()
if not retval:
break
curTime = time.time()
sec = curTime - prevTime
prevTime = curTime
fps = 1/(sec)
str = "FPS : %0.1f" % fps
cv2.putText(frame, str, (0, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0))
cv2.imshow('frame', frame)
key = cv2.waitKey(1)
if (key == 27):
break
if cap.isOpened():
cap.release()
cv2.destroyAllWindows()
thanks you in advance.
Use timing in your loop to get image every x second.
you're measuring a) wall time, not cpu / process cycles b) the time of the whole loop (including waitKey(), drawing, etc.
since you're using python, you won't have any control about it, you're at the mercy of your os (which is ?) your camera driver (which is ?) and the opencv backend used (which is ?)
So your point is that there is no way to control fps using python opencv so I should use other language(like c++) or other library(i don't know in this case) to control webcam, right? I'm not really experienced with programming in this field and it's first time for me to use webcam in this way, so would be appreciated if you give me some details. thanks :P
How do you take a picture with a camera ? press the button. Instead of press the button ask an image when you need it using cap.read()
No, it's the contrary: you can use set on
CAP_PROP_FPS
only on cameras. Video files have fixed FPS.Anyway, it's better to set the FPS value; timed capture causes lot of problems (for lower framerates jitter, and you cannot increase the framerate)
Try other FPS and resolution values too; maybe the camera doesn't support 60fps, or it won't work on the default resolution.
In the meantime I join berak's question: what OS and camera driver do you use?
I merely agreed withh @LBerger.
You have typo error. Change this:
to
Change this too:
cap = cv2.VideoCapture(1)
tocap = cv2.VideoCapture(0)
Ok! Here is answer, but the moderator(s) may help you tranlsated to c++ to python using pc system. logitech c922
I'm currently using 'window 10' and, i don't know whether it's right or not but, am using 'C922 Pro Stream Webcam' driver provided by Microsoft
thanks for telling me typo error. And the reason why i used
cap = cv2.VideoCapture(1)
is that I used second webcam which is legitech c922 not a built-in camera by the way. thanks for your opinion though.