【问题标题】:Opencv-Python cv2.CV_CAP_PROP_FPS errorOpencv-Python cv2.CV_CAP_PROP_FPS 错误
【发布时间】:2017-07-20 13:10:29
【问题描述】:

我目前使用的是 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'

谁能告诉我该怎么做?

【问题讨论】:

    标签: python opencv


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      Eshiima 的回答解决了这个问题。 但仅供参考,我想向您展示另一种执行这些操作的方法,如文档中所述: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))
      

      【讨论】:

        猜你喜欢
        • 2016-11-28
        • 1970-01-01
        • 1970-01-01
        • 2018-05-20
        • 1970-01-01
        • 1970-01-01
        • 2016-10-13
        • 2019-02-28
        • 1970-01-01
        相关资源
        最近更新 更多