本项目包含四个实用的文档图像处理脚本,支持证件自动裁剪与多图合并功能,适用于文档归档、打印整理等场景。
- 功能:自动识别图像中的证件区域,裁剪并去除空白边缘。
- 使用方法:
python document_card_cropper.py
- 功能:将多个图片文件按文件名字母顺序合并排版至 A4 页面。
- 支持格式:PNG、JPG/JPEG
- 使用方法:
python document_image_merger.py
- 功能:展平图像,去除模糊和阴影,提升文档阅读效果。
- 支持格式:PNG、JPG/JPEG
- 使用方法:
python document_flatten_tool.py
- 注意:该工具依赖于训练好的模型。
- 功能:将图像合并工具生成的图片生成为word文档,以便打印。
- 使用方法:
python imageMergerDoc.py
确保你已经安装 Python 3,并使用以下命令安装必要依赖:
pip install -r requirements.txt- 使用
document_card_cropper.py处理包含证件的图片,自动裁剪出证件区域。 - 使用
document_image_merger.py将裁剪后的图像合并排版成标准 A4 页面。 - 使用
document_flatten_tool.py展平图像并去除模糊和阴影。 - 使用
imageMergerDoc.py将图像合并工具生成的图片生成为word文档,以便打印。
pip install pyinstaller# 通用打包(无图标)
pyinstaller -F -w document_card_cropper.py
# 带图标打包(推荐)
pyinstaller -F -w -i document_merger_icon.ico document_image_merger.py
pyinstaller -F -w -i imageMergerDoc_icon.ico imageMergerDoc.py# 避免 docx 导入错误
pyinstaller -F -w -i imageMergerDoc_icon.ico --hidden-import=docx imageMergerDoc.py
# 包含模型文件(Windows 分号分隔)
pyinstaller -F -w --icon=document_card_cropper.ico --add-data "models/card_correction.onnx;models" document_card_cropper.py
pyinstaller -F -w --icon=document_card_cropper.ico --add-data "models/drnet.onnx" --add-data "models/gcnet.onnx" --add-data "models/nafdpm.onnx" --add-data "models/unetcnn.onnx" --add-data "models/uvdoc.onnx" document_flatten_tool.py# 注意:Linux 使用冒号分隔
pyinstaller -F -w --icon=document_card_cropper.ico --add-data "models/card_correction.onnx:models" document_card_cropper.py
pyinstaller -F -w --icon=document_merger_icon.ico --add-data "models/drnet.onnx:models" --add-data "models/gcnet.onnx:models" --add-data "models/nafdpm.onnx:models" --add-data "models/unetcnn.onnx:models" --add-data "models/uvdoc.onnx:models" document_flatten_tool.pynuitka --onefile --windows-disable-console --windows-icon-from-ico=document_card_cropper.ico --include-data-dir=models=./models document_card_cropper.py --output-dir=nuitka_out打包后大小约 96MB。需确保
models文件夹位于同目录。
nuitka document_card_cropper.py --jobs=0 --mingw64 --standalone --onefile --show-progress --windows-console-mode=disable --include-module=wx._xml --include-data-files=document_card_cropper.png=. --include-data-files=document_card_cropper.ico=. --include-data-dir=models=models --output-dir=nuitka_outhttps://cloud.189.cn/t/URZJBnvq6Vz2(访问码:ox1j)
- Python 版本:3.x
- 测试系统:Windows 10 / Ubuntu 22.04
本项目直接使用了下面项目的源代码和模型文件: