Skip to content

Commit

Permalink
feat: api idphoto hd (#107)
Browse files Browse the repository at this point in the history
* idphoto hd

* Update deploy_api.py

* Update api_CN.md
  • Loading branch information
Zeyi-Lin authored Sep 11, 2024
1 parent 7ca017c commit fd90bb9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/sync-to-gitee.yml

This file was deleted.

30 changes: 17 additions & 13 deletions deploy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ def numpy_2_base64(img: np.ndarray):
@app.post("/idphoto")
async def idphoto_inference(
input_image: UploadFile,
height: str = Form(...),
width: str = Form(...),
height: int = Form(413),
width: int = Form(295),
human_matting_model: str = Form("hivision_modnet"),
face_detect_model: str = Form("mtcnn"),
head_measure_ratio=0.2,
head_height_ratio=0.45,
top_distance_max=0.12,
top_distance_min=0.10,
hd: bool = Form(True),
head_measure_ratio: float = 0.2,
head_height_ratio: float = 0.45,
top_distance_max: float = 0.12,
top_distance_min: float = 0.10,
):

image_bytes = await input_image.read()
Expand All @@ -66,15 +67,18 @@ async def idphoto_inference(
result_message = {
"status": True,
"image_base64_standard": numpy_2_base64(result.standard),
"image_base64_hd": numpy_2_base64(result.hd),
}

# 如果hd为True, 则增加高清照结果(png 4通道图像)
if hd:
result_message["image_base64_hd"] = numpy_2_base64(result.hd)

return result_message


# 人像抠图接口
@app.post("/human_matting")
async def idphoto_inference(
async def human_matting_inference(
input_image: UploadFile,
human_matting_model: str = Form("hivision_modnet"),
):
Expand Down Expand Up @@ -105,8 +109,8 @@ async def idphoto_inference(
@app.post("/add_background")
async def photo_add_background(
input_image: UploadFile,
color: str = Form(...),
kb: str = Form(None),
color: str = Form("000000"),
kb: int = Form(50),
render: int = Form(0),
):
render_choice = ["pure_color", "updown_gradient", "center_gradient"]
Expand Down Expand Up @@ -150,9 +154,9 @@ async def photo_add_background(
@app.post("/generate_layout_photos")
async def generate_layout_photos(
input_image: UploadFile,
height: str = Form(...),
width: str = Form(...),
kb: str = Form(None),
height: int = Form(413),
width: int = Form(295),
kb: int = Form(50),
):
# try:
image_bytes = await input_image.read()
Expand Down
5 changes: 3 additions & 2 deletions docs/api_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ curl -X POST "http://127.0.0.1:8080/idphoto" \
-F "height=413" \
-F "width=295" \
-F "human_matting_model=hivision_modnet" \
-F "face_detect_model=mtcnn"
-F "face_detect_model=mtcnn" \
-F "hd=true"
```

### 2. 添加背景色
Expand Down Expand Up @@ -148,7 +149,7 @@ url = "http://127.0.0.1:8080/idphoto"
input_image_path = "demo/images/test0.jpg"

files = {"input_image": open(input_image_path, "rb")}
data = {"height": 413, "width": 295, "human_matting_model": "hivision_modnet", "face_detect_model": "mtcnn"}
data = {"height": 413, "width": 295, "human_matting_model": "hivision_modnet", "face_detect_model": "mtcnn", "hd": True}

response = requests.post(url, files=files, data=data).json()

Expand Down

0 comments on commit fd90bb9

Please sign in to comment.