SuperAPI AI Directory

HivisionIDPhotos

ID photo generation

Open website

About this tool

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]

  1. Lightweight matting: supports pure offline operation and only requires a CPU for fast inference.
  2. ID photo generation: can generate different standard ID photos according to different size specifications as well as six-inch layout photos.
  3. Provides a Gradio Demo page, allowing ID photo operations and interaction to be completed in a local Web page.
  4. Provides API interfaces, supporting base64 image input, dpi, face_alignment, beauty retouching, and other parameters.
  5. Supports face rotation alignment, custom background color (HEX input), sharing template photos, American-style ID photo backgrounds, layout photo crop lines, and other functions.
  6. Print layouts support five layout sizes: six-inch, five-inch, A4, 3R, and 4R.
  7. Default photo download supports 300DPI, and supports five-inch photo paper and JPEG download options.

[Usage]

  1. 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.
  2. 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.
  3. Face detection model configuration (optional).
  4. 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.
  5. 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.
  6. 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.
  7. 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]

  1. Individuals or teams quickly producing standard ID photos and layout photos.
  2. Developers integrating ID photo generation capabilities into their own applications, such as WeChat Mini Programs, Windows clients, etc.
  3. Producing ID photos in a pure offline or resource-constrained environment.
  4. Solving the problem of emergency ID photo production.

[Custom configuration]

  1. Modify preset sizes and colors: modify size_list_CN.csv for sizes and color_list_CN.csv for colors.
  2. Add a watermark: place the font file in the hivision/plugin/font folder, and modify the font_file parameter in hivision/plugin/watermark.py.
  3. 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.
  4. Modify the top navigation bar of the Gradio Demo: modify demo/assets/title.md.
  5. 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.