我必须读取一个本地的.avi文件,并使它shaw在一个window.Here上是我的代码:
import os,cv2
user=os.path.expanduser('~')
capture=cv2.VideoCapture(str(user)+"/Downloads/vehicle/Sunny/april21.avi")
if(capture.isOpened()):
print "Open"
else:
print "Fail to open!"
fps=capture.get(cv2.CAP_PROP_FPS)
fourcc=capture.get(cv2.CAP_PROP_FOURCC)
print fourcc#why fourcc is return 0.0?
print "fps:%d"%fps
size=(int(capture.get(cv2.CAP_PROP_FRAME_WIDTH))/2,
(int)(capture.get(cv2.CAP_PROP_FRAME_HEIGHT))/2
)
isStop=1
while isStop:
grabbed,frame=capture.read()#frame is None
cv2.namedWindow("window")
img=cv2.resize(frame,size,interpolation=cv2.INTER_CUBIC)
cv2.imshow("window",img)
c=0xFF&cv2.waitKey(1)
if c ==27:
isStop=False
cv2.destroyAllWindows()但现在的结果是:
Open
0.0
fps:29
OpenCV Error: Assertion failed (ssize.area() > 0) in resize, file /Users/tom/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp, line 3229
Traceback (most recent call last):
File "/Users/tom/Documents/readVideo.py", line 20, in <module>
img=cv2.resize(frame,size,interpolation=cv2.INTER_CUBIC)
cv2.error: /Users/tom/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp:3229: error: (-215) ssize.area() > 0 in function resize我唯一确定的是这些代码是正确的,因为我已经通过cv2.VideoWriter创建了一个.avi文件,它可以被读取并显示在窗口上。谢谢你的回答。
发布于 2016-05-30 21:29:56
OpenCV返回的数据类型很可能是一个双精度型(浮点),它的任意内容(FOURCC码)是无效的(不符合IEEE )。
我不懂Python,但是下面的C/C++代码片段可以完成这项工作:
union {
char c[5];
int i;
} myfourcc;
myfourcc.i = capture.get(CV_CAP_PROP_FOURCC);
myfourcc.c[4] = '\0';
std::cout << "4cc:" << myfourcc.c << std::endl;我猜Python有一种比ctype更惯用的方式。只有我的便士。
https://stackoverflow.com/questions/36112147
复制相似问题