Python OpenCV3 VideoCapture读取视频文件失败解决方案

问题描述

环境:Windows 7、Python2.7、OpenCV3.2、Miniconda2
如下代码不能打开视频:

def playing_video_from_file():
    # videocv2.VideoWriter_fourcc(*'mp4v')
    videoCapture = cv2.VideoCapture()

    videoCapture.open("../videos/movie.avi")
    # 获得码率及尺寸
    fps = videoCapture.get(cv2.CAP_PROP_FPS)
    size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),
            int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))

    print size
    # 指定写视频的格式, I420-avi, MJPG-mp4
    videoWriter = cv2.VideoWriter('./output/MyOutputVid.avi',
                                  cv2.VideoWriter_fourcc('I', '4', '2', '0'),
                                  fps, size)

    # 读帧
    success, frame = videoCapture.read()
    while success:  # Loop until there are no more frames.
        cv2.imshow("show window", frame)  # 显示
        cv2.waitKey(1000 / int(fps))  # 延迟
        videoWriter.write(frame)  # 写视频帧
        success, frame = videoCapture.read()  # 获取下一帧

    # When everything done, release the capture
    videoCapture.release()
    cv2.destroyAllWindows()

解决方案

复制 OpenCV 安装路径下的 D:\opencv_3_2\opencv\build\x64\vc14\bin\下的所有动态链接库文件到Python 安装的路径下/Miniconda2的安装路径下:


Python OpenCV3 VideoCapture读取视频文件失败解决方案_第1张图片

你可能感兴趣的:(图像处理)