subprocess.run
This commit is contained in:
parent
bb17302919
commit
6ad875d59a
@ -307,7 +307,7 @@ class ImagePreprocessor:
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 创建配置
|
# 创建配置
|
||||||
config = PreprocessConfig(
|
config = PreprocessConfig(
|
||||||
image_dir=r"F:\error_data\20241024100834\project\images",
|
image_dir=r"G:\error_data\20241024100834\project\images",
|
||||||
output_dir=r"G:\ODM_output\20241024100834",
|
output_dir=r"G:\ODM_output\20241024100834",
|
||||||
|
|
||||||
cluster_eps=0.01,
|
cluster_eps=0.01,
|
||||||
|
@ -20,45 +20,49 @@ class ODMProcessMonitor:
|
|||||||
|
|
||||||
def run_odm_with_monitor(self, grid_dir: str, grid_idx: int, fast_mode: bool = True) -> Tuple[bool, str]:
|
def run_odm_with_monitor(self, grid_dir: str, grid_idx: int, fast_mode: bool = True) -> Tuple[bool, str]:
|
||||||
"""运行ODM命令"""
|
"""运行ODM命令"""
|
||||||
try:
|
self.logger.info(f"开始处理网格 {grid_idx + 1}")
|
||||||
self.logger.info(f"开始处理网格 {grid_idx + 1}")
|
|
||||||
|
|
||||||
# 构建命令字符串
|
# 规范化路径
|
||||||
command = (
|
grid_dir = os.path.abspath(grid_dir).replace('\\', '/')
|
||||||
f"docker run -ti --rm "
|
|
||||||
f"-v {grid_dir}:/datasets "
|
# 设置环境变量
|
||||||
f"opendronemap/odm "
|
# env = os.environ.copy()
|
||||||
f"--project-path /datasets project "
|
# env["PYTHONUNBUFFERED"] = "1"
|
||||||
f"--max-concurrency 10 "
|
|
||||||
f"--force-gps "
|
# 构建命令字符串
|
||||||
|
command = (
|
||||||
|
f"docker run --rm " # 移除 -ti 参数
|
||||||
|
f"-v {grid_dir}:/datasets "
|
||||||
|
f"opendronemap/odm "
|
||||||
|
f"--project-path /datasets project "
|
||||||
|
f"--max-concurrency 10 "
|
||||||
|
f"--force-gps "
|
||||||
|
)
|
||||||
|
|
||||||
|
if fast_mode:
|
||||||
|
command += (
|
||||||
|
f"--feature-quality lowest "
|
||||||
|
f"--orthophoto-resolution 8 "
|
||||||
|
f"--fast-orthophoto "
|
||||||
|
f"--skip-3dmodel "
|
||||||
)
|
)
|
||||||
|
|
||||||
if fast_mode:
|
command += "--rerun-all"
|
||||||
command += (
|
|
||||||
f"--feature-quality lowest "
|
|
||||||
f"--orthophoto-resolution 8 "
|
|
||||||
f"--fast-orthophoto "
|
|
||||||
f"--skip-3dmodel "
|
|
||||||
)
|
|
||||||
|
|
||||||
command += "--rerun-all"
|
# 执行命令
|
||||||
|
result = subprocess.run(
|
||||||
|
command,
|
||||||
|
shell=True,
|
||||||
|
# env=env,
|
||||||
|
cwd=grid_dir, # 设置工作目录
|
||||||
|
stdout=subprocess.DEVNULL, # 完全禁用输出捕获
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
creationflags=subprocess.CREATE_NO_WINDOW if os.name == 'nt' else 0 # Windows下不创建新窗口
|
||||||
|
)
|
||||||
|
|
||||||
# 执行命令
|
# 检查是否成功完成
|
||||||
result = subprocess.run(
|
if result.returncode == 0 and self._check_success(grid_dir):
|
||||||
command,
|
self.logger.info(f"网格 {grid_idx + 1} 处理成功")
|
||||||
shell=True,
|
return True, ""
|
||||||
stdout=subprocess.DEVNULL,
|
|
||||||
stderr=subprocess.DEVNULL
|
return False, f"网格 {grid_idx + 1} 处理失败"
|
||||||
)
|
|
||||||
|
|
||||||
# 检查是否成功完成
|
|
||||||
if result.returncode == 0 and self._check_success(grid_dir):
|
|
||||||
self.logger.info(f"网格 {grid_idx + 1} 处理成功")
|
|
||||||
return True, ""
|
|
||||||
|
|
||||||
return False, f"网格 {grid_idx + 1} 处理失败"
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
error_msg = f"执行异常: {str(e)}"
|
|
||||||
self.logger.error(error_msg)
|
|
||||||
return False, error_msg
|
|
Loading…
Reference in New Issue
Block a user