From f95682f6161d397cb72e10ce783fe38baffeb847 Mon Sep 17 00:00:00 2001 From: Colombo Date: Thu, 2 Jan 2020 21:19:19 +0400 Subject: [PATCH] fix --- converters/ConvertMasked.py | 20 +++++++++----------- mainscripts/Converter.py | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/converters/ConvertMasked.py b/converters/ConvertMasked.py index fa123cb..67769cd 100644 --- a/converters/ConvertMasked.py +++ b/converters/ConvertMasked.py @@ -344,12 +344,10 @@ def ConvertMaskedFace (predictor_func, predictor_input_shape, cfg, frame_info, i else: alpha = cfg.color_degrade_power / 100.0 out_img = (out_img*(1.0-alpha) + out_img_reduced*alpha) - - if cfg.export_mask_alpha: - out_img = np.concatenate ( [out_img, img_face_mask_aaa[:,:,0:1]], -1 ) + out_merging_mask = img_face_mask_aaa - return out_img, out_merging_mask + return out_img, out_merging_mask[...,0:1] def ConvertMasked (predictor_func, predictor_input_shape, cfg, frame_info): @@ -364,18 +362,18 @@ def ConvertMasked (predictor_func, predictor_input_shape, cfg, frame_info): #Combining multiple face outputs final_img = None + final_mask = None for img, merging_mask in outs: h,w,c = img.shape if final_img is None: final_img = img + final_mask = merging_mask else: - merging_mask = merging_mask[...,0:1] - if c == 3: - final_img = final_img*(1-merging_mask) + img*merging_mask - elif c == 4: - final_img_bgr = final_img[...,0:3]*(1-merging_mask) + img[...,0:3]*merging_mask - final_img_mask = np.clip ( final_img[...,3:4] + img[...,3:4], 0, 1 ) - final_img = np.concatenate ( [final_img_bgr, final_img_mask], -1 ) + final_img = final_img*(1-merging_mask) + img*merging_mask + final_mask = np.clip (final_mask + merging_mask, 0, 1 ) + if cfg.export_mask_alpha: + final_img = np.concatenate ( [final_img, final_mask], -1) + return (final_img*255).astype(np.uint8) \ No newline at end of file diff --git a/mainscripts/Converter.py b/mainscripts/Converter.py index 6a55de5..614a5a0 100644 --- a/mainscripts/Converter.py +++ b/mainscripts/Converter.py @@ -169,12 +169,22 @@ class ConvertSubprocessor(Subprocessor): if len(landmarks_list) == 0: self.log_info ( 'no faces found for %s, copying without faces' % (filename_path.name) ) - - if filename_path.suffix == '.png': - shutil.copy (filename, output_filename ) - else: + + if cfg.export_mask_alpha: img_bgr = cv2_imread(filename) + h,w,c = img_bgr.shape + if c == 1: + img_bgr = np.repeat(img_bgr, 3, -1) + if c == 3: + img_bgr = np.concatenate ([img_bgr, np.zeros((h,w,1), dtype=img_bgr.dtype) ], axis=-1) + cv2_imwrite (output_filename, img_bgr) + else: + if filename_path.suffix == '.png': + shutil.copy (filename, output_filename ) + else: + img_bgr = cv2_imread(filename) + cv2_imwrite (output_filename, img_bgr) if need_return_image: img_bgr = cv2_imread(filename)