为什么我得到一个 NoneType?

Why am I getting a NoneType?

谁能看出我错在哪里?我一行一行地检查它,直到 new_face,当 new_face 开始生成 NoneType 时,它​​都会产生预期的结果。

import numpy, cv2
from PIL import Image

face_cascade = cv2.CascadeClassifier("..data/haarcascade_frontalface_default.xml") #absolute path cut down for privacy

def find_faces(image_for_faces):
    image = image_for_faces.resize((1800,3150))
    image_np = numpy.asarray(image)
    image_gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(image_gray) #correct numpy array, prints correct coordinates per face
    face_list = []
    image.show()
    for face in faces:
        print(face)
        box = (face[0], face[1], face[0]+face[2], face[1]+face[3]) #correctly produces numpy coordinates
        copy_image = image.copy()
        cropped = copy_image.crop(box = (box))
        new_face = cropped.thumbnail((128,128))
        face_list.append(new_face)
    return face_list

y = Image.open('famphoto.jpg')
z = y.convert('RGB')
x = find_faces(z)

Image.thumbnail() 修改 Image 对象,在 docs 中阅读更多相关信息。它提到它 returns 是 None 类型。

Image.thumbnail:

Make this image into a thumbnail. This method modifies the image to contain a thumbnail version of itself, no larger than the given size. This method calculates an appropriate thumbnail size to preserve the aspect of the image, calls the draft() method to configure the file reader (where applicable), and finally resizes the image.