我正在尝试使用 Python 2.7 读取图像imread
。下面是我的代码。
with open('../Caltech Data 200-2011/CUB_200_2011/images.txt') as lines:
for ln in islice(lines,60):
j=0
for x in ln.split():
if j==1:
print x,
#Below is the line that is causing trouble
img = cv2.imread('../Caltech Data 200-2011/CUB_200_2011/images/"%s"' % (x))
cv2.imshow('Image',img)
cv2.waitKey()
j=j+1
上面的代码不起作用。当我打印变量x
时,它打印正确。当我使用任何实际文件名而不是变量 in 时imread
,它正在读取图像并显示它。但是在使用变量时,它没有读取图像并显示以下错误。
error: C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\highgui\src\window.cpp:271: error: (-215) size.width>0 && size.height>0 in function cv::imshow
- 我究竟做错了什么?
- 有没有其他方法可以在作为输入的路径中包含变量
imread
?
从这里阅读后,我尝试了上面的代码