gpt4 book ai didi

python - opencv `cv2` python 模块中缺少 CAP_PROP_FRAME_COUNT 常量

转载 作者:太空狗 更新时间:2023-10-29 19:31:35 26 4
gpt4 key购买 nike

如何在 python 中从 opencv 访问 CAP_PROP_FRAME_COUNT?我试过这个:

import cv2
cap = cv2.VideoCapture('myvideo.avi')
frames_count, fps, width, height = cap.get(cv2.CAP_PROP_FRAME_COUNT), cap.get(cv2.CAP_PROP_FPS), cap.get(cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

还有这个:

import cv2
import cv
cap = cv2.VideoCapture('myvideo.avi')
frames_count, fps, width, height = cap.get(cv.CAP_PROP_FRAME_COUNT), cap.get(cv.CAP_PROP_FPS), cap.get(cv.CAP_PROP_FRAME_WIDTH), cap.get(cv.CAP_PROP_FRAME_HEIGHT)

还有这个:

import cv2
cap = cv2.VideoCapture('myvideo.avi')
frames_count, fps, width, height = cap.get(cv2.cv.CAP_PROP_FRAME_COUNT), cap.get(cv2.cv.CAP_PROP_FPS), cap.get(cv2.cv.CAP_PROP_FRAME_WIDTH), cap.get(cv2.cv.CAP_PROP_FRAME_HEIGHT)

但是我收到了这个错误:

AttributeError: 'module' object has no attribute 'CAP_PROP_FRAME_COUNT'

我正在使用 python 2.7.5OpenCV 2.4.9

最佳答案

第一版 OpenCV python 模块中的常量有一个 CV_ 前缀。因此,您可以使用 cv.CV_CAP_PROP_FRAME_COUNTcv2.cv.CV_CAP_PROP_FRAME_COUNT

关于python - opencv `cv2` python 模块中缺少 CAP_PROP_FRAME_COUNT 常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26559179/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com