Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

inport 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.

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.

inport 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.