From 10c2703c2f8fc9d756ec6e10f954d970e6ce0476 Mon Sep 17 00:00:00 2001
From: ZeYi Lin <944270057@qq.com>
Date: Sat, 14 Sep 2024 13:12:15 +0800
Subject: [PATCH] docs: community add wechat miniprogram
---
README.md | 2 +-
README_EN.md | 2 +-
README_JP.md | 2 +
README_KO.md | 2 +
hivision/plugin/beauty/grind_skin.py | 104 ++++++++++++++++++++++-----
5 files changed, 94 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
index 62addb5c..c5d52f5b 100644
--- a/README.md
+++ b/README.md
@@ -102,7 +102,7 @@ HivisionIDPhoto 旨在开发一种实用、系统性的证件照智能制作算
[![](assets/comfyui.png)](https://github.com/AIFSH/HivisionIDPhotos-ComfyUI)
- [HivisionIDPhotos-NAS](https://github.com/ONG-Leo/HivisionIDPhotos-NAS): 群晖NAS部署中文教程,由 [ONG-Leo](https://github.com/ONG-Leo) 贡献
-- [zjzWx](https://github.com/no1xuan/zjzWx): 精美的开源证件照微信小程序项目,后台基于HivisionIDphotos算法,由 [no1xuan](https://github.com/no1xuan) 贡献
+- [HivisionIDPhotos-wechat-weapp](https://github.com/no1xuan/HivisionIDPhotos-wechat-weapp): 微信证件照小程序,基于HivisionIDphotos算法驱动,由 [no1xuan](https://github.com/no1xuan) 贡献
diff --git a/README_EN.md b/README_EN.md
index d41b19ee..d999ac78 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -99,7 +99,7 @@ We have shared some interesting applications and extensions of HivisionIDPhotos
[![](assets/comfyui.png)](https://github.com/AIFSH/HivisionIDPhotos-ComfyUI)
-- [zjzWx](https://github.com/no1xuan/zjzWx): Exquisite open source ID photo WeChat mini program project, contributed by [no1xuan](https://github.com/no1xuan)
+- [HivisionIDPhotos-wechat-weapp](https://github.com/no1xuan/HivisionIDPhotos-wechat-weapp): WeChat ID photo mini program, powered by the HivisionIDphotos algorithm, contributed by [no1xuan](https://github.com/no1xuan)
diff --git a/README_JP.md b/README_JP.md
index a521dcc0..333f8d07 100644
--- a/README_JP.md
+++ b/README_JP.md
@@ -96,6 +96,8 @@ HivisionIDPhotoがあなたに役立つ場合は、このリポジトリをス
[![](assets/comfyui.png)](https://github.com/AIFSH/HivisionIDPhotos-ComfyUI)
+- [HivisionIDPhotos-wechat-weapp](https://github.com/no1xuan/HivisionIDPhotos-wechat-weapp): WeChat ID写真ミニプログラムで、HivisionIDphotosアルゴリズムに基づいており、[no1xuan](https://github.com/no1xuan)が貢献しました。
+
# 🔧 準備作業
diff --git a/README_KO.md b/README_KO.md
index 79c8537b..c5b0a93d 100644
--- a/README_KO.md
+++ b/README_KO.md
@@ -97,6 +97,8 @@ HivisionIDPhoto가 여러분에게 도움이 된다면, 이 리포지토리를
[![](assets/comfyui.png)](https://github.com/AIFSH/HivisionIDPhotos-ComfyUI)
+- [HivisionIDPhotos-wechat-weapp](https://github.com/no1xuan/HivisionIDPhotos-wechat-weapp): WeChat ID 사진 미니 프로그램, HivisionIDphotos 알고리즘을 기반으로 하며, [no1xuan](https://github.com/no1xuan)이 기여하였습니다.
+
# 🔧 준비 작업
diff --git a/hivision/plugin/beauty/grind_skin.py b/hivision/plugin/beauty/grind_skin.py
index 30402842..58431b9f 100644
--- a/hivision/plugin/beauty/grind_skin.py
+++ b/hivision/plugin/beauty/grind_skin.py
@@ -1,20 +1,50 @@
-"""
-@author: cuny
-@file: GrindSkin.py
-@time: 2022/7/2 14:44
-@description:
-磨皮算法
-"""
-
+# Required Libraries
import cv2
import numpy as np
+import gradio as gr
+
+
+def annotate_image(image, grind_degree, detail_degree, strength):
+ """Annotates the image with parameters in the lower-left corner."""
+ font = cv2.FONT_HERSHEY_SIMPLEX
+ font_scale = 0.5
+ color = (0, 0, 255)
+ thickness = 1
+ line_type = cv2.LINE_AA
+
+ # Text positions
+ y_offset = 20
+ x_offset = 10
+ y_base = image.shape[0] - 10
+
+ # Define each line of the annotation
+ lines = [
+ f"Grind Degree: {grind_degree}",
+ f"Detail Degree: {detail_degree}",
+ f"Strength: {strength}",
+ ]
+
+ # Draw the text lines on the image
+ for i, line in enumerate(lines):
+ y_position = y_base - (i * y_offset)
+ cv2.putText(
+ image,
+ line,
+ (x_offset, y_position),
+ font,
+ font_scale,
+ color,
+ thickness,
+ line_type,
+ )
+
+ return image
def grindSkin(src, grindDegree: int = 3, detailDegree: int = 1, strength: int = 9):
"""
- Dest =(Src * (100 - Opacity) + (Src + 2 * GaussBlur(EPFFilter(Src) - Src)) * Opacity) /100
- 人像磨皮方案,后续会考虑使用一些皮肤区域检测算法来实现仅皮肤区域磨皮,增加算法的精细程度——或者使用人脸关键点
- https://www.cnblogs.com/Imageshop/p/4709710.html
+ Dest =(Src * (100 - Opacity) + (Src + 2 * GaussBlur(EPFFilter(Src) - Src)) * Opacity) / 100
+ 人像磨皮方案
Args:
src: 原图
grindDegree: 磨皮程度调节参数
@@ -28,8 +58,8 @@ def grindSkin(src, grindDegree: int = 3, detailDegree: int = 1, strength: int =
return src
dst = src.copy()
opacity = min(10.0, strength) / 10.0
- dx = grindDegree * 5 # 双边滤波参数之一
- fc = grindDegree * 12.5 # 双边滤波参数之一
+ dx = grindDegree * 5
+ fc = grindDegree * 12.5
temp1 = cv2.bilateralFilter(src[:, :, :3], dx, fc, fc)
temp2 = cv2.subtract(temp1, src[:, :, :3])
temp3 = cv2.GaussianBlur(temp2, (2 * detailDegree - 1, 2 * detailDegree - 1), 0)
@@ -38,7 +68,49 @@ def grindSkin(src, grindDegree: int = 3, detailDegree: int = 1, strength: int =
return dst
+def process_image(input_img, grind_degree, detail_degree, strength):
+ # Reading the image using OpenCV
+ img = cv2.cvtColor(input_img, cv2.COLOR_RGB2BGR)
+ # Processing the image
+ output_img = grindSkin(img, grind_degree, detail_degree, strength)
+ # Annotating the processed image with parameters
+ output_img_annotated = annotate_image(
+ output_img.copy(), grind_degree, detail_degree, strength
+ )
+ # Horizontal stacking of input and processed images
+ combined_img = cv2.hconcat([img, output_img_annotated])
+ # Convert the combined image back to RGB for display
+ combined_img_rgb = cv2.cvtColor(combined_img, cv2.COLOR_BGR2RGB)
+ return combined_img_rgb
+
+
+with gr.Blocks(title="Skin Grinding") as iface:
+ gr.Markdown("## Skin Grinding Application")
+
+ with gr.Row():
+ image_input = gr.Image(type="numpy", label="Input Image")
+ image_output = gr.Image(label="Output Image")
+
+ grind_degree_slider = gr.Slider(
+ minimum=1, maximum=10, value=3, step=1, label="Grind Degree"
+ )
+ detail_degree_slider = gr.Slider(
+ minimum=1, maximum=10, value=1, step=1, label="Detail Degree"
+ )
+ strength_slider = gr.Slider(
+ minimum=0, maximum=10, value=9, step=1, label="Strength"
+ )
+
+ gr.Button("Process Image").click(
+ fn=process_image,
+ inputs=[
+ image_input,
+ grind_degree_slider,
+ detail_degree_slider,
+ strength_slider,
+ ],
+ outputs=image_output,
+ )
+
if __name__ == "__main__":
- input_image = cv2.imread("test_image/7.jpg")
- output_image = grindSkin(src=input_image)
- cv2.imwrite("grindSkinCompare.png", np.hstack((input_image, output_image)))
+ iface.launch()