This commit is contained in:
Colombo 2020-06-04 16:42:36 +04:00
parent 4ed320a86b
commit addc96fe3e

View file

@ -1,13 +1,15 @@
import sys
import traceback import traceback
import cv2 import cv2
import numpy as np import numpy as np
from core import imagelib from core import imagelib
from facelib import FaceType, LandmarksProcessor
from core.interact import interact as io
from core.cv2ex import * from core.cv2ex import *
from core.interact import interact as io
from facelib import FaceType, LandmarksProcessor
is_windows = sys.platform[0:3] == 'win'
xseg_input_size = 256 xseg_input_size = 256
def MergeMaskedFace (predictor_func, predictor_input_shape, def MergeMaskedFace (predictor_func, predictor_input_shape,
@ -149,7 +151,7 @@ def MergeMaskedFace (predictor_func, predictor_input_shape,
out_img = np.clip (out_img, 0.0, 1.0 ) out_img = np.clip (out_img, 0.0, 1.0 )
else: else:
# Process if the mask meets minimum size # Process if the mask meets minimum size
maxregion = np.argwhere( img_face_mask_a >= 0.1 ) maxregion = np.argwhere( img_face_mask_a >= 0.1 )
if maxregion.size != 0: if maxregion.size != 0:
@ -160,7 +162,7 @@ def MergeMaskedFace (predictor_func, predictor_input_shape,
if min(lenx,leny) >= 4: if min(lenx,leny) >= 4:
wrk_face_mask_area_a = wrk_face_mask_a.copy() wrk_face_mask_area_a = wrk_face_mask_a.copy()
wrk_face_mask_area_a[wrk_face_mask_area_a>0] = 1.0 wrk_face_mask_area_a[wrk_face_mask_area_a>0] = 1.0
if 'seamless' not in cfg.mode and cfg.color_transfer_mode != 0: if 'seamless' not in cfg.mode and cfg.color_transfer_mode != 0:
if cfg.color_transfer_mode == 1: #rct if cfg.color_transfer_mode == 1: #rct
prd_face_bgr = imagelib.reinhard_color_transfer ( np.clip( prd_face_bgr*wrk_face_mask_area_a*255, 0, 255).astype(np.uint8), prd_face_bgr = imagelib.reinhard_color_transfer ( np.clip( prd_face_bgr*wrk_face_mask_area_a*255, 0, 255).astype(np.uint8),
@ -232,10 +234,15 @@ def MergeMaskedFace (predictor_func, predictor_input_shape,
cfg_mp = cfg.motion_blur_power / 100.0 cfg_mp = cfg.motion_blur_power / 100.0
# linux opencv can produce nan's so there will be errors in multiplying and glitches in videos if not is_windows:
img_bgr = np.nan_to_num(img_bgr) # linux opencv can produce nan's so there will be errors in multiplying and glitches in videos
img_bgr = np.nan_to_num(img_bgr)
img_face_mask_a = np.nan_to_num(img_face_mask_a) img_face_mask_a = np.nan_to_num(img_face_mask_a)
out_img = np.nan_to_num(out_img)
if not is_windows:
out_img = np.nan_to_num(out_img)
out_img = img_bgr*(1-img_face_mask_a) + (out_img*img_face_mask_a) out_img = img_bgr*(1-img_face_mask_a) + (out_img*img_face_mask_a)
if ('seamless' in cfg.mode and cfg.color_transfer_mode != 0) or \ if ('seamless' in cfg.mode and cfg.color_transfer_mode != 0) or \
@ -311,7 +318,7 @@ def MergeMaskedFace (predictor_func, predictor_input_shape,
out_img = (out_img*(1.0-alpha) + out_img_reduced*alpha) out_img = (out_img*(1.0-alpha) + out_img_reduced*alpha)
else: else:
out_img = img_bgr.copy() out_img = img_bgr.copy()
out_merging_mask_a = img_face_mask_a out_merging_mask_a = img_face_mask_a
return out_img, out_merging_mask_a return out_img, out_merging_mask_a
@ -347,4 +354,4 @@ def MergeMasked (predictor_func,
final_img = np.concatenate ( [final_img, final_mask], -1) final_img = np.concatenate ( [final_img, final_mask], -1)
return (final_img*255).astype(np.uint8) return (final_img*255).astype(np.uint8)