CV2无法找到属性CV_CAP_PROP_FPS

刚刚学习OpenCV的时候,发现获得video的FPS总是不成功,提示无法找到属性CV_CAP_PROP_FPS.

最终,在stackoverflow网站上找到了答案。看来,在做opencv的时候,一定要找到相对应的opencv的帮助文档。

比如3.2版本的,要参考下面的链接,

https://docs.opencv.org/3.2.0/d4/d15/group__videoio__flags__base.html#gaeb8dd9c89c10a5c63c139bf7c4f5704d

问题:

I'm using opencv 3.2.0 and python 3.5.2 currently. When executing following code:

videoCapture = cv2.VideoCapture(file_path)
fps = videoCapture.get(cv2.CV_CAP_PROP_FPS)
size = (int(videoCapture.get(cv2.CV_CAP_PROP_FRAME_WIDTH)),
        int(videoCapture.get(cv2.CV_CAP_PROP_FRAME_HEIGHT)))

I encountered following error:

Traceback (most recent call last):
  File "videoEditor.py", line 29, in <module>
    fps = videoCapture.get(cv2.CV_CAP_PROP_FPS)
AttributeError: module 'cv2.cv2' has no attribute 'CV_CAP_PROP_FPS'

Could anyone tell me what I should do?


答案:

In OpenCV 3.2, drop the CV in front of the flag. This should work just fine

videoCapture = cv2.VideoCapture(file_path)
fps = videoCapture.get(cv2.CAP_PROP_FPS)
size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),
        int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))


下面是opencv 3.2中定义的属性,如果是其他版本的opencv,请自行去opencv官网查询,

Enumerator
CAP_PROP_POS_MSEC 

Current position of the video file in milliseconds.

CAP_PROP_POS_FRAMES 

0-based index of the frame to be decoded/captured next.

CAP_PROP_POS_AVI_RATIO 

Relative position of the video file: 0=start of the film, 1=end of the film.

CAP_PROP_FRAME_WIDTH 

Width of the frames in the video stream.

CAP_PROP_FRAME_HEIGHT 

Height of the frames in the video stream.

CAP_PROP_FPS 

Frame rate.

CAP_PROP_FOURCC 

4-character code of codec. see VideoWriter::fourcc .

CAP_PROP_FRAME_COUNT 

Number of frames in the video file.

CAP_PROP_FORMAT 

Format of the Mat objects returned by VideoCapture::retrieve().

CAP_PROP_MODE 

Backend-specific value indicating the current capture mode.

CAP_PROP_BRIGHTNESS 

Brightness of the image (only for cameras).

CAP_PROP_CONTRAST 

Contrast of the image (only for cameras).

CAP_PROP_SATURATION 

Saturation of the image (only for cameras).

CAP_PROP_HUE 

Hue of the image (only for cameras).

CAP_PROP_GAIN 

Gain of the image (only for cameras).

CAP_PROP_EXPOSURE 

Exposure (only for cameras).

CAP_PROP_CONVERT_RGB 

Boolean flags indicating whether images should be converted to RGB.

CAP_PROP_WHITE_BALANCE_BLUE_U 

Currently unsupported.

CAP_PROP_RECTIFICATION 

Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently).

CAP_PROP_MONOCHROME  
CAP_PROP_SHARPNESS  
CAP_PROP_AUTO_EXPOSURE 

DC1394: exposure control done by camera, user can adjust reference level using this feature.

CAP_PROP_GAMMA  
CAP_PROP_TEMPERATURE  
CAP_PROP_TRIGGER  
CAP_PROP_TRIGGER_DELAY  
CAP_PROP_WHITE_BALANCE_RED_V  
CAP_PROP_ZOOM  
CAP_PROP_FOCUS  
CAP_PROP_GUID  
CAP_PROP_ISO_SPEED  
CAP_PROP_BACKLIGHT  
CAP_PROP_PAN  
CAP_PROP_TILT  
CAP_PROP_ROLL  
CAP_PROP_IRIS  
CAP_PROP_SETTINGS  
CAP_PROP_BUFFERSIZE 

Pop up video/camera filter dialog (note: only supported by DSHOW backend currently. Property value is ignored)

CAP_PROP_AUTOFOCUS 

  • 12
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值