TypeError: int() argument must be a string, a bytes-like object or a number, not ‘dict’
I am passing colors into function
def apply_virtual_foundation(image,color,opacity):
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = face_mesh.process(image_rgb)
if results.multi_face_landmarks:
for face_landmarks in results.multi_face_landmarks:
h, w, _ = image.shape
landmarks = [(int(pt.x * w), int(pt.y * h)) for pt in face_landmarks.landmark]
outer_lip_indices = [61, 185, 40, 39, 37, 0, 267, 269, 270, 409, 291]
inner_lip_indices = [146, 91, 181, 84, 17, 314, 405, 321, 375]
lip_landmarks = [landmarks[i] for i in outer_lip_indices + inner_lip_indices]
landmarks = [pt for i, pt in enumerate(landmarks) if i not in outer_lip_indices + inner_lip_indices]
points = np.array(landmarks, dtype=np.int32)
hull = cv2.convexHull(points)
mask = np.zeros((h, w), dtype=np.uint8)
cv2.fillConvexPoly(mask, hull, 255)
kernel_height = 70
kernel_width = 20
kernel = np.ones((kernel_height, kernel_width), np.uint8)
mask = cv2.dilate(mask, kernel, iterations=1)
mask = cv2.GaussianBlur(mask, (31, 31), 0)
distance_transform = cv2.distanceTransform(mask, cv2.DIST_L2, 3)
max_dist = distance_transform.max()
gradient_mask = cv2.normalize(distance_transform, None, 0, 0.4, cv2.NORM_MINMAX)
gradient_mask = gradient_mask ** 0.9
gradient_mask = (gradient_mask * 255).astype(np.uint8)
foundation_overlay = np.full((h, w, 3), color, dtype=np.uint8)# This line give error as color dictionary do not pass directly
foundation_overlay = cv2.bitwise_and(foundation_overlay, foundation_overlay, mask=mask)
alpha = gradient_mask / 255.0
alpha = alpha * opacity
alpha = np.clip(alpha, 0, 1)
alpha = alpha[…, np.newaxis]
foundation_overlay = alpha * foundation_overlay + (1 – alpha) * image
return foundation_overlay.astype(np.uint8)
return image
def get_color_for_foundation(choice=None):
color_map = {
“1”: (129, 137, 238),
“2”: (204,207,251),
“3”: (158,193,236),
“4”: (182,196,222),
“5”: (155,165,208),
“6”: (113,167,225),
“7”: (130,156,219),
“8”: (51,93,152),
“9”: (22,49,100),
“10”: (40,60,95),
“11”: (6,25,60)
}
if choice:
return color_map.get(choice, (129, 137, 238))
return color_map
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘dict’
I am passing colors into function
def apply_virtual_foundation(image,color,opacity):
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = face_mesh.process(image_rgb)
if results.multi_face_landmarks:
for face_landmarks in results.multi_face_landmarks:
h, w, _ = image.shape
landmarks = [(int(pt.x * w), int(pt.y * h)) for pt in face_landmarks.landmark]
outer_lip_indices = [61, 185, 40, 39, 37, 0, 267, 269, 270, 409, 291]
inner_lip_indices = [146, 91, 181, 84, 17, 314, 405, 321, 375]
lip_landmarks = [landmarks[i] for i in outer_lip_indices + inner_lip_indices]
landmarks = [pt for i, pt in enumerate(landmarks) if i not in outer_lip_indices + inner_lip_indices]
points = np.array(landmarks, dtype=np.int32)
hull = cv2.convexHull(points)
mask = np.zeros((h, w), dtype=np.uint8)
cv2.fillConvexPoly(mask, hull, 255)
kernel_height = 70
kernel_width = 20
kernel = np.ones((kernel_height, kernel_width), np.uint8)
mask = cv2.dilate(mask, kernel, iterations=1)
mask = cv2.GaussianBlur(mask, (31, 31), 0)
distance_transform = cv2.distanceTransform(mask, cv2.DIST_L2, 3)
max_dist = distance_transform.max()
gradient_mask = cv2.normalize(distance_transform, None, 0, 0.4, cv2.NORM_MINMAX)
gradient_mask = gradient_mask ** 0.9
gradient_mask = (gradient_mask * 255).astype(np.uint8)
foundation_overlay = np.full((h, w, 3), color, dtype=np.uint8)# This line give error as color dictionary do not pass directly
foundation_overlay = cv2.bitwise_and(foundation_overlay, foundation_overlay, mask=mask)
alpha = gradient_mask / 255.0
alpha = alpha * opacity
alpha = np.clip(alpha, 0, 1)
alpha = alpha[…, np.newaxis]
foundation_overlay = alpha * foundation_overlay + (1 – alpha) * image
return foundation_overlay.astype(np.uint8)
return image
def get_color_for_foundation(choice=None):
color_map = {
“1”: (129, 137, 238),
“2”: (204,207,251),
“3”: (158,193,236),
“4”: (182,196,222),
“5”: (155,165,208),
“6”: (113,167,225),
“7”: (130,156,219),
“8”: (51,93,152),
“9”: (22,49,100),
“10”: (40,60,95),
“11”: (6,25,60)
}
if choice:
return color_map.get(choice, (129, 137, 238))
return color_map