'show alpha mask' now on 'V' button

'super resolution mode' is replaced by
'super resolution power' (0..100) which can be modified via 'T' 'G' buttons
This commit is contained in:
Colombo 2020-02-02 10:13:23 +04:00
parent 054a7e0e6e
commit 85792d232a
6 changed files with 31 additions and 38 deletions

View File

@ -190,12 +190,11 @@ class MergeSubprocessor(Subprocessor):
self.predictor_input_shape = predictor_input_shape self.predictor_input_shape = predictor_input_shape
self.face_enhancer = None self.face_enhancer = None
def superres_func(mode, face_bgr): def superres_func(face_bgr):
if mode == 1: if self.face_enhancer is None:
if self.face_enhancer is None: self.face_enhancer = FaceEnhancer(place_model_on_cpu=True)
self.face_enhancer = FaceEnhancer(place_model_on_cpu=True)
return self.face_enhancer.enhance (face_bgr, is_tanh=True, preserve_size=False) return self.face_enhancer.enhance (face_bgr, is_tanh=True, preserve_size=False)
self.superres_host, self.superres_func = SubprocessFunctionCaller.make_pair(superres_func) self.superres_host, self.superres_func = SubprocessFunctionCaller.make_pair(superres_func)
@ -372,6 +371,8 @@ class MergeSubprocessor(Subprocessor):
'd' : lambda cfg,shift_pressed: cfg.add_blur_mask_modifier(-1 if not shift_pressed else -5), 'd' : lambda cfg,shift_pressed: cfg.add_blur_mask_modifier(-1 if not shift_pressed else -5),
'r' : lambda cfg,shift_pressed: cfg.add_motion_blur_power(1 if not shift_pressed else 5), 'r' : lambda cfg,shift_pressed: cfg.add_motion_blur_power(1 if not shift_pressed else 5),
'f' : lambda cfg,shift_pressed: cfg.add_motion_blur_power(-1 if not shift_pressed else -5), 'f' : lambda cfg,shift_pressed: cfg.add_motion_blur_power(-1 if not shift_pressed else -5),
't' : lambda cfg,shift_pressed: cfg.add_super_resolution_power(1 if not shift_pressed else 5),
'g' : lambda cfg,shift_pressed: cfg.add_super_resolution_power(-1 if not shift_pressed else -5),
'y' : lambda cfg,shift_pressed: cfg.add_blursharpen_amount(1 if not shift_pressed else 5), 'y' : lambda cfg,shift_pressed: cfg.add_blursharpen_amount(1 if not shift_pressed else 5),
'h' : lambda cfg,shift_pressed: cfg.add_blursharpen_amount(-1 if not shift_pressed else -5), 'h' : lambda cfg,shift_pressed: cfg.add_blursharpen_amount(-1 if not shift_pressed else -5),
'u' : lambda cfg,shift_pressed: cfg.add_output_face_scale(1 if not shift_pressed else 5), 'u' : lambda cfg,shift_pressed: cfg.add_output_face_scale(1 if not shift_pressed else 5),
@ -386,7 +387,6 @@ class MergeSubprocessor(Subprocessor):
'z' : lambda cfg,shift_pressed: cfg.toggle_masked_hist_match(), 'z' : lambda cfg,shift_pressed: cfg.toggle_masked_hist_match(),
'x' : lambda cfg,shift_pressed: cfg.toggle_mask_mode(), 'x' : lambda cfg,shift_pressed: cfg.toggle_mask_mode(),
'c' : lambda cfg,shift_pressed: cfg.toggle_color_transfer_mode(), 'c' : lambda cfg,shift_pressed: cfg.toggle_color_transfer_mode(),
'v' : lambda cfg,shift_pressed: cfg.toggle_super_resolution_mode(),
'n' : lambda cfg,shift_pressed: cfg.toggle_sharpen_mode(), 'n' : lambda cfg,shift_pressed: cfg.toggle_sharpen_mode(),
} }
self.masked_keys = list(self.masked_keys_funcs.keys()) self.masked_keys = list(self.masked_keys_funcs.keys())
@ -523,7 +523,7 @@ class MergeSubprocessor(Subprocessor):
self.screen_manager.get_current().diff_scale(-0.1) self.screen_manager.get_current().diff_scale(-0.1)
elif chr_key == '=': elif chr_key == '=':
self.screen_manager.get_current().diff_scale(0.1) self.screen_manager.get_current().diff_scale(0.1)
elif chr_key == 'b': elif chr_key == 'v':
self.screen_manager.get_current().toggle_show_checker_board() self.screen_manager.get_current().toggle_show_checker_board()
if go_prev_frame: if go_prev_frame:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 306 KiB

After

Width:  |  Height:  |  Size: 307 KiB

View File

@ -26,8 +26,8 @@ def MergeFaceAvatar (predictor_func, predictor_input_shape, cfg, prev_temporal_f
prd_f = predictor_func ( prev_imgs, img, next_imgs ) prd_f = predictor_func ( prev_imgs, img, next_imgs )
if cfg.super_resolution_mode != 0: #if cfg.super_resolution_mode != 0:
prd_f = cfg.superres_func(cfg.super_resolution_mode, prd_f) # prd_f = cfg.superres_func(cfg.super_resolution_mode, prd_f)
if cfg.sharpen_mode != 0 and cfg.sharpen_amount != 0: if cfg.sharpen_mode != 0 and cfg.sharpen_amount != 0:
prd_f = cfg.sharpen_func ( prd_f, cfg.sharpen_mode, 3, cfg.sharpen_amount) prd_f = cfg.sharpen_func ( prd_f, cfg.sharpen_mode, 3, cfg.sharpen_amount)

View File

@ -22,7 +22,7 @@ def MergeMaskedFace (predictor_func, predictor_input_shape, cfg, frame_info, img
input_size = predictor_input_shape[0] input_size = predictor_input_shape[0]
mask_subres_size = input_size*4 mask_subres_size = input_size*4
output_size = input_size output_size = input_size
if cfg.super_resolution_mode != 0: if cfg.super_resolution_power != 0:
output_size *= 4 output_size *= 4
face_mat = LandmarksProcessor.get_transform_mat (img_face_landmarks, output_size, face_type=cfg.face_type) face_mat = LandmarksProcessor.get_transform_mat (img_face_landmarks, output_size, face_type=cfg.face_type)
@ -53,8 +53,12 @@ def MergeMaskedFace (predictor_func, predictor_input_shape, cfg, frame_info, img
prd_face_mask_a_0 = cv2.resize (dst_face_mask_a_0, (input_size,input_size) ) prd_face_mask_a_0 = cv2.resize (dst_face_mask_a_0, (input_size,input_size) )
predictor_masked = False predictor_masked = False
if cfg.super_resolution_mode != 0: if cfg.super_resolution_power != 0:
prd_face_bgr = cfg.superres_func(cfg.super_resolution_mode, prd_face_bgr) prd_face_bgr_enhanced = cfg.superres_func(prd_face_bgr)
mod = cfg.super_resolution_power / 100.0
prd_face_bgr = cv2.resize(prd_face_bgr, (output_size,output_size))*(1.0-mod) + \
prd_face_bgr_enhanced*mod
prd_face_bgr = np.clip(prd_face_bgr, 0, 1) prd_face_bgr = np.clip(prd_face_bgr, 0, 1)
if predictor_masked: if predictor_masked:
@ -123,7 +127,7 @@ def MergeMaskedFace (predictor_func, predictor_input_shape, cfg, frame_info, img
# clip eroded/dilated mask in actual predict area # clip eroded/dilated mask in actual predict area
# pad with half blur size in order to accuratelly fade to zero at the boundary # pad with half blur size in order to accuratelly fade to zero at the boundary
clip_size = input_size + blur // 2 clip_size = input_size + blur // 2
prd_face_mask_a_0[:clip_size,:] = 0 prd_face_mask_a_0[:clip_size,:] = 0
prd_face_mask_a_0[-clip_size:,:] = 0 prd_face_mask_a_0[-clip_size:,:] = 0
prd_face_mask_a_0[:,:clip_size] = 0 prd_face_mask_a_0[:,:clip_size] = 0
@ -132,7 +136,7 @@ def MergeMaskedFace (predictor_func, predictor_input_shape, cfg, frame_info, img
if blur > 0: if blur > 0:
blur = blur + (1-blur % 2) blur = blur + (1-blur % 2)
prd_face_mask_a_0 = cv2.GaussianBlur(prd_face_mask_a_0, (blur, blur) , 0) prd_face_mask_a_0 = cv2.GaussianBlur(prd_face_mask_a_0, (blur, blur) , 0)
prd_face_mask_a_0 = prd_face_mask_a_0[input_size:-input_size,input_size:-input_size] prd_face_mask_a_0 = prd_face_mask_a_0[input_size:-input_size,input_size:-input_size]
prd_face_mask_a_0 = np.clip(prd_face_mask_a_0, 0, 1) prd_face_mask_a_0 = np.clip(prd_face_mask_a_0, 0, 1)
@ -141,7 +145,7 @@ def MergeMaskedFace (predictor_func, predictor_input_shape, cfg, frame_info, img
img_face_mask_a = np.clip (img_face_mask_a, 0.0, 1.0) img_face_mask_a = np.clip (img_face_mask_a, 0.0, 1.0)
img_face_mask_a [ img_face_mask_a < (1.0/255.0) ] = 0.0 # get rid of noise img_face_mask_a [ img_face_mask_a < (1.0/255.0) ] = 0.0 # get rid of noise
if prd_face_mask_a_0.shape[0] != output_size: if prd_face_mask_a_0.shape[0] != output_size:
prd_face_mask_a_0 = cv2.resize (prd_face_mask_a_0, (output_size,output_size), cv2.INTER_CUBIC) prd_face_mask_a_0 = cv2.resize (prd_face_mask_a_0, (output_size,output_size), cv2.INTER_CUBIC)
@ -277,7 +281,7 @@ def MergeMaskedFace (predictor_func, predictor_input_shape, cfg, frame_info, img
k_size = int(frame_info.motion_power*cfg_mp) k_size = int(frame_info.motion_power*cfg_mp)
if k_size >= 1: if k_size >= 1:
k_size = np.clip (k_size+1, 2, 50) k_size = np.clip (k_size+1, 2, 50)
if cfg.super_resolution_mode != 0: if cfg.super_resolution_power != 0:
k_size *= 2 k_size *= 2
out_face_bgr = imagelib.LinearMotionBlur (out_face_bgr, k_size , frame_info.motion_deg) out_face_bgr = imagelib.LinearMotionBlur (out_face_bgr, k_size , frame_info.motion_deg)

View File

@ -15,8 +15,6 @@ class MergerConfig(object):
TYPE_IMAGE_WITH_LANDMARKS = 4 TYPE_IMAGE_WITH_LANDMARKS = 4
def __init__(self, type=0, def __init__(self, type=0,
super_resolution_mode=0,
sharpen_mode=0, sharpen_mode=0,
blursharpen_amount=0, blursharpen_amount=0,
**kwargs **kwargs
@ -28,11 +26,9 @@ class MergerConfig(object):
self.fanseg_input_size = None self.fanseg_input_size = None
self.fanseg_extract_func = None self.fanseg_extract_func = None
self.super_res_dict = {0:"None", 1:'FaceEnhancer'}
self.sharpen_dict = {0:"None", 1:'box', 2:'gaussian'} self.sharpen_dict = {0:"None", 1:'box', 2:'gaussian'}
#default changeable params #default changeable params
self.super_resolution_mode = super_resolution_mode
self.sharpen_mode = sharpen_mode self.sharpen_mode = sharpen_mode
self.blursharpen_amount = blursharpen_amount self.blursharpen_amount = blursharpen_amount
@ -50,12 +46,6 @@ class MergerConfig(object):
if self.sharpen_mode != 0: if self.sharpen_mode != 0:
self.blursharpen_amount = np.clip ( io.input_int ("Choose blur/sharpen amount", 0, add_info="-100..100"), -100, 100 ) self.blursharpen_amount = np.clip ( io.input_int ("Choose blur/sharpen amount", 0, add_info="-100..100"), -100, 100 )
s = """Choose super resolution mode: \n"""
for key in self.super_res_dict.keys():
s += f"""({key}) {self.super_res_dict[key]}\n"""
io.log_info(s)
self.super_resolution_mode = io.input_int ("", 0, valid_list=self.super_res_dict.keys(), help_message="Enhance details by applying superresolution network.")
def toggle_sharpen_mode(self): def toggle_sharpen_mode(self):
a = list( self.sharpen_dict.keys() ) a = list( self.sharpen_dict.keys() )
self.sharpen_mode = a[ (a.index(self.sharpen_mode)+1) % len(a) ] self.sharpen_mode = a[ (a.index(self.sharpen_mode)+1) % len(a) ]
@ -63,19 +53,11 @@ class MergerConfig(object):
def add_blursharpen_amount(self, diff): def add_blursharpen_amount(self, diff):
self.blursharpen_amount = np.clip ( self.blursharpen_amount+diff, -100, 100) self.blursharpen_amount = np.clip ( self.blursharpen_amount+diff, -100, 100)
def toggle_super_resolution_mode(self):
a = list( self.super_res_dict.keys() )
self.super_resolution_mode = a[ (a.index(self.super_resolution_mode)+1) % len(a) ]
#overridable #overridable
def get_config(self): def get_config(self):
d = self.__dict__.copy() d = self.__dict__.copy()
d.pop('type') d.pop('type')
return d return d
return {'sharpen_mode':self.sharpen_mode,
'blursharpen_amount':self.blursharpen_amount,
'super_resolution_mode':self.super_resolution_mode
}
#overridable #overridable
def __eq__(self, other): def __eq__(self, other):
@ -83,8 +65,7 @@ class MergerConfig(object):
if isinstance(other, MergerConfig): if isinstance(other, MergerConfig):
return self.sharpen_mode == other.sharpen_mode and \ return self.sharpen_mode == other.sharpen_mode and \
self.blursharpen_amount == other.blursharpen_amount and \ self.blursharpen_amount == other.blursharpen_amount
self.super_resolution_mode == other.super_resolution_mode
return False return False
@ -93,7 +74,6 @@ class MergerConfig(object):
r = "" r = ""
r += f"sharpen_mode : {self.sharpen_dict[self.sharpen_mode]}\n" r += f"sharpen_mode : {self.sharpen_dict[self.sharpen_mode]}\n"
r += f"blursharpen_amount : {self.blursharpen_amount}\n" r += f"blursharpen_amount : {self.blursharpen_amount}\n"
r += f"super_resolution_mode : {self.super_res_dict[self.super_resolution_mode]}\n"
return r return r
mode_dict = {0:'original', mode_dict = {0:'original',
@ -137,6 +117,7 @@ class MergerConfigMasked(MergerConfig):
blur_mask_modifier = 0, blur_mask_modifier = 0,
motion_blur_power = 0, motion_blur_power = 0,
output_face_scale = 0, output_face_scale = 0,
super_resolution_power = 0,
color_transfer_mode = ctm_str_dict['rct'], color_transfer_mode = ctm_str_dict['rct'],
image_denoise_power = 0, image_denoise_power = 0,
bicubic_degrade_power = 0, bicubic_degrade_power = 0,
@ -165,6 +146,7 @@ class MergerConfigMasked(MergerConfig):
self.blur_mask_modifier = blur_mask_modifier self.blur_mask_modifier = blur_mask_modifier
self.motion_blur_power = motion_blur_power self.motion_blur_power = motion_blur_power
self.output_face_scale = output_face_scale self.output_face_scale = output_face_scale
self.super_resolution_power = super_resolution_power
self.color_transfer_mode = color_transfer_mode self.color_transfer_mode = color_transfer_mode
self.image_denoise_power = image_denoise_power self.image_denoise_power = image_denoise_power
self.bicubic_degrade_power = bicubic_degrade_power self.bicubic_degrade_power = bicubic_degrade_power
@ -206,6 +188,9 @@ class MergerConfigMasked(MergerConfig):
def toggle_color_transfer_mode(self): def toggle_color_transfer_mode(self):
self.color_transfer_mode = (self.color_transfer_mode+1) % ( max(ctm_dict.keys())+1 ) self.color_transfer_mode = (self.color_transfer_mode+1) % ( max(ctm_dict.keys())+1 )
def add_super_resolution_power(self, diff):
self.super_resolution_power = np.clip ( self.super_resolution_power+diff , 0, 100)
def add_color_degrade_power(self, diff): def add_color_degrade_power(self, diff):
self.color_degrade_power = np.clip ( self.color_degrade_power+diff , 0, 100) self.color_degrade_power = np.clip ( self.color_degrade_power+diff , 0, 100)
@ -257,6 +242,8 @@ class MergerConfigMasked(MergerConfig):
self.color_transfer_mode = ctm_str_dict[self.color_transfer_mode] self.color_transfer_mode = ctm_str_dict[self.color_transfer_mode]
super().ask_settings() super().ask_settings()
self.super_resolution_power = np.clip ( io.input_int ("Choose super resolution power", 0, add_info="0..100", help_message="Enhance details by applying superresolution network."), 0, 100)
if 'raw' not in self.mode: if 'raw' not in self.mode:
self.image_denoise_power = np.clip ( io.input_int ("Choose image degrade by denoise power", 0, add_info="0..500"), 0, 500) self.image_denoise_power = np.clip ( io.input_int ("Choose image degrade by denoise power", 0, add_info="0..500"), 0, 500)
@ -279,6 +266,7 @@ class MergerConfigMasked(MergerConfig):
self.motion_blur_power == other.motion_blur_power and \ self.motion_blur_power == other.motion_blur_power and \
self.output_face_scale == other.output_face_scale and \ self.output_face_scale == other.output_face_scale and \
self.color_transfer_mode == other.color_transfer_mode and \ self.color_transfer_mode == other.color_transfer_mode and \
self.super_resolution_power == other.super_resolution_power and \
self.image_denoise_power == other.image_denoise_power and \ self.image_denoise_power == other.image_denoise_power and \
self.bicubic_degrade_power == other.bicubic_degrade_power and \ self.bicubic_degrade_power == other.bicubic_degrade_power and \
self.color_degrade_power == other.color_degrade_power self.color_degrade_power == other.color_degrade_power
@ -313,7 +301,8 @@ class MergerConfigMasked(MergerConfig):
r += f"""color_transfer_mode: { ctm_dict[self.color_transfer_mode]}\n""" r += f"""color_transfer_mode: { ctm_dict[self.color_transfer_mode]}\n"""
r += super().to_string(filename) r += super().to_string(filename)
r += f"""super_resolution_power: {self.super_resolution_power}\n"""
if 'raw' not in self.mode: if 'raw' not in self.mode:
r += (f"""image_denoise_power: {self.image_denoise_power}\n""" r += (f"""image_denoise_power: {self.image_denoise_power}\n"""
f"""bicubic_degrade_power: {self.bicubic_degrade_power}\n""" f"""bicubic_degrade_power: {self.bicubic_degrade_power}\n"""