myutil.py 965 B

123456789101112131415161718192021222324252627
  1. import numpy as np
  2. import cv2
  3. import copy
  4. def get_image_blending(image,face,face_box,mask_array,crop_box):
  5. body = image
  6. x, y, x1, y1 = face_box
  7. x_s, y_s, x_e, y_e = crop_box
  8. face_large = copy.deepcopy(body[y_s:y_e, x_s:x_e])
  9. face_large[y-y_s:y1-y_s, x-x_s:x1-x_s]=face
  10. mask_image = cv2.cvtColor(mask_array,cv2.COLOR_BGR2GRAY)
  11. mask_image = (mask_image/255).astype(np.float32)
  12. # mask_not = cv2.bitwise_not(mask_array)
  13. # prospect_tmp = cv2.bitwise_and(face_large, face_large, mask=mask_array)
  14. # background_img = body[y_s:y_e, x_s:x_e]
  15. # background_img = cv2.bitwise_and(background_img, background_img, mask=mask_not)
  16. # body[y_s:y_e, x_s:x_e] = prospect_tmp + background_img
  17. #print(mask_image.shape)
  18. #print(cv2.minMaxLoc(mask_image))
  19. 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)
  20. #body.paste(face_large, crop_box[:2], mask_image)
  21. return body