简体   繁体   English

类型错误:颜色必须是整数或元组

[英]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.

相关问题 TypeError:int()参数必须是字符串或数字,而不是&#39;tuple&#39; - TypeError: int() argument must be a string or a number, not 'tuple' Python PIL putdata 颜色必须是整数或元组 - Python PIL putdata color must be int or tuple 运行代码返回“color must int or tuple” - Running code returns with “color must int or tuple” TypeError:int()参数必须是字符串或数字,而不是使用ouchdb-python的“元组” - TypeError: int() argument must be a string or a number, not 'tuple' with couchdb-python TypeError:“ int”对象不可下标,然后转换为字符串时TypeError:元组索引必须为整数,而不是str - TypeError: 'int' object is not subscriptable then when converted to string TypeError: tuple indices must be integers, not str Numpy TypeError 必须是整数,而不是元组 - Numpy TypeError must be integer, not tuple TypeError:必须为str not int - TypeError: Must be str not int 类型错误:将形状转换为 TensorShape 时出错:int() 参数必须是字符串、类似字节的对象或数字,而不是“元组”。 在蟒蛇 - TypeError: Error converting shape to a TensorShape: int() argument must be a string, a bytes-like object or a number, not 'tuple'. in python 类型错误:只能将元组(不是“int”)连接到元组 - TypeError: can only concatenate tuple (not “int”) to tuple 类型错误:将形状转换为 TensorShape 时出错:int() 参数必须是字符串或数字,而不是“元组” - TypeError: Error converting shape to a TensorShape: int() argument must be a string or a number, not 'tuple'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM