无法使用OpenCV在Python中打开视频文件 [英] Unable to open Video File in Python using OpenCV

查看:142
本文介绍了无法使用OpenCV在Python中打开视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Windows 7(32位)中安装了OpenCV,并将cv2.pyd文件放入Python Modules Directory中,并且一切正常,但是除了打开视频文件{我已经尝试了5-6种不同类型的扩展名,但是没有正在帮助} 代码::

I have installed OpenCV in Windows 7 (32 bit) and Put the cv2.pyd file in Python Modules Directory and everything is working just fine but except opening of Video file {I have tried 5-6 different kind of extensions but nothing is helping} CODE::

import numpy as np
import cv2
cap = cv2.VideoCapture('vtest.avi')
while(cap.isOpened()):
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

cap.isOpened()行始终返回False {我也尝试提供视频文件的绝对路径},但也返回false 因此,请任何人帮助我,为什么该行总是返回False

the line cap.isOpened() always returns False {i also tried providing absolute path to the video file} but that too return false So please can please anybody help me that why that line is always returning False

推荐答案

我发现解决方案C:\opencv\sources\3rdparty\ffmpeg\opencv_ffmpeg.dll中存在一个文件,只需将该文件复制并粘贴到您的Python基本目录中并说C:\Python\opencv_ffmpeg.dll并重命名该文件到您正在使用的OpenCV版本,例如我的v3.0.0,因此我必须将其重命名为C:\Python\opencv_ffmpeg300.dll 如果您的系统是X64,则还要在末尾添加_64,如C:\Python\opencv_ffmpeg300_64.dll

I have found the solution there is a file present in C:\opencv\sources\3rdparty\ffmpeg\opencv_ffmpeg.dll just Copy and Paste that file into your Python base directory say C:\Python\opencv_ffmpeg.dll and rename the file to the version of the OpenCV you are using like in my case its v3.0.0 so i have to rename it as C:\Python\opencv_ffmpeg300.dll if your system is X64 then also add _64 at the end like C:\Python\opencv_ffmpeg300_64.dll

这篇关于无法使用OpenCV在Python中打开视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆