Skip to content

Commit

Permalink
docs: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeyi-Lin committed Sep 11, 2024
1 parent 2260bd8 commit dbf3838
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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增加**高级参数设置****水印**选项卡
Expand Down
53 changes: 7 additions & 46 deletions demo/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@


class IDPhotoProcessor:
def __init__(self):
self.crop_only = False
self.matting_cache = None

def process(
self,
input_image,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 [
Expand Down
9 changes: 0 additions & 9 deletions demo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions hivision/creator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dbf3838

Please sign in to comment.