From fd90bb94315c12aa18ac3361a609fad7b42320e4 Mon Sep 17 00:00:00 2001 From: Ze-Yi LIN <58305964+Zeyi-Lin@users.noreply.github.com> Date: Thu, 12 Sep 2024 01:36:01 +0800 Subject: [PATCH] feat: api idphoto hd (#107) * idphoto hd * Update deploy_api.py * Update api_CN.md --- .github/workflows/sync-to-gitee.yml | 22 --------------------- deploy_api.py | 30 ++++++++++++++++------------- docs/api_CN.md | 5 +++-- 3 files changed, 20 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/sync-to-gitee.yml diff --git a/.github/workflows/sync-to-gitee.yml b/.github/workflows/sync-to-gitee.yml deleted file mode 100644 index bcbf895..0000000 --- a/.github/workflows/sync-to-gitee.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Sync to Gitee - -on: - push: - branches: - - master # 或者你想要同步的其他分支 - -jobs: - sync: - runs-on: ubuntu-latest - environment: gitee - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Push to Gitee - run: | - git config --global user.name ${{ vars.GITEE_USERNAME }} - git config --global user.email ${{ vars.GITEE_EMAIL }} - git remote add gitee https://${{ vars.GITEE_USERNAME }}:${{ secrets.GITEE_TOKEN }}@gitee.com/${{ vars.GITEE_USERNAME }}/HivisionIDPhotos.git - git push -f gitee master:master diff --git a/deploy_api.py b/deploy_api.py index 43904f2..b05e1bd 100644 --- a/deploy_api.py +++ b/deploy_api.py @@ -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() @@ -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"), ): @@ -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"] @@ -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() diff --git a/docs/api_CN.md b/docs/api_CN.md index 8d318ed..b6c4a5b 100644 --- a/docs/api_CN.md +++ b/docs/api_CN.md @@ -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. 添加背景色 @@ -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()