General Introduction
HivisionIDPhotos is an open source, lightweight AI photo ID creation tool that intelligently recognizes the user's photo scene and keying to generate a standard ID photo that meets a variety of specifications. The tool supports custom background colors and sizes, and in the future will also launch the beauty and intelligent change of formal dress function. Users can easily build a local service through Docker deployment, suitable for personal and enterprise photo ID production needs.
Function List
- Lightweight keying: Utilize efficient AI algorithms to accurately key portraits and generate images with transparent backgrounds.
- Multi-size photo ID generation: support passport photo, visa photo and other specifications of the photo ID generation.
- Six-inch Typeset Photo Generation: Typeset multiple ID photos into a standard six-inch photo for easy printing and batch production.
- Intelligent background change: supports adding or changing the background color for ID photos.
- API service: FastAPI-based API service, convenient for developers to integrate the photo ID function.
- Docker support: quickly get services up and running, simplify the installation process, and improve system compatibility.
- Live Web Interaction: Operate the photo ID generation process online through a local web page provided by the Gradio Demo.
Using Help
Installation and environment configuration
- Cloning Project:
git clone https://github.com/Zeyi-Lin/HivisionIDPhotos.git cd HivisionIDPhotos
- Install dependent environments:
pip install -r requirements.txt
- Download the model file: Place the pre-trained model file
hivision_modnet.onnx
Download and save it to the project root directory.
Running Local Services
- Start the Gradio Demo:
python app.py
After running the program, a local web page will be generated where the user can complete the generation and adjustment of the ID photo.
- Deploying API services:
python deploy_api.py
Deploying the API service through FastAPI, users can realize operations such as photo ID generation and background modification through the API.
Using API Services
- Send a request for ID photo creation:
import requests url = "http://127.0.0.1:8080" files = {'file': open('test.jpg', 'rb')} response = requests.post(f"{url}/generate_idphoto", files=files) with open('idphoto.png', 'wb') as f. f.write(response.content)
- Add the base color:
import requests url = "http://127.0.0.1:8080" files = {'file': open('idphoto.png', 'rb')} data = {'color': '(0,0,0)'} response = requests.post(f"{url}/add_background", files=files, data=data) with open('idphoto_ab.jpg', 'wb') as f. f.write(response.content)
- Generate a six-inch typeset photo:
import requests url = "http://127.0.0.1:8080" files = {'file': open('idphoto_ab.jpg', 'rb')} response = requests.post(f"{url}/generate_layout_photos", files=files) with open('idphoto_layout.jpg', 'wb') as f. f.write(response.content)
Docker Deployment
- Build the Docker image:
docker build -t hivisionidphotos .
- Run the Docker container:
docker run -p 8080:8080 hivisionidphotos