Opencv-Python cv2.CV_CAP_PROP_FPS错误

时间:2017-07-20 13:10:30

标签: python opencv

我目前正在使用opencv 3.2.0和python 3.5.2。执行以下代码时:

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)))

我遇到了以下错误:

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'

有谁能告诉我应该做什么?

2 个答案:

答案 0 :(得分:20)

在OpenCV 3.2中,将CV放在标志前面。 这应该可以正常工作

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)))

答案 1 :(得分:2)

Eshirima的回答解决了这个问题。 但仅供参考,我想向您展示执行文档中提到的这些操作的另一种方法:https://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-get

videoCapture = cv2.VideoCapture(file_path)
width  = int(videoCapture.get(3))
height = int(videoCapture.get(4))
fps = int(videoCapture.get(5))