【发布时间】:2018-04-23 12:03:36
【问题描述】:
我在让 OpenCV 2.4.9 使用 python 读取(和显示)视频文件时遇到问题。我知道查找文件不是问题,因为我能够让cv2.imread() 从同一目录中读取图像。这绝对是cv2.VideoCapture() 的问题。这是我得到的代码和输出:
import cv2
import numpy as np
testvid = cv2.VideoCapture('testvid.avi')
while(1):
ret, frame = testvid.read()
print ret
cv2.imshow('frame',frame)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
testvid.release()
cv2.destroyAllWindows()
输出:
False
error: C:\pisi\tmp\opencv-2.4.9-5\work\opencv-2.4.9\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\pisi\tmp\opencv-2.4.9-5\work\opencv-2.4.9\modules\highgui\src\window.cpp, line 261
我知道有几个人遇到过同样的问题。 This thread 和 this tread 都通过说您必须重命名 opencv_ffmpeg.dll 文件以适合您的版本并将其复制到路径中的主 python 目录或目录(或类似的东西)来解决这个问题。
但是,我通过 Enthought 使用 Python 2.7.13(由我的教授推荐),库和包的设置路径和方式似乎与其他线程中的完全不同。 Enthought 使用了一个包管理器,它会自动为我下载和设置 OpenCV。没有 Python 目录。一切都是通过Enthought。经过一番挖掘,我找到了所有 OpenCV .dll 所在的位置,包括 opencv_ffmpeg249_64.dll:
C:\Users\USERNAME\AppData\Local\Enthought\Canopy\edm\pkgs\03\9d58e152b8f411718220c30639b8448585cb7d9a82de662c7e34b35d9ec1f6
那我该怎么办呢?我在哪里复制 .dll? .dll 甚至是这里的问题吗?我已经尝试了很多东西,包括将它复制到各种地方并重命名.dll,但没有任何效果。救命!
【问题讨论】:
标签: python python-2.7 opencv video-capture enthought