OpenCV 2.4 - 在OSX上播放文件中的视频

时间:2016-06-29 03:10:17

标签: python c++ macos opencv computer-vision

我使用brew

安装Open CV和所有deps

遵循本教程:

http://docs.opencv.org/3.1.0/dd/d43/tutorial_py_video_display.html#gsc.tab=0

我能够使用我的网络摄像头但无法读取AVI或MP4文件。每次执行此命令时:

ret, frame = cap.read()frameNone

Python 2.7.10 (default, Sep 23 2015, 04:34:14) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'2.4.12'`

这是脚本:

import cv2
cap = cv2.VideoCapture('drop.avi')

while cap.isOpened():
    ret, frame = cap.read() # frame is ALWAYS None.
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame', gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

可以尝试使用python和ffmpeg支持重新安装opencv

brew install opencv --with-ffmpeg -v

但在此之前安装perian

http://www.perian.org/