我正在尝试使用imread
在Python 2.7中读取图像。以下是我的代码。
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
时,它正确打印。当我使用任何实际文件名而不是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
输入的路径中包含变量?我在阅读here
后尝试了上述代码答案 0 :(得分:0)
你似乎有太多的引号。试试这个:
img = cv2.imread('../Caltech Data 200-2011/CUB_200_2011/images/%s' % (x))