简体   繁体   中英

OpenCV 2.4 - Playing Video from file on OSX

I install Open CV and all the deps with brew

Following this tutorial:

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

I'm able to have it working with my webcam but unable to read a AVI or MP4 file. Every time, when I execute this command:

ret, frame = cap.read() , frame is None .

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'`

Here is the script:

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

Thanks in advance for your help!

May be try reinstalling opencv with python and ffmpeg support

brew install opencv --with-ffmpeg -v

But before that install perian

http://www.perian.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM