2024-12-30 17:34:21 +08:00
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import subprocess
|
|
|
|
from typing import Dict, Tuple
|
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
class ODMProcessMonitor:
|
|
|
|
"""ODM处理监控器"""
|
|
|
|
|
2024-12-30 20:41:22 +08:00
|
|
|
def __init__(self, output_dir: str, fast_mode: bool):
|
2024-12-30 17:34:21 +08:00
|
|
|
self.output_dir = output_dir
|
|
|
|
self.logger = logging.getLogger('UAV_Preprocess.ODMMonitor')
|
2024-12-30 20:41:22 +08:00
|
|
|
self.fast_mode = fast_mode
|
2024-12-30 17:34:21 +08:00
|
|
|
|
|
|
|
def _check_success(self, grid_dir: str) -> bool:
|
|
|
|
"""检查ODM是否执行成功"""
|
|
|
|
success_markers = ['odm_orthophoto', 'odm_georeferencing']
|
2024-12-30 20:41:22 +08:00
|
|
|
if not self.fast_mode:
|
2024-12-30 17:34:21 +08:00
|
|
|
success_markers.append('odm_texturing')
|
|
|
|
return all(os.path.exists(os.path.join(grid_dir, 'project', marker)) for marker in success_markers)
|
|
|
|
|
2024-12-30 20:41:22 +08:00
|
|
|
def run_odm_with_monitor(self, project_dir: str, fast_mode: bool = True) -> Tuple[bool, str]:
|
2024-12-30 17:34:21 +08:00
|
|
|
"""运行ODM命令"""
|
|
|
|
# 构建Docker命令
|
|
|
|
docker_command = (
|
|
|
|
f"docker run --gpus all -ti --rm "
|
2024-12-30 20:41:22 +08:00
|
|
|
f"-v {project_dir}:/datasets "
|
2024-12-30 17:34:21 +08:00
|
|
|
f"opendronemap/odm:gpu "
|
|
|
|
f"--project-path /datasets project "
|
2024-12-30 20:41:22 +08:00
|
|
|
f"--max-concurrency 15 "
|
2024-12-30 17:34:21 +08:00
|
|
|
f"--force-gps "
|
|
|
|
f"--feature-quality lowest "
|
|
|
|
f"--orthophoto-resolution 10 "
|
2024-12-30 20:41:22 +08:00
|
|
|
f"--split-overlap 0 "
|
2024-12-30 17:34:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if fast_mode:
|
|
|
|
docker_command += (
|
|
|
|
f"--fast-orthophoto "
|
|
|
|
f"--skip-3dmodel "
|
|
|
|
)
|
|
|
|
|
|
|
|
docker_command += "--rerun-all"
|
|
|
|
self.logger.info(docker_command)
|
|
|
|
result = subprocess.run(
|
|
|
|
docker_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
stdout, stderr = result.stdout.decode(
|
|
|
|
'utf-8'), result.stderr.decode('utf-8')
|
|
|
|
|
|
|
|
self.logger.info(f"==========stdout==========: {stdout}")
|
|
|
|
self.logger.error(f"==========stderr==========: {stderr}")
|
|
|
|
# 检查执行结果
|
2024-12-30 20:41:22 +08:00
|
|
|
if self._check_success(image_dir):
|
|
|
|
self.logger.info(f"处理成功")
|
2024-12-30 17:34:21 +08:00
|
|
|
else:
|
2024-12-30 20:41:22 +08:00
|
|
|
self.logger.error(f"处理失败")
|