diff --git a/demo/processor.py b/demo/processor.py
index bed27f62..fdebdf67 100644
--- a/demo/processor.py
+++ b/demo/processor.py
@@ -320,10 +320,11 @@ def _handle_photo_generation_error(self, language):
"""处理照片生成错误"""
return [gr.update(value=None) for _ in range(4)] + [
gr.update(visible=False),
+ gr.update(value=None),
+ gr.update(value=None),
gr.update(
value=LOCALES["notification"][language]["face_error"], visible=True
),
- None,
]
# 处理生成的照片
diff --git a/deploy_api.py b/deploy_api.py
index b01e2d73..4330dcf2 100644
--- a/deploy_api.py
+++ b/deploy_api.py
@@ -15,7 +15,6 @@
add_watermark,
save_image_dpi_to_bytes,
)
-import base64
import numpy as np
import cv2
from starlette.middleware.cors import CORSMiddleware
@@ -47,10 +46,14 @@ async def idphoto_inference(
hd: bool = Form(True),
dpi: int = Form(300),
face_align: bool = Form(False),
- head_measure_ratio: float = 0.2,
- head_height_ratio: float = 0.45,
- top_distance_max: float = 0.12,
- top_distance_min: float = 0.10,
+ head_measure_ratio: float = Form(0.2),
+ head_height_ratio: float = Form(0.45),
+ top_distance_max: float = Form(0.12),
+ top_distance_min: float = Form(0.10),
+ brightness_strength: float = Form(0),
+ contrast_strength: float = Form(0),
+ sharpen_strength: float = Form(0),
+ saturation_strength: float = Form(0),
):
# 如果传入了base64,则直接使用base64解码
if input_image_base64:
@@ -74,6 +77,10 @@ async def idphoto_inference(
head_height_ratio=head_height_ratio,
head_top_range=(top_distance_max, top_distance_min),
face_alignment=face_align,
+ brightness_strength=brightness_strength,
+ contrast_strength=contrast_strength,
+ sharpen_strength=sharpen_strength,
+ saturation_strength=saturation_strength,
)
except FaceError:
result_message = {"status": False}
@@ -304,10 +311,10 @@ async def idphoto_crop_inference(
face_detect_model: str = Form("mtcnn"),
hd: bool = Form(True),
dpi: int = Form(300),
- head_measure_ratio: float = 0.2,
- head_height_ratio: float = 0.45,
- top_distance_max: float = 0.12,
- top_distance_min: float = 0.10,
+ head_measure_ratio: float = Form(0.2),
+ head_height_ratio: float = Form(0.45),
+ top_distance_max: float = Form(0.12),
+ top_distance_min: float = Form(0.10),
):
if input_image_base64:
img = base64_2_numpy(input_image_base64)
diff --git a/docs/api_CN.md b/docs/api_CN.md
index 8af37cdc..d687edd5 100644
--- a/docs/api_CN.md
+++ b/docs/api_CN.md
@@ -60,7 +60,10 @@ python deploy_api.py
| head_height_ratio | float | 否 | 面部中心与照片顶部的高度比例,默认为`0.45` |
| top_distance_max | float | 否 | 头部与照片顶部距离的比例最大值,默认为`0.12` |
| top_distance_min | float | 否 | 头部与照片顶部距离的比例最小值,默认为`0.1` |
-
+| brightness_strength | float | 否 | 亮度调整强度,默认为`0` |
+| contrast_strength | float | 否 | 对比度调整强度,默认为`0` |
+| sharpen_strength | float | 否 | 锐化调整强度,默认为`0` |
+| saturation_strength | float | 否 | 饱和度调整强度,默认为`0` |
**返回参数:**
@@ -247,7 +250,15 @@ curl -X POST "http://127.0.0.1:8080/idphoto" \
-F "face_detect_model=mtcnn" \
-F "hd=true" \
-F "dpi=300" \
--F "face_alignment=true"
+-F "face_alignment=true" \
+-F 'head_height_ratio=0.45' \
+-F 'head_measure_ratio=0.2' \
+-F 'top_distance_min=0.1' \
+-F 'top_distance_max=0.12' \
+-F 'sharpen_strength=0' \
+-F 'saturation_strength=0' \
+-F 'brightness_strength=10' \
+-F 'contrast_strength=0'
```
### 2. 添加背景色
@@ -305,8 +316,7 @@ curl -X 'POST' \
### 7. 证件照裁切
```bash
-curl -X 'POST' \
- 'http://127.0.0.1:8080/idphoto_crop?head_measure_ratio=0.2&head_height_ratio=0.45&top_distance_max=0.12&top_distance_min=0.1' \
+curl -X 'POST' 'http://127.0.0.1:8080/idphoto_crop' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'input_image=@idphoto_matting.png;type=image/png' \
@@ -314,7 +324,11 @@ curl -X 'POST' \
-F 'width=295' \
-F 'face_detect_model=mtcnn' \
-F 'hd=true' \
- -F 'dpi=300'
+ -F 'dpi=300' \
+ -F 'head_height_ratio=0.45' \
+ -F 'head_measure_ratio=0.2' \
+ -F 'top_distance_min=0.1' \
+ -F 'top_distance_max=0.12'
```
@@ -328,13 +342,6 @@ import requests
url = "http://127.0.0.1:8080/idphoto"
input_image_path = "demo/images/test0.jpg"
-# 设置请求参数
-params = {
- "head_measure_ratio": 0.2,
- "head_height_ratio": 0.45,
- "top_distance_max": 0.12,
- "top_distance_min": 0.1,
-}
files = {"input_image": open(input_image_path, "rb")}
data = {
"height": 413,
@@ -344,6 +351,14 @@ data = {
"hd": True,
"dpi": 300,
"face_alignment": True,
+ "head_measure_ratio": 0.2,
+ "head_height_ratio": 0.45,
+ "top_distance_max": 0.12,
+ "top_distance_min": 0.1,
+ "brightness_strength": 0,
+ "contrast_strength": 0,
+ "sharpen_strength": 0,
+ "saturation_strength": 0,
}
response = requests.post(url, params=params, files=files, data=data).json()
@@ -481,14 +496,6 @@ import requests
# 设置请求的 URL
url = "http://127.0.0.1:8080/idphoto_crop"
-# 设置请求参数
-params = {
- "head_measure_ratio": 0.2,
- "head_height_ratio": 0.45,
- "top_distance_max": 0.12,
- "top_distance_min": 0.1,
-}
-
# 设置文件和其他表单数据
input_image_path = "idphoto_matting.png"
files = {"input_image": ("idphoto_matting.png", open(input_image_path, "rb"), "image/png")}
@@ -498,10 +505,14 @@ data = {
"face_detect_model": "mtcnn",
"hd": "true",
"dpi": 300,
+ "head_measure_ratio": 0.2,
+ "head_height_ratio": 0.45,
+ "top_distance_max": 0.12,
+ "top_distance_min": 0.1,
}
# 发送 POST 请求
-response = requests.post(url, params=params, files=files, data=data)
+response = requests.post(url, files=files, data=data)
# 检查响应
if response.ok:
diff --git a/docs/api_EN.md b/docs/api_EN.md
index 56a4aab3..39d9e5d0 100644
--- a/docs/api_EN.md
+++ b/docs/api_EN.md
@@ -59,6 +59,10 @@ It is important to note that both generated photos are transparent (RGBA four-ch
| head_height_ratio | float | No | The ratio of the face center to the top of the photo, with a default value of `0.45`. |
| top_distance_max | float | No | The maximum ratio of the head to the top of the photo, with a default value of `0.12`. |
| top_distance_min | float | No | The minimum ratio of the head to the top of the photo, with a default value of `0.1`. |
+| brightness_strength | float | No | Brightness adjustment strength, default is `0` |
+| contrast_strength | float | No | Contrast adjustment strength, default is `0` |
+| sharpen_strength | float | No | Sharpening adjustment strength, default is `0` |
+| saturation_strength | float | No | Saturation adjustment strength, default is `0` |
**Return Parameters:**
@@ -329,12 +333,6 @@ url = "http://127.0.0.1:8080/idphoto"
input_image_path = "demo/images/test0.jpg"
# Set request parameters
-params = {
- "head_measure_ratio": 0.2,
- "head_height_ratio": 0.45,
- "top_distance_max": 0.12,
- "top_distance_min": 0.1,
-}
files = {"input_image": open(input_image_path, "rb")}
data = {
"height": 413,
@@ -344,9 +342,17 @@ data = {
"hd": True,
"dpi": 300,
"face_alignment": True,
+ "head_measure_ratio": 0.2,
+ "head_height_ratio": 0.45,
+ "top_distance_max": 0.12,
+ "top_distance_min": 0.1,
+ "brightness_strength": 0,
+ "contrast_strength": 0,
+ "sharpen_strength": 0,
+ "saturation_strength": 0,
}
-response = requests.post(url, params=params, files=files, data=data).json()
+response = requests.post(url, files=files, data=data).json()
# response is a JSON formatted dictionary containing status, image_base64_standard, and image_base64_hd
print(response)
@@ -481,14 +487,6 @@ import requests
# Set the request URL
url = "http://127.0.0.1:8080/idphoto_crop"
-# Set request parameters
-params = {
- "head_measure_ratio": 0.2,
- "head_height_ratio": 0.45,
- "top_distance_max": 0.12,
- "top_distance_min": 0.1,
-}
-
# Set file and other form data
input_image_path = "idphoto_matting.png"
files = {"input_image": ("idphoto_matting.png", open(input_image_path, "rb"), "image/png")}
@@ -498,10 +496,14 @@ data = {
"face_detect_model": "mtcnn",
"hd": "true",
"dpi": 300,
+ "head_measure_ratio": 0.2,
+ "head_height_ratio": 0.45,
+ "top_distance_max": 0.12,
+ "top_distance_min": 0.1,
}
# Send POST request
-response = requests.post(url, params=params, files=files, data=data)
+response = requests.post(url, files=files, data=data)
# Check response
if response.ok: