set(cv2.CAP_PROP_FPS, 60) is not working and camera feed lagging

asked 2019-10-06 16:59:49 -0500

updated 2019-10-06 21:05:51 -0500

supra56 gravatar image

using PyCharm on MacOS. installed OpenCV by using command: pip install opencv-contrib-python.

cap.set(cv2.CAP_PROP_FPS, 60) does not reset CAP_PROP_FPS and video stream is lagging.

someone mentioned libv4l-dev should be installed, but libv4l-dev cannot be installed on macOS.

after set FPS, cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) will throw below error. OpenCV(4.1.1) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'.

import cv2

import os

toggle = True

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FPS, 60)

while True:

    ret, frame =
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow("image", gray)
    if toggle:
        os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')
        toggle = False

    if cv2.waitKey(1) & 0xFF == ord('q'):

edit retag flag offensive close merge delete


Mac is not supportedlibv4l-dev.

supra56 gravatar imagesupra56 ( 2019-10-07 04:36:26 -0500 )edit

Your camera can't support settings FPS or can't set to 60 frames/s. You also should check variable ret after If ret is False, frame is not valid.

kiet gravatar imagekiet ( 2019-10-11 00:05:02 -0500 )edit