Skip to content
Permalink
Browse files

fix

  • Loading branch information
iperov committed Jan 2, 2020
1 parent 5efb430 commit f95682f6161d397cb72e10ce783fe38baffeb847
Showing with 23 additions and 15 deletions.
  1. +9 −11 converters/ConvertMasked.py
  2. +14 −4 mainscripts/Converter.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)
@@ -169,12 +169,22 @@ def process_data(self, pf): #pf=ProcessingFrame

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)

0 comments on commit f95682f

Please sign in to comment.
You can’t perform that action at this time.