mirror of
https://github.com/TMElyralab/MuseTalk.git
synced 2026-02-04 09:29:20 +08:00
improve blending speed
This commit is contained in:
@@ -85,16 +85,15 @@ def get_image_prepare_material(image,face_box,upper_boundary_ratio = 0.5,expand=
|
|||||||
return mask_array,crop_box
|
return mask_array,crop_box
|
||||||
|
|
||||||
def get_image_blending(image,face,face_box,mask_array,crop_box):
|
def get_image_blending(image,face,face_box,mask_array,crop_box):
|
||||||
body = Image.fromarray(image[:,:,::-1])
|
body = image
|
||||||
face = Image.fromarray(face[:,:,::-1])
|
|
||||||
|
|
||||||
x, y, x1, y1 = face_box
|
x, y, x1, y1 = face_box
|
||||||
x_s, y_s, x_e, y_e = crop_box
|
x_s, y_s, x_e, y_e = crop_box
|
||||||
face_large = body.crop(crop_box)
|
face_large = copy.deepcopy(body[y_s:y_e, x_s:x_e])
|
||||||
|
face_large[y-y_s:y1-y_s, x-x_s:x1-x_s]=face
|
||||||
|
|
||||||
mask_image = Image.fromarray(mask_array)
|
mask_image = cv2.cvtColor(mask_array,cv2.COLOR_BGR2GRAY)
|
||||||
mask_image = mask_image.convert("L")
|
mask_image = (mask_image/255).astype(np.float32)
|
||||||
face_large.paste(face, (x-x_s, y-y_s, x1-x_s, y1-y_s))
|
|
||||||
body.paste(face_large, crop_box[:2], mask_image)
|
body[y_s:y_e, x_s:x_e] = cv2.blendLinear(face_large,body[y_s:y_e, x_s:x_e],mask_image,1-mask_image)
|
||||||
body = np.array(body)
|
|
||||||
return body[:,:,::-1]
|
return body
|
||||||
Reference in New Issue
Block a user