# image_matting **Repository Path**: lzptg/image_matting ## Basic Information - **Project Name**: image_matting - **Description**: No description available - **Primary Language**: TypeScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-13 - **Last Updated**: 2026-01-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Hello Python 项目 一个基础的 Python 项目模板,配置了完整的开发环境和构建工具,特别适用于快速开发和打包 Python 应用程序。 ## 🎯 项目特色 - **AI 版本支持**: 提供高精度 AI 抠图版本 - **自动化构建**: 一键打包为独立 exe 文件 - **跨平台脚本**: 支持 Windows 和 Unix 系统 - **模块化架构**: 清晰的项目结构,易于扩展 ## 📦 版本说明 ### 🤖 AI 版本(推荐) - **文件**: `masking.exe` (482MB) - **特点**: 高精度 AI 抠图,支持多种深度学习模型 - **优势**: 抠图效果最佳,专业级质量 - **要求**: 首次运行需要网络下载模型文件 - **构建**: `python scripts.py masking:binary` > 💡 **建议**: 使用 AI 版本以获得最佳的抠图效果。详细信息请查看 [版本指南](VERSION_GUIDE.md)。 ## 📁 项目结构 ``` hello_python/ ├── modules/ # 模块目录 │ ├── hello_python/ # Hello Python 基础模块 │ │ ├── main.py # 主程序文件 │ │ ├── build_exe.bat # 构建脚本 │ │ └── hello_python.spec # PyInstaller配置 │ └── masking/ # 一键抠图模块 │ ├── cli.py # 命令行接口 │ ├── remover.py # 核心功能 │ ├── __init__.py # 模块初始化 │ └── __main__.py # 模块入口点 ├── dist/ # 打包输出目录 │ ├── hello_python.exe # Hello Python可执行文件 │ └── masking.exe # 抠图工具可执行文件 ├── build/ # 构建临时文件 ├── venv/ # Python虚拟环境 ├── scripts.py # 统一脚本管理器 ├── requirements.txt # 项目依赖 ├── pyproject.toml # 项目配置 └── README.md # 项目说明 ``` ## 🚀 使用方法 ### 基本语法 ```bash # 查看所有可用模块和命令 python scripts.py # 运行模块命令 python scripts.py : # 运行全局命令 python scripts.py ``` ### 可用模块 #### 1. Hello Python 基础模块 (`hello_python`) ```bash # 运行程序 python scripts.py hello_python:run # 打包为exe文件 python scripts.py hello_python:build # 运行打包的exe文件 python scripts.py hello_python:run:exe ``` #### 2. 一键抠图模块 (`masking`) ```bash # 显示帮助信息 python scripts.py masking:help # 命令行模式 python scripts.py masking:cli # 打包为独立的二进制文件 python scripts.py masking:binary ``` ### 全局命令 ```bash # 安装项目依赖 python scripts.py install # 安装开发依赖 python scripts.py install:dev # 清理构建文件 python scripts.py clean # 创建虚拟环境 python scripts.py env:create # 激活虚拟环境(提示) python scripts.py env:activate # 格式化代码 python scripts.py format # 代码检查 python scripts.py lint ``` ## 📍 路径处理规则 ### 输入路径 - **绝对路径**:直接使用 `C:\path\to\image.jpg` - **相对路径**:相对于执行文件目录 `photos\image.jpg` → `执行目录\photos\image.jpg` ### 输出路径 - **指定输出**:`-o output\result.png` → `执行目录\output\result.png` - **默认单文件**:自动生成 `执行目录\原文件名_no_bg.png` - **默认批量**:自动创建 `执行目录\no_background\` 文件夹 ### 使用场景 #### 场景 1:便携使用 1. 将 `masking.exe` 复制到包含图片的文件夹 2. 在该文件夹中运行 `masking.exe -d .` 3. 所有处理结果会保存在 `no_background` 子文件夹中 #### 场景 2:指定输入输出 ```bash # 处理其他位置的图片,但输出到当前目录 masking.exe -i C:\Pictures\photo.jpg -o result.png # 批量处理其他位置的图片,输出到当前目录 masking.exe -d C:\Pictures\ -o processed\ ``` ### 激活虚拟环境 在 Windows 命令提示符中: ```cmd venv\Scripts\activate ``` 在 Git Bash 或 Linux/Mac 中: ```bash source venv/Scripts/activate ``` ## 项目信息 - Python 版本:3.13.8 - 虚拟环境位置:`./venv/` - 包管理器:pip 24.2 ## 项目脚本(类似 npm scripts) 本项目提供了类似 JavaScript 项目中 npm scripts 的功能,通过配置文件和脚本运行器来统一管理常用命令。 ### 📁 配置文件 - **[pyproject.toml](file://c:\workspace\hello_python\pyproject.toml)** - 项目配置文件(类似 package.json) - **[scripts.py](file://c:\workspace\hello_python\scripts.py)** - 脚本运行器(Python 版本) - **[run.bat](file://c:\workspace\hello_python\run.bat)** - Windows 批处理脚本 - **[run.sh](file://c:\workspace\hello_python\run.sh)** - 跨平台 shell 脚本 ### 🚀 快速使用 ```bash # 查看所有可用命令 python scripts.py help # 运行程序 python scripts.py hello_python:run # 安装依赖 python scripts.py install # 打包抠图文件 python scripts.py masking:binary ``` ## 🚀 构建方法 ### 方法 1:使用项目脚本(推荐) ```bash # Git Bash环境 python scripts.py masking:binary ``` ### 方法 2:使用 Windows 批处理 ```cmd # Windows命令行 python scripts.py masking:binary ``` ### 📋 可用命令 | 命令 | 描述 | 需要虚拟环境 | | ---------------------- | --------------------------------- | ------------ | | `hello_python:run` | 运行 Hello Python 程序 | ❌ | | `hello_python:build` | 打包为 exe 文件 | ✅ | | `hello_python:run:exe` | 运行打包的 exe 文件 | ❌ | | `masking:help` | 显示抠图工具帮助信息 | ✅ | | `masking:cli` | 命令行模式 | ✅ | | `masking:binary` | 使用 PyInstaller 打包为二进制文件 | ✅ | | `install` | 安装项目依赖 | ✅ | | `install:dev` | 安装开发依赖 | ✅ | | `clean` | 清理构建文件 | ❌ | | `env:create` | 创建虚拟环境 | ❌ | | `env:activate` | 一键激活当前虚拟环境 | ❌ | | `env:create-activate` | 创建便捷的激活脚本文件 | ❌ | | `format` | 格式化代码 | ✅ | | `lint` | 代码检查 | ✅ | ## 标记说明 - 🐍 需要激活虚拟环境的命令 - 🎮 交互式命令(需要额外参数) ## 依赖管理 生成依赖列表: ```bash pip freeze > requirements.txt ``` 安装依赖: ```bash pip install -r requirements.txt ``` ## 打包为 EXE 文件 本项目已配置了 PyInstaller 用于将 Python 代码打包为独立的 exe 文件。 ### 手动打包 1. 激活虚拟环境 2. 安装 PyInstaller(如果还未安装): ```bash pip install pyinstaller ``` 3. 打包为 exe 文件: ```bash pyinstaller --onefile --name hello_python main.py ``` 4. 生成的 exe 文件位于 `dist/hello_python.exe` ### 使用脚本打包 直接运行打包脚本: ```cmd build_exe.bat ``` ### 文件说明 - `hello_python.spec` - PyInstaller 配置文件 - `build/` - 构建过程中的临时文件 - `dist/hello_python.exe` - 最终生成的可执行文件(约 7.8MB)