import os, cv2, imagehash, PIL
hashList = []
path = "C:\cardscryer\CardScryer-master\pictures"
folderList = os.listdir(path)
print(folderList)
os.chdir(path)
for folder in folderList:
fileList = os.listdir(folder)
for file in fileList:
cardImage = cv2.imread(os.path.join(folder, file))
cropImage = cardImage[15:200, 20:420]
hash = imagehash.phash(PIL.Image.fromarray(cropImage))
file = file.replace('.jpg','')
print(file)
hashList.append([file[:-4], folder, hash])
我认为“cv2.imread(os.path.join(文件夹,文件))”由于某种原因返回为无,因为下一个分配给出了一个无类型错误,但它仅在所有子文件夹都运行时才会中断。将其更改为仅在发生错误的子文件夹上运行;它运行良好。我最困惑的是,如此微小的变化带来的回报却不同。