# shufazititiqu **Repository Path**: duan-qi-rui/shufazititiqu ## Basic Information - **Project Name**: shufazititiqu - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-06 - **Last Updated**: 2025-06-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 书法字体图像处理项目 --- ## 主要功能 - **`seperate_img.py`** 对原始字帖图片(默认为 `hanzi.jpg`)进行网格切分(默认为10x10),将每个汉字单独保存为灰度图至 `seperate` 目录。切分行列数可在脚本内配置。 脚本运行后会在 `seperate` 目录生成类似 `seperate1.png` 的文件。 - **`steps_of_img.py`** 依次展示对 `hanzi.jpg` 进行图像处理的各个步骤:从灰度图开始,包括二值化、腐蚀、膨胀、中值滤波、闭运算、边缘检测到最终的轮廓标记。每一步处理后的图像会显示出来,并自动保存至 `steps` 目录,文件名按步骤命名(如 `step1_gray.png`, `step2_binary.png` 等)。如图所示: ![alt text](steps/step1_gray.png) ![alt text](steps/step2_binary.png) ![alt text](steps/step3_erode.png) ![alt text](steps/step4_dilate.png) ![alt text](steps/step5_median.png) ![alt text](steps/step6_close.png) ![alt text](steps/step7_canny.png) ![alt text](steps/step8_result.png) --- ## 使用方法 1. **环境准备** * 安装依赖库:`matplotlib`、`numpy`、`Pillow`、`opencv-python` ```bash pip install matplotlib numpy Pillow opencv-python ``` * 确保项目根目录下有 `hanzi.jpg` (原始字帖图片)和 `SimHei.ttf` 字体文件(用于中文标题显示)。 2. **运行脚本** * 运行 `seperate_img.py`: ```bash python seperate_img.py ``` 该脚本会将 `hanzi.jpg` 按默认 10x10 网格切分,输出每个汉字的灰度图至 `seperate` 文件夹。 * 运行 `steps_of_img.py`: ```bash python steps_of_img.py ``` 该脚本会逐步展示并保存对 `hanzi.jpg` 的每个图像处理步骤的结果,所有图片保存在 `steps` 目录。 --- ## 注意事项 - 脚本默认读取当前目录下的 `hanzi.jpg` 和 `SimHei.ttf`。如果文件不在当前目录或名称不同,请修改脚本内的 `IMG_PATH` 和 `FONT_PATH` (在 `steps_of_img.py` 中) 或 `DEFAULT_SOURCE_IMG` (在 `seperate_img.py` 中) 常量。 - 输出目录 `seperate` 和 `steps` 会在脚本运行时自动创建(如果不存在)。 - 若遇到“拒绝访问”或“找不到文件”类错误,请检查文件路径和权限。 - 输出图片标题为中文,需确保 `matplotlib` 能正确加载 `SimHei.ttf` 字体。如果字体文件缺失或路径不正确,中文标题可能无法正常显示,脚本中会有相应的警告信息。 --- ## 目录结构示例 ``` training-calligraphy-fonts-master/ ├── hanzi.jpg ├── SimHei.ttf ├── seperate_img.py ├── steps_of_img.py ├── seperate/ # 由 seperate_img.py 生成 │ └── seperate1.png ... ├── steps/ # 由 steps_of_img.py 生成 │ └── step1_gray.png ... └── README.md ``` --- ## 参考资料 - [OpenCV官方文档](https://docs.opencv.org/4.x/d6/d00/tutorial_py_root.html) - [Pillow (PIL Fork) 官方文档](https://pillow.readthedocs.io/en/stable/) - [matplotlib官方文档](https://matplotlib.org/stable/index.html) --- ## 个人信息 - 学号: 202352320120 - 年级: 2023 - 专业: 智能科学与技术 - 班级: 1 班