TypeError: color must be int or tuple

Viewed 3919

I'm trying to arrange faces detected by opencv face_cascade in a contact sheet. The following code produces this error: "TypeError: color must be int or tuple", which traces to the last line below. Does anyone know what's causing this error?

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))

The resized_images are PIL.Images.Image's.

Full traceback:

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
1 Answers

I had a similar case. Probably the point is that you need to use the native int instead numpy.int. Try yourdata[i][j].item() to remove numpy wrapper

Related