[英]TypeError: color must be int or tuple
I'm trying to arrange faces detected by opencv face_cascade in a contact sheet.我正在尝试在联系表中排列由 opencv face_cascade 检测到的人脸。 The following code produces this error: "TypeError: color must be int or tuple", which traces to the last line below.以下代码产生此错误:“TypeError: color must be int or tuple”,跟踪到下面的最后一行。 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. resized_images 是 PIL.Images.Image 的。
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
I had a similar case.我有一个类似的案例。 Probably the point is that you need to use the native int instead numpy.int.可能关键是您需要使用本机 int 而不是 numpy.int。 Try yourdata[i][j].item() to remove numpy wrapper尝试 yourdata[i][j].item() 删除 numpy 包装器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.