OpenCV 打开文件错误(Assertion failed)

OpenCV opening file error (Assertion failed)

处理这段代码时,OpenCV 给我错误:

OpenCV 错误:断言失败 (size.width>0 && size.height>0) cv::imshow,文件 C:\bld\opencv_1498174012660\work\opencv-3.2。 0\modules\highgui\src\window.cpp,第 304 行

回溯(最近调用最后):

文件 "C:/Users/User/Desktop/Flow/FlowP/detect-extration - temp.py",第 34 行,在

cv2.imshow('win',img)

cv2.error: C:\bld\opencv_1498174012660\work\opencv-3.2.0\modules\highgui\src\window.cpp:304: 错误: (-215) size.width>0 && size.height>0 函数 cv::imshow

now = datetime.now()
id_folder = now.strftime('%Y%m%d-%H%M%S-%f')

b_temp = ('C:\Users\User\Desktop\b_temp\' + id_folder)
os.makedirs(b_temp, exist_ok=True)


src = ('C:\Users\User\Desktop\Images\')
files = os.listdir(src)
print(files)


shutil.move(str(src + str(files[0])),b_temp)


img = cv2.imread('C:\Users\User\Desktop\b_temp\' + id_folder + '.tif')
print(img)
cv2.imshow('win', img)
cv2.waitKey(0)

它可能是什么?所有模块都正确导入,代码似乎可以工作,直到第一个 OpenCV 指令...

编辑:据我所见,它无法识别目录中的文件...但是文件存在,是否存在...

外观如下:

我解决了。这是正确答案...

img = cv2.imread('C:\Users\User\Desktop\b_temp\' + id_folder + '\' + str(files[0]))