HivisionIDPhotos is a lightweight and efficient AI ID photo production algorithm project, aiming to develop a practical and systematic intelligent ID photo production algorithm. Through a complete AI model workflow, it realizes recognition, matting, and ID photo generation for various user photo-taking scenarios.
[Main capabilities]
- Lightweight matting: supports pure offline operation and only requires a CPU for fast inference.
- ID photo generation: can generate different standard ID photos according to different size specifications as well as six-inch layout photos.
- Provides a Gradio Demo page, allowing ID photo operations and interaction to be completed in a local Web page.
- Provides API interfaces, supporting base64 image input, dpi, face_alignment, beauty retouching, and other parameters.
- Supports face rotation alignment, custom background color (HEX input), sharing template photos, American-style ID photo backgrounds, layout photo crop lines, and other functions.
- Print layouts support five layout sizes: six-inch, five-inch, A4, 3R, and 4R.
- Default photo download supports 300DPI, and supports five-inch photo paper and JPEG download options.
[Usage]
- Environment requirements: Python >= 3.7 (the project is mainly tested on Python 3.10), and the operating system supports Linux, Windows, and MacOS. It is recommended to use conda to create a Python 3.10 virtual environment.
- Download the portrait matting model weight files: all models are stored in the project's hivision/creator/weights directory. If the download is not smooth, you can go to SwanHub to download.
- Face detection model configuration (optional).
- Run the Gradio Demo: after executing the relevant command, a local Web page will be generated, where ID photo operations and interaction can be completed.
- Inference types include: idphoto, human_matting, add_background, generate_layout_photos. The portrait matting model weights and face detection model can be selected through parameters. More parameters can be viewed through python inference.py --help.
- Supports directly building images with Dockerfile, building with Docker compose, and after starting the Gradio Demo service, accessing it locally http://127.0.0.1:7860 for use.
- Provides environment variables for additional configuration.
[GPU acceleration] In the current version, the model that can be accelerated by NVIDIA GPU is birefnet-v1-lite, and it is necessary to ensure about 16GB of VRAM. Before use, CUDA and cuDNN need to be installed, and the corresponding versions should be installed according to the onnxruntime-gpu documentation and the official PyTorch website. CUDA supports backward compatibility.
[Applicable scenarios]
- Individuals or teams quickly producing standard ID photos and layout photos.
- Developers integrating ID photo generation capabilities into their own applications, such as WeChat Mini Programs, Windows clients, etc.
- Producing ID photos in a pure offline or resource-constrained environment.
- Solving the problem of emergency ID photo production.
[Custom configuration]
- Modify preset sizes and colors: modify size_list_CN.csv for sizes and color_list_CN.csv for colors.
- Add a watermark: place the font file in the hivision/plugin/font folder, and modify the font_file parameter in hivision/plugin/watermark.py.
- Add social media template photos: place the template image in the hivision/plugin/template/assets folder, add the template information in template_config.json, and at the same time add the template name to the TEMPLATE_NAME_LIST variable in the _generate_image_template function in demo/processor.py.
- Modify the top navigation bar of the Gradio Demo: modify demo/assets/title.md.
- Add or modify sizes in the print layout: modify the print_switch dictionary in demo/locales.py, then rerun python app.py.
[Community extensions] The community has built many interesting applications and extensions, including HivisionIDPhotos-cpp (C++ version), ai-idphoto (uniapp multi-platform compatible version), HivisionIDPhotos-uniapp-WeChat-gpto1 (WeChat Mini Program), HivisionIDPhotos-windows-GUI (Windows client app), HivisionIDPhotos-NAS (Synology NAS deployment tutorial), etc.
[License and Citation] This project is licensed under Apache-2.0. If HivisionIDPhotos is used in research or projects, it is recommended to cite the related work.