【问题标题】:low fps by using cv2.VideoCapture使用 cv2.VideoCapture 降低 fps
【发布时间】:2019-06-12 11:21:50
【问题描述】:

我的 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应该怎么做?

【问题讨论】:

  • 你在另一台机器上测试过这个吗?
  • 你为什么在里面提到了urllib?您是否以某种方式通过“网络”阅读?

标签: python opencv camera frame-rate


【解决方案1】:

我知道我迟到了,但是如果其他人面临这个问题......

检查您是否使用了正确的编解码器。对于 Logitech OrbiCam,我必须将其设置为 MJPG:

对于 C++:

cv::VideoCapture camera;
camera.open(0);
auto codec = cv::VideoWriter::fourcc('M','J','P','G');
camera.set(cv::CAP_PROP_FOURCC, codec);

在 Python 中:

import cv2
camera = cv2.VideoCapture(0)
camera.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('m','j','p','g'))

对于 Kotlin:

var capture: VideoCapture = VideoCapture()
camera.open(deviceId)
val mjpg = VideoWriter.fourcc('M', 'J', 'P', 'G')
capture.set(Videoio.CAP_PROP_FOURCC, mjpg.toDouble())

等等……

...然后设置你的目标分辨率

【讨论】:

    【解决方案2】:

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

     cap = cv2.VideoCapture(0)
    

    它只进行一次一次性初始化。

    【讨论】:

      【解决方案3】:

      尝试降低分辨率。你可以试试 640x480。

      示例:

      cap.set(CV_CAP_PROP_FRAME_WIDTH, 640)
      cap.set(CV_CAP_PROP_FRAME_WIDTH, 480)
      

      【讨论】:

        【解决方案4】:
        # 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))
        

        将这些行放在 while 函数上方。

        【讨论】:

          猜你喜欢
          • 2018-04-11
          • 1970-01-01
          • 2019-05-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-06-26
          • 2021-12-20
          • 2020-11-08
          相关资源
          最近更新 更多