首页 > 解决方案 > 使用 cv2.VideoCapture 降低 fps

问题描述

我的 FPB 较低 ~5,我在不同的相机罗技 c270 和罗技 9000 上检查了此代码,情况相同。

我完成了关于关闭右灯等的所有提示。

import urllib.request as urllib
import cv2
import numpy as np
import time

while True:

    # Use urllib to get the image and convert into a cv2 usable format
    cap = cv2.VideoCapture(0)

    width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    hiegh = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

    ret, frame = cap.read()


    # put the image on screen
    cv2.imshow('Webcam', frame)


    if cv2.waitKey(1) & 0xFF == 27:
        break

cap.release()        
cv2.destroyAllWindows()

我应该怎么做才能增加FPS?

标签: pythonopencvcameraframe-rate

解决方案


您需要将这条线向上移动,您的采集循环之外:

 cap = cv2.VideoCapture(0)

它只进行一次初始化。


推荐阅读