# portrait-matting **Repository Path**: einak/portrait-matting ## Basic Information - **Project Name**: portrait-matting - **Description**: 通过使用MODNet模型实现人脸与背景的分割,为证件照替换背景。 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2022-11-18 - **Last Updated**: 2022-11-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 证件照背景替换 使用模型MODNet实现人脸抠图,对证件照背景进行替换。 模型来自于**柯章翰** github仓库地址为[链接](https://github.com/ZHKKKe/MODNet) - 可以通过添加背景图片给证件照更换背景 - 可以通过自定义rgb元组为证件照更换背景颜色 ------- ## 项目运行 **测试图片来源于网络,侵删** 项目中`python`环境为3.8 **1.安装依赖** ```shell pip install -r requirements.txt ``` **2.将背景图片放置于`background`文件夹下** **3.将证件照图片放置于`input`文件夹下** **4.修改`run_replace.py`中的代码** ```python input_image_file = "portrait_2.png" # background_image_file = "bg_2.jpg" # 格式为(red, green, blue) background_image_file = (255, 0, 0) output_image_file = "output_rgb.jpg" ``` ------- ## 最终实现效果 初始图片: ![portrait](./input/portrait_2.png) rgb图片效果: ![portrait](./output/output_rgb.jpg) 自定义背景图片效果 ![portrait](./output/output_bg.jpg)