diff --git a/README.md b/README.md index 9668fc40..1772819f 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ - 在线体验: [![SwanHub Demo](https://img.shields.io/static/v1?label=Demo&message=SwanHub%20Demo&color=blue)](https://swanhub.co/ZeYiLin/HivisionIDPhotos/demo)、[![Spaces](https://img.shields.io/badge/🤗-Open%20in%20Spaces-blue)](https://huggingface.co/spaces/TheEeeeLin/HivisionIDPhotos) -- 2024.9.12: 优化 Gradio Demo处理同一张照片时的性能 | API接口增加**加水印**、**设置照片KB值大小**、**证件照裁切** +- 2024.9.12: API接口增加**加水印**、**设置照片KB值大小**、**证件照裁切** - 2024.09.11: Gradio Demo增加**透明图显示与下载**功能 - 2024.09.10: 增加新的**人脸检测模型** Retinaface-resnet50,以稍弱于mtcnn的速度换取更高的检测精度,推荐使用 - 2024.09.09: 增加新的**抠图模型** [BiRefNet-v1-lite](https://github.com/ZhengPeng7/BiRefNet) | Gradio增加**高级参数设置**和**水印**选项卡 diff --git a/demo/processor.py b/demo/processor.py index 0a958648..afc5f819 100644 --- a/demo/processor.py +++ b/demo/processor.py @@ -15,10 +15,6 @@ class IDPhotoProcessor: - def __init__(self): - self.crop_only = False - self.matting_cache = None - def process( self, input_image, @@ -119,46 +115,14 @@ def process( idphoto_json["size_mode"] in LOCALES["size_mode"][language]["choices"][1] ) - # 如果不是只裁切模式,则清空抠图缓存 - if not self.crop_only: - # print("--清空缓存") - self.matting_cache = None - self.face_detect_cache = None - try: - if self.matting_cache is None: - result = creator( - input_image, - change_bg_only=change_bg_only, - size=idphoto_json["size"], - head_measure_ratio=head_measure_ratio, - head_top_range=(top_distance_max, top_distance_min), - ) - self.matting_cache = result.matting - self.face_detect_cache = result.face - # 如果第一次点了只换底,第二次选了尺寸 - elif self.matting_cache is not None and self.face_detect_cache is None: - result = creator( - self.matting_cache, - change_bg_only=change_bg_only, - size=idphoto_json["size"], - head_measure_ratio=head_measure_ratio, - head_top_range=(top_distance_max, top_distance_min), - crop_only=True, - ) - self.face_detect_cache = result.face - - else: - # print("使用缓存") - result = creator( - self.matting_cache, - change_bg_only=change_bg_only, - size=idphoto_json["size"], - head_measure_ratio=head_measure_ratio, - head_top_range=(top_distance_max, top_distance_min), - crop_only=True, - face=self.face_detect_cache, - ) + result = creator( + input_image, + change_bg_only=change_bg_only, + size=idphoto_json["size"], + head_measure_ratio=head_measure_ratio, + head_top_range=(top_distance_max, top_distance_min), + ) except FaceError: return [ gr.update(value=None), # img_output_standard @@ -313,9 +277,6 @@ def process( else: output_image_path = None - # 设置crop_only模式为True,会在Gradio的上传图像组件变化时重新设置为False - self.crop_only = True - # 返回结果 if output_image_path: return [ diff --git a/demo/ui.py b/demo/ui.py index bf05c0b1..7c50394a 100644 --- a/demo/ui.py +++ b/demo/ui.py @@ -42,10 +42,6 @@ def create_ui( with gr.Column(): img_input = gr.Image(height=400) - def crop_only_false(): - # print("crop_only_false") - processor.crop_only = False - with gr.Row(): # 语言选择器 language = ["zh", "en"] @@ -67,11 +63,6 @@ def crop_only_false(): value=human_matting_models[0], ) - # 重新上传照片、选择人脸检测模型、选择抠图模型时,重置裁切模式 - img_input.change(crop_only_false) - face_detect_model_options.change(crop_only_false) - matting_model_options.change(crop_only_false) - with gr.Tab( LOCALES["key_param"][DEFAULT_LANG]["label"] ) as key_parameter_tab: diff --git a/hivision/creator/__init__.py b/hivision/creator/__init__.py index a34fb163..378e1d23 100644 --- a/hivision/creator/__init__.py +++ b/hivision/creator/__init__.py @@ -108,11 +108,9 @@ def __call__( return ctx.result # 2. 人脸检测 - if not ctx.params.face: - self.detection_handler(ctx) - else: - ctx.face = ctx.params.face + self.detection_handler(ctx) self.after_detect and self.after_detect(ctx) + # 3. 图像调整 result_image_hd, result_image_standard, clothing_params, typography_params = ( adjust_photo(ctx)