1.读取视频man.avi,
报错。
我的视频和文件在同一目录下.
#coding=utf-8
import numpy as np
import cv2
cap = cv2.VideoCapture('man.avi')
while(cap.isOpened()):
# 从摄像头读取一帧,ret是表明成功与否
ret, frame = cap.read()
if ret:
#处理得到的帧,这里将其翻转
frame = cv2.flip(frame,0)
cv2.imshow('frame',frame)
else:
break
# 监听键盘,按下q键退出
if cv2.waitKey(25) & 0xFF == ord('q'):
break
##释放
cap.release()
cv2.destroyAllWindows()
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\build\master_winpack-bindings-win32-vc14-static\opencv\modules\highgui\src\window.cpp, line 325
Traceback (most recent call last):
File "C:/PycharmProjects11/day5 ����/2 MOG2��ϸ�˹ģ��.py", line 18, in <module>
cv2.imshow('frame',fgmask)
cv2.error: C:\build\master_winpack-bindings-win32-vc14-static\opencv\modules\highgui\src\window.cpp:325: error: (-215) size.width>0 && size.height>0 in function cv::imshow
2. 有些博客写的是绝对路径
#-*- coding:utf-8 -*- import cv2
import numpy as np
from matplotlib import pyplot as plt #1.读入avi对象
cap = cv2.VideoCapture('C:\\PycharmProjects11\\video\\people.avi') #2.视频有多少秒
fps = cap.get(cv2.CAP_PROP_FPS)
print fps #3.视频的width,height
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print size
显示根本没有读取进来视频
无效
3.缺少ffmpeg.dll文件
参考博客:http://blog.csdn.net/djcxym/article/details/52177220
解决方案:(亲测可行),
如果获取失败的话,可能是因为缺少ffmpeg的dll,
搜索文件用Everything(推荐),下载地址:https://www.so.com/s?ie=utf-8&src=360se7_addr&q=Everything
把opencv目录下的ffmepg.dell文件复制到python27目录下
我的是:C:\opencv\build\bin到C:\Python27
4.重新执行程序成功