INNER CODE UNIT · Python
paste_back_frame
Tencent-Hunyuan/HunyuanPortrait · inference.py:49
def paste_back_frame(original_img, generated_crop, crop_bbox, mask=None):
"""
paste the generated cropped frame back to the original image
original_img: original image numpy array
generated_crop: generated 512x512 face frame
crop_bbox: [x1, y1, x2, y2]
"""
x1, y1, x2, y2 = crop_bbox
target_w = x2 - x1
target_h = y2 - y1
# 1. resize the generated face back to the size of the original crop box
generated_resized = cv2.resize(generated_crop, (target_w, target_h))
# 2. if no mask is provided, create a new one
if mask is None:
mask = create_soft_mask((target_w, target_h))