当非类型对象出现时,phash会中断

时间:2015-11-17 06:14:15

标签: python python-imaging-library nonetype phash

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,因为下一个赋值会产生非类型错误,但只有在所有子文件夹都在运行时才会中断。将其更改为仅在发生错误的子文件夹上运行;它运行正常。我对这种微小变化的回报不同感到困惑。

1 个答案:

答案 0 :(得分:0)

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

iResult=send(sock,*c, (int)strlen(*c),0);
*c[0] = 0;

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