Skip to content

Latest commit

 

History

History
270 lines (168 loc) · 7.77 KB

README_EN.md

File metadata and controls

270 lines (168 loc) · 7.77 KB

HivisionIDPhoto

English / 中文 / 日本語

GitHub SwanHub Demo zhihu Spaces

Zeyi-Lin%2FHivisionIDPhotos | Trendshift

🤩Project Update

  • Online Demo: SwanHub DemoSpaces

  • 2024.9.2: Update Adjusted photo KB sizeDockerHub

  • 2023.12.1: Update API deployment (based on fastapi)

  • 2023.6.20: Update Preset size menu

  • 2023.6.19: Update Layout photos

  • 2023.6.13: Update Center gradient color

  • 2023.6.11: Update Top and bottom gradient color

  • 2023.6.8: Update Custom size

  • 2023.6.4: Update Custom background color, face detection bug notification

  • 2023.5.10: Update Change the background without changing the size


Overview

🚀Thank you for your interest in our work. You may also want to check out our other achievements in the field of image processing. Please feel free to contact us at zeyi.lin@swanhub.co.

HivisionIDPhoto aims to develop a practical intelligent algorithm for producing ID photos. It uses a complete set of model workflows to recognize various user photo scenarios, perform image segmentation, and generate ID photos.

HivisionIDPhoto can:

  1. Perform lightweight image segmentation (Only CPU is needed for fast inference.)
  2. Generate standard ID photos and six-inch layout photos according to different size specifications
  3. Provide beauty features (waiting)
  4. Provide intelligent formal wear replacement (waiting)

If HivisionIDPhoto is helpful to you, please star this repo or recommend it to your friends to solve the problem of emergency ID photo production!


🔧Environment Dependencies and Installation

  • Python >= 3.7 (The main test of the project is in Python 3.10.)
  • onnxruntime
  • OpenCV
  • Option: Linux, Windows, MacOS

Installation

  1. Clone repo
git clone https://github.com/Zeyi-Lin/HivisionIDPhotos.git
cd  HivisionIDPhotos
  1. (Important) Install dependent packages

It is recommended to create a Python 3.10 virtual environment with conda and then execute the following command.

pip install -r requirements.txt

3. Download Pretrain file

Download the weight file hivision_modnet.onnx from our Release and save it to the root directory.


🚀 Gradio Demo

python app.py

Running the program will generate a local web page, where operations and interactions with ID photos can be completed.


🚀 Python Inference

1. ID Photo Production

Input 1 photo, get 1 standard ID photo and 1 HD ID photo in a transparent PNG with 4 channels.

python inference.py -i images/test.jpg -o ./idphoto.png -s '(413,295)'

2. Add Background Color

Input 1 transparent PNG with 4 channels, get an image with added background color.

python inference.py -t add_background -i ./idphoto.png -o ./idhoto_ab.jpg -c '(0,0,0)' -k 30

3. Obtain Six-Inch Layout Photo

Input 1 photo with 3 channels, obtain one six-inch layout photo.

python inference.py -t generate_layout_photos -i ./idhoto_ab.jpg -o ./idhoto_layout.jpg -s '(413,295)' -k 200

⚡️ Deploy API service

python deploy_api.py

Request API service (Python)

Use Python to send a request to the service:

ID photo production (input 1 photo, get 1 standard ID photo and 1 high-definition ID photo 4-channel transparent png):

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

Add background color (input 1 4-channel transparent png, get 1 image with added background color):

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

Get a six-inch layout photo (input a 3-channel photo, get a six-inch layout photo):

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

🐳 Docker deployment

1. Pull or Build Image

Choose one of the following three methods

Method 1 - Pull Image from DockerHub:

docker pull linzeyi/hivision_idphotos:v1
docker tag linzeyi/hivision_idphotos:v1 hivision_idphotos

Method 2 - Build Image:

After ensuring that the model weight file hivision_modnet.onnx is placed in the root directory, execute in the root directory:

docker build -t hivision_idphotos .

Method 3 - Docker Compose:

After ensuring that the model weight file hivision_modnet.onnx is placed in the root directory, execute in the root directory:

docker compose build

After the image is packaged, run the following command to start the Gradio service:

docker compose up -d

2. Run the Gradio Demo

After the image packaging is completed, run the following command to start the Gradio Demo service:

docker run -p 7860:7860 hivision_idphotos

You can access it locally at http://127.0.0.1:7860.

3. Run API backend service

docker run -p 8080:8080 hivision_idphotos python3 deploy_api.py

🌲 Friendship link

📖 Reference Projects

  1. MTCNN:
@software{ipazc_mtcnn_2021,
    author = {ipazc},
    title = {{MTCNN}},
    url = {https://github.com/ipazc/mtcnn},
    year = {2021},
    publisher = {GitHub}
}
  1. ModNet:
@software{zhkkke_modnet_2021,
    author = {ZHKKKe},
    title = {{ModNet}},
    url = {https://github.com/ZHKKKe/MODNet},
    year = {2021},
    publisher = {GitHub}
}

💻 Development Tips

1. How to modify the preset size?

After modifying size_list_CN.csv, run app.py again, where the first column is the size name, the second column is height, and the third column is width.


📧 Contact

If you have any questions, please email Zeyi.lin@swanhub.co

Copyright © 2023, ZeYiLin. All Rights Reserved.


Contributor

Zeyi-LinSAKURA-CATFeudalmanswpfYKaikaikaifangShaohonChenKashiwaByte


StarHistory

Star History Chart