# test **Repository Path**: quano/test ## Basic Information - **Project Name**: test - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-03 - **Last Updated**: 2026-06-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TIF Watchdog 颜色转换服务 TIF 图片自动颜色转换服务,监听指定目录的新 TIF 文件,自动将特定颜色映射为统一蓝色。 ## 功能说明 - **监听目录**: 实时监控指定目录下的新 TIF 文件(文件名需以 `fire_risk_` 开头) - **颜色转换**: 将绿色 `(0,128,0,128)` 和特定蓝色 `(1,1,254,128)` 转换为统一蓝色 `(0,100,255,128)` - **防重复处理**: 记录已处理文件,避免重复转换 - **定时退出**: 可配置最大运行时间,配合 systemd/cron 实现定时重启 - **状态持久化**: 保存处理状态到 JSON 文件,重启后恢复 ## 颜色映射表 | 原颜色 (RGBA) | 转换后颜色 (RGBA) | 说明 | |--------------|------------------|------| | (255, 0, 0, 128) | (255, 0, 0, 128) | 红色保持不变 | | (255, 163, 0, 128) | (255, 163, 0, 128) | 橙色保持不变 | | (255, 254, 0, 128) | (255, 254, 0, 128) | 黄色保持不变 | | (0, 128, 0, 128) | (0, 100, 255, 128) | **绿色转蓝色** | | (1, 1, 254, 128) | (0, 100, 255, 128) | **蓝色统一化** | ## 环境要求 - **Python 版本**: 3.7.9(目标机器需自带) - **系统**: UOS 20 / CentOS 7+ / Ubuntu 16.04+ (x86_64) - **依赖**: `watchdog`、`pillow`、`numpy`(已包含在 `deps/` 目录) ## 文件说明 | 文件 | 说明 | |-----|------| | `tif_watchdog_restart.py` | 主程序(支持命令行参数) | | `tif_watchdog_restart_original.py` | 原始版本(硬编码配置) | | `tif_watchdog_restart_test.py` | 测试脚本 | | `tif_watchdog_restart.spec` | PyInstaller 打包配置 | | `deps/` | 依赖包目录(watchdog/pillow/numpy) | | `run.sh` | 启动脚本 | | `Dockerfile.build-py37` | PyInstaller 构建镜像 | | `build-on-server.sh` | 目标服务器本地打包脚本 | | `build-with-docker.sh` | Docker 容器打包脚本 | ## 离线部署 ### 前置条件 目标机器需安装 Python 3.7.9,无需外网。 ### 步骤 ```bash # 1. 复制项目到目标机器 scp -r tif_watchdog_offline.tar.gz user@server:/opt/tif_watchdog/ # 2. 解压(或直接 clone 仓库) cd /opt/tif_watchdog tar xzvf tif_watchdog_offline.tar.gz # 3. 创建监听目录 mkdir -p /fire_layer # 4. 启动(使用自带 run.sh,自动加载 deps 依赖) ./run.sh ``` ### 验证 ```bash # 测试运行 60 秒 ./run.sh --max-runtime 60 # 自定义参数 ./run.sh --watch-dir /data/fire_images --max-runtime 7200 ``` ### 生产部署(systemd) ```bash # 创建服务文件 sudo tee /etc/systemd/system/tif-watchdog.service << 'EOF' [Unit] Description=TIF Watchdog Color Converter After=network.target [Service] Type=simple WorkingDirectory=/opt/tif_watchdog ExecStart=/opt/tif_watchdog/run.sh Restart=always RestartSec=10 User=root [Install] WantedBy=multi-user.target EOF # 启动 sudo systemctl daemon-reload sudo systemctl enable tif-watchdog sudo systemctl start tif-watchdog sudo systemctl status tif-watchdog # cron 定时重启(每小时) 0 * * * * /usr/bin/systemctl restart tif-watchdog ``` ### 命令行参数 | 参数 | 默认值 | 说明 | |-----|--------|------| | `--watch-dir` | `/fire_layer` | 监听目录路径 | | `--log-file` | `/zxtx/soft/scripts/tif_convert.log` | 日志文件路径 | | `--state-file` | `/zxtx/soft/scripts/tif_convert_state.json` | 状态文件路径 | | `--max-runtime` | `3600` | 最大运行秒数(0=无限) | | `--process-timeout` | `30` | 等待文件写入完成的秒数 | ## 日志示例 ``` 2026-06-03 11:20:29 [INFO] ============================================================ 2026-06-03 11:20:29 [INFO] TIF颜色转换服务启动 2026-06-03 11:20:29 [INFO] 监听目录: /fire_layer 2026-06-03 11:20:29 [INFO] 最大运行时间: 3600秒 2026-06-03 11:20:29 [INFO] ============================================================ 2026-06-03 11:20:29 [INFO] 监听已启动,等待新TIF文件... 2026-06-03 11:21:15 [INFO] 检测到新TIF文件: /fire_layer/fire_risk_20260603_112115.tif 2026-06-03 11:21:15 [INFO] 图像尺寸: (1024, 1024, 4) 2026-06-03 11:21:16 [INFO] 转换完成: /fire_layer/fire_risk_20260603_112115.tif, 共转换15234像素 ```