简体   繁体   English

如何使用OpenCV摄像机捕获设置帧率

[英]How to set framerate with OpenCV camera capture

How can I set the capture framerate, using OpenCV in Python? 如何在Python中使用OpenCV设置捕获帧率? Here's my code, but the resulting framerate is less than the requested 30fps. 这是我的代码,但是最终的帧率小于要求的30fps。 Also, quality of video very bad. 另外,视频质量也很差。

import cv
cv.NamedWindow ('CamShiftDemo', 1)
device = -1
cap = cv.CaptureFromCAM(device)
size = (640,480)
cv.SetCaptureProperty(cap, cv.CV_CAP_PROP_FPS,30)
cv.SetCaptureProperty(cap, cv.CV_CAP_PROP_FRAME_WIDTH, size[0])
cv.SetCaptureProperty(cap, cv.CV_CAP_PROP_FRAME_HEIGHT, size[1])
while True:
    frame = cv.QueryFrame(cap)
    cv.ShowImage('CamShiftDemo', frame)
    cv.WaitKey(10)

You are limited by the hardware, namely: 您受到硬件的限制,即:

  1. your camera's capture capabilities, and 相机的拍摄功能,以及
  2. your computer's system resources. 您计算机的系统资源。

If either of these cannot handle the requested capture parameters (in your case 640x480 resolution at 30fps), you're out of luck. 如果其中任何一个都不能处理请求的捕获参数(在30 fps下,分辨率为640x480),那么您就不走运了。 Parameters you give to OpenCV are merely suggestions -- it tries to match them as best it can. 您提供给OpenCV的参数仅是建议 -它会尽力匹配它们。

What model camera are you using? 您正在使用哪种型号的相机? I would first look at the model specs to see if they advertise the parameters you desire. 首先,我将看看模型规格,看看它们是否宣传您所需的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM