断言失败:size.width>0 &&函数 imshow 中的 size.height>0 [英] Assertion failure : size.width>0 && size.height>0 in function imshow

查看:29
本文介绍了断言失败:size.width>0 &&函数 imshow 中的 size.height>0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在树莓派上使用 opencv2 和 python.我是 python 和 opencv 的新手.我尝试读取 jpeg 图像并显示图像,但显示以下错误:

i am using opencv2 and python on raspberry pi. and i am new with python and opencv. i tried to read a jpeg image and display image it shows the following error:

/home/pi/opencv-2.4.9/modules/highgui/src/window.cpp:269: 
  error: (-215) size.width>0 &&  size.height>0 in function imshow.

代码是:

import cv2
# windows to display image
cv2.namedWindow("Image")
# read image
image = cv2.imread('home/pi/bibek/book/test_set/bbb.jpeg')
# show image
cv2.imshow("Image", image)
# exit at closing of window
cv2.waitKey(0)
cv2.destroyAllWindows()

推荐答案

图像加载失败(可能是因为您忘记了路径中的前导 /).imread 然后返回 None.将 None 传递给 imshow 会导致它尝试创建一个大小为 0x0 的窗口,但失败了.

The image fails to load (probably because you forgot the leading / in the path). imread then returns None. Passing None to imshow causes it to try to create a window of size 0x0, which fails.

cv 中糟糕的错误处理可能归因于它在 C++ 实现上的非常薄的包装层(其中错误返回 NULL 是一种常见做法).

The poor error handling in cv probably owes to its quite thin wrapper layer on the C++ implementation (where returning NULL on error is a common practice).

这篇关于断言失败:size.width>0 &&函数 imshow 中的 size.height>0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆