Skip to content

Commit

Permalink
docs: update readme api
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeyi-Lin committed Sep 5, 2024
1 parent 131f8e3 commit 71a374c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 17 deletions.
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,42 +130,74 @@ python inference.py -t generate_layout_photos -i ./idhoto_ab.jpg -o ./idhoto_lay

# ⚡️ 部署 API 服务

详细请参考 [API 文档](docs/api_CN.md),含 [RestAPI 请求方式](https://github.com/Zeyi-Lin/HivisionIDPhotos/blob/master/docs/api_CN.md#1%EF%B8%8F%E2%83%A3-python-requests-%E8%AF%B7%E6%B1%82%E6%96%B9%E6%B3%95)

## 启动后端

```
python deploy_api.py
```

## 请求 API 服务 - Python 脚本
## 请求 API 服务 - Python Request

### 1. 证件照制作

输入 1 张照片,获得 1 张标准证件照和 1 张高清证件照的 4 通道透明 png

```bash
python requests_api.py -u http://127.0.0.1:8080 -i images/test.jpg -o ./idphoto.png --height 413 --width 295
import requests

url = "http://127.0.0.1:8080/idphoto"
input_image_path = "images/test.jpg"

files = {"input_image": open(input_image_path, "rb")}
data = {"height": 413, "width": 295}

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

# response为一个json格式字典,包含status、image_base64_standard和image_base64_hd三项
print(response)

```

### 2. 增加底色

输入 1 张 4 通道透明 png,获得 1 张增加了底色的图像

```bash
python requests_api.py -u http://127.0.0.1:8080 -t add_background -i ./idphoto.png -o ./idhoto_ab.jpg -c 000000 -k 30
import requests

url = "http://127.0.0.1:8080/add_background"
input_image_path = "test.png"

files = {"input_image": open(input_image_path, "rb")}
data = {"color": '638cce', 'kb': None}

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

# response为一个json格式字典,包含status和image_base64
print(response)
```

### 3. 得到六寸排版照

输入 1 张 3 通道照片,获得 1 张六寸排版照

```bash
python requests_api.py -u http://127.0.0.1:8080 -t generate_layout_photos -i ./idhoto_ab.jpg -o ./idhoto_layout.jpg --height 413 --width 295 -k 200
import requests

url = "http://127.0.0.1:8080/generate_layout_photos"
input_image_path = "test.jpg"

files = {"input_image": open(input_image_path, "rb")}
data = {"height": 413, "width": 295, "kb": 200}

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

# response为一个json格式字典,包含status和image_base64
print(response)
```

更多请求方式请参考 [API 文档](docs/api_CN.md),含 Python 脚本请求、Python Request 请求、Java 请求。

<br>

# 🐳 Docker 部署
Expand Down
58 changes: 49 additions & 9 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,34 +130,74 @@ python inference.py -t generate_layout_photos -i ./idhoto_ab.jpg -o ./idhoto_lay

# ⚡️ Deploy API service

Please refer to the [API documentation](docs/api_EN.md) for details, including [RestAPI request methods](https://github.com/Zeyi-Lin/HivisionIDPhotos/blob/master/docs/api_CN.md#Python-Requests-Method)
## Start backend

```
python deploy_api.py
```

**Request API service (Python)**
## Request API Service - Python Request

Use Python to send a request to the service:
### 1. ID Photo Creation

ID photo production (input 1 photo, get 1 standard ID photo and 1 high-definition ID photo 4-channel transparent png):
Input 1 photo, receive 1 standard ID photo and 1 high-definition ID photo in 4-channel transparent PNG format.

```bash
python requests_api.py -u http://127.0.0.1:8080 -i images/test.jpg -o ./idphoto.png -s '(413,295)'
import requests

url = "http://127.0.0.1:8080/idphoto"
input_image_path = "images/test.jpg"

files = {"input_image": open(input_image_path, "rb")}
data = {"height": 413, "width": 295}

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

# response is a JSON dictionary containing status, image_base64_standard, and image_base64_hd
print(response)

```

Add background color (input 1 4-channel transparent png, get 1 image with added background color):
### 2. Add Background Color

Input 1 4-channel transparent PNG, receive 1 image with added background color.

```bash
python requests_api.py -u http://127.0.0.1:8080 -t add_background -i ./idphoto.png -o ./idhoto_ab.jpg -c '(0,0,0)' -k 30
import requests

url = "http://127.0.0.1:8080/add_background"
input_image_path = "test.png"

files = {"input_image": open(input_image_path, "rb")}
data = {"color": '638cce', 'kb': None}

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

# response is a JSON dictionary containing status and image_base64
print(response)
```

Get a six-inch layout photo (input a 3-channel photo, get a six-inch layout photo):
### 3. Get 6-inch Layout Photo

Input 1 3-channel photo, receive 1 6-inch layout photo.

```bash
python requests_api.py -u http://127.0.0.1:8080 -t generate_layout_photos -i ./idhoto_ab.jpg -o ./idhoto_layout.jpg -s '(413,295)' -k 200
import requests

url = "http://127.0.0.1:8080/generate_layout_photos"
input_image_path = "test.jpg"

files = {"input_image": open(input_image_path, "rb")}
data = {"height": 413, "width": 295, "kb": 200}

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

# response is a JSON dictionary containing status and image_base64
print(response)
```

For more request methods, please refer to the [API documentation](docs/api_EN.md), including Python script requests, Python Request requests, and Java requests.

<br>

# 🐳 Docker deployment
Expand Down

0 comments on commit 71a374c

Please sign in to comment.