断言失败: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
传递给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).