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