非类型对象出现时 phash 中断

phash breaks when nonetype object apears

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(folder, file))" 出于某种原因返回为 none,因为下一个分配给出了 none 类型错误,但只有当所有子文件夹都是 运行宁。仅在发生错误的子文件夹上将其更改为 运行; 运行没问题。我最困惑的是 returns 在如此微小的变化上有所不同。

在 Windows 路径名中使用反斜杠时,请转义它们或使用原始字符串:

path = "C:\cardscryer\CardScryer-master\pictures"

path = r"C:\cardscryer\CardScryer-master\pictures"