TypeError:颜色必须为int或tuple

2022-01-19 00:11:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将opencv face_cascade检测到的人脸排列在联系人表中。下面的代码产生了这个错误:“TypeError:color必须是int或tuple”,它可以追溯到下面的最后一行。有人知道是什么导致了这个错误吗

contact_sheet_size = (640, height * 128)
contact_sheet = Image.new(mode ='RGB', size = contact_sheet_size)
x, y = 0, 0
for face in faces_detect:
    cropped = resized_images[image_no].crop(box = (face[0], face[1], face[2], face[3]))
    contact_sheet.paste(cropped.thumbnail(size = (128, 128)), (x, y))

调整大小的_图像是PIL.images.Image的

完全回溯:

Traceback (most recent call last):
  File "../approach.py", line 147, in <module>
    contact_sheet.paste(cropped.thumbnail(size = (128, 128)), (x, y, 128, 128))
  File "..\venv\lib\site-packages\PIL\Image.py", line 1506, in paste
    self.im.paste(im, box)
TypeError: color must be int or tuple