[英]error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
For below code I am getting Assertion failed error as highlighted in title.对于下面的代码,我收到标题中突出显示的断言失败错误。
cap = cv2.VideoCapture('vtest.avi')
ret, frame = cap.read()
cv2.imshow("Feed", frame)
while cap.isOpened():
ret, frame = cap.read()
cv2.imshow("Feed", frame)
Error - cv2.error: OpenCV(4.1.1) /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
In order to remove the path as suspect - video is same folder where I am code.为了删除可疑路径 - 视频与我所在的代码所在的文件夹相同。 I verified the path by replacing with image and it works fine.我通过用图像替换来验证路径并且它工作正常。
I also verified I am able to open the video.我还验证了我能够打开视频。 Since I am on Mac - I tried with VLC and even converted the format to.mp4 for it support default quicktime player but still same error.由于我使用的是 Mac - 我尝试使用 VLC,甚至将格式转换为 .mp4,因为它支持默认的 quicktime 播放器,但仍然出现同样的错误。 If I just try to get image from video I do first frame - I have commented that code above.如果我只是尝试从视频中获取图像,我会先做第一帧——我已经在上面评论了该代码。
If I try below set of code如果我尝试下面的代码集
while cap.isOpened():
ret, frame = cap.read()
if ret == True:
cv2.imshow("Feed", frame)
I no longer see above assertion failed error but the feed frame window opens and just hangs我不再看到上面的断言失败错误,但提要框架窗口打开并挂起
I see it as common error when video or file is not available for being read by cv2.imshow().当视频或文件不可用于 cv2.imshow() 读取时,我将其视为常见错误。 I went through quite a few suggestions given around this in SO but somehow nothing worked for me.我在 SO 中通过了很多关于此的建议,但不知何故对我没有任何帮助。
You need to add你需要添加
if cv2.waitKey(1) & 0xFF == ord('q'):
break
after cv2.imshow()
.在cv2.imshow()
之后。 I've encountered the same issue before, and adding that worked for me.我以前遇到过同样的问题,添加它对我有用。
For below code I am getting Assertion failed error as highlighted in title.对于下面的代码,我收到了标题中突出显示的 Assertion failed 错误。
cap = cv2.VideoCapture('vtest.avi')
ret, frame = cap.read()
cv2.imshow("Feed", frame)
while cap.isOpened():
ret, frame = cap.read()
cv2.imshow("Feed", frame)
Error - cv2.error: OpenCV(4.1.1) /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
In order to remove the path as suspect - video is same folder where I am code.为了删除可疑路径 - 视频与我所在的代码文件夹相同。 I verified the path by replacing with image and it works fine.我通过替换图像验证了路径,它工作正常。
I also verified I am able to open the video.我还验证了我可以打开视频。 Since I am on Mac - I tried with VLC and even converted the format to.mp4 for it support default quicktime player but still same error.由于我在 Mac 上 - 我尝试使用 VLC,甚至将格式转换为 .mp4,因为它支持默认的 quicktime 播放器,但仍然出现相同的错误。 If I just try to get image from video I do first frame - I have commented that code above.如果我只是尝试从视频中获取图像,我会做第一帧 - 我已经在上面评论了该代码。
If I try below set of code如果我尝试下面的代码集
while cap.isOpened():
ret, frame = cap.read()
if ret == True:
cv2.imshow("Feed", frame)
I no longer see above assertion failed error but the feed frame window opens and just hangs我不再看到上述断言失败错误,但馈送框架 window 打开并挂起
I see it as common error when video or file is not available for being read by cv2.imshow().当 cv2.imshow() 无法读取视频或文件时,我将其视为常见错误。 I went through quite a few suggestions given around this in SO but somehow nothing worked for me.我在 SO 中提出了很多关于这个问题的建议,但不知何故对我没有任何帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.