这是我的代码
import cv2
video_capture = cv2.VideoCapture("test.mpeg")
cv2.convertMaps
while True:
# get frame by frame
ret, frame = video_capture.read()
cv2.imwrite('pic.png',frame)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
我收到以下错误:
None
Traceback (most recent call last):
File "D:/Itellingence Transportation Systems/Material-lab8/home_work8.py", line 12, in <module>
cv2.imshow('Video', frame)
error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow
有什么问题?
答案 0 :(得分:0)
简单的回答,我相信。您的循环在视频完成时无法检测到任何内容。最终,在尝试阅读时,video_capture对象将返回False。您应该在循环中检查该条件是否正常退出。
import cv2
video_capture = cv2.VideoCapture("test.mpeg")
while True:
# get frame by frame
ret, frame = video_capture.read()
if not ret:
break
cv2.imwrite('pic.png',frame)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break