From 453afa971ef8c5ed72e8e1fad5c39e848f0621f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E6=BE=B3?= Date: Mon, 13 Jan 2025 14:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8E=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- odm_preprocess.py | 58 +------------------------------------------ post_pro/merge_laz.py | 20 +++++++++++---- post_pro/merge_obj.py | 10 ++++++-- post_pro/merge_tif.py | 14 ++++++++--- 4 files changed, 35 insertions(+), 67 deletions(-) diff --git a/odm_preprocess.py b/odm_preprocess.py index 7362a22..96e7379 100644 --- a/odm_preprocess.py +++ b/odm_preprocess.py @@ -247,63 +247,7 @@ class ImagePreprocessor: def post_process(self, successful_grid_points: Dict[tuple, pd.DataFrame], grid_points: Dict[tuple, pd.DataFrame], translations: Dict[tuple, tuple]): """后处理:合并或复制处理结果""" - if len(successful_grid_points) == 1: - # 获取唯一成功的网格ID - grid_id = list(successful_grid_points.keys())[0] - self.logger.info(f"只有一个网格 {grid_id} 成功处理,直接复制结果") - - # 构建源目录路径(成功网格的输出目录) - src_dir = os.path.join( - self.config.output_dir, f"grid_{grid_id[0]}_{grid_id[1]}", "project") - - # 复制正射影像 - if self.config.mode == "快拼模式": - shutil.copy2(os.path.join(src_dir, "odm_orthophoto", "odm_orthophoto.original.tif"), - os.path.join(self.config.output_dir, - "orthophoto.tif") - ) - elif self.config.mode == "三维模式": - shutil.copy2(os.path.join(src_dir, "odm_georeferencing", "odm_georeferenced_model.laz"), - os.path.join(self.config.output_dir, - "pointcloud.laz") - ) - shutil.copytree(os.path.join(src_dir, "odm_texturing"), - os.path.join(self.config.output_dir, "texturing")) - os.rename(os.path.join(self.config.output_dir, "texturing", "odm_textured_model_geo.obj"), - os.path.join(self.config.output_dir, "texturing", "textured_model.obj")) - os.rename(os.path.join(self.config.output_dir, "texturing", "odm_textured_model_geo.mtl"), - os.path.join(self.config.output_dir, "texturing", "textured_model.mtl")) - elif self.config.mode == "重建模式": - shutil.copy2(os.path.join(src_dir, "odm_orthophoto", "odm_orthophoto.tif"), - os.path.join(self.config.output_dir, - "orthophoto.tif") - ) - shutil.copy2(os.path.join(src_dir, "odm_georeferencing", "odm_georeferenced_model.laz"), - os.path.join(self.config.output_dir, - "pointcloud.laz") - ) - shutil.copytree(os.path.join(src_dir, "odm_texturing"), - os.path.join(self.config.output_dir, "texturing")) - os.rename(os.path.join(self.config.output_dir, "texturing", "odm_textured_model_geo.obj"), - os.path.join(self.config.output_dir, "texturing", "textured_model.obj")) - os.rename(os.path.join(self.config.output_dir, "texturing", "odm_textured_model_geo.mtl"), - os.path.join(self.config.output_dir, "texturing", "textured_model.mtl")) - if self.config.produce_dem: - shutil.copy2( - os.path.join(src_dir, "odm_dem", "dsm.tif"), - os.path.join(self.config.output_dir, "dsm.tif") - ) - shutil.copy2( - os.path.join(src_dir, "odm_dem", "dtm.tif"), - os.path.join(self.config.output_dir, "dtm.tif") - ) - - self.logger.info("单网格结果复制完成") - - return - - # 如果有多个网格,执行合并操作 - elif len(successful_grid_points) < len(grid_points): + if len(successful_grid_points) < len(grid_points): self.logger.warning( f"有 {len(grid_points) - len(successful_grid_points)} 个网格处理失败," f"将只合并成功处理的 {len(successful_grid_points)} 个网格" diff --git a/post_pro/merge_laz.py b/post_pro/merge_laz.py index b4ff770..70cb732 100644 --- a/post_pro/merge_laz.py +++ b/post_pro/merge_laz.py @@ -4,6 +4,7 @@ import numpy as np from typing import Dict, Tuple import pandas as pd import subprocess +import shutil class MergePly: @@ -14,8 +15,15 @@ class MergePly: def merge_grid_laz(self, grid_points: Dict[tuple, pd.DataFrame]): """合并所有网格的点云数据""" if len(grid_points) == 1: - self.logger.info("只有一个网格,无需合并") - return + grid_id = list(grid_points.keys())[0] + shutil.copy2(os.path.join(self.output_dir, + f"grid_{grid_id[0]}_{grid_id[1]}", + "project", + "odm_georeferencing", + "odm_georeferenced_model.laz"), + os.path.join(self.output_dir, + "pointcloud.laz") + ) try: # 获取所有点云文件路径 @@ -31,15 +39,17 @@ class MergePly: if os.path.exists(laz_path): laz_files.append(laz_path) else: - self.logger.warning(f"网格 ({grid_id[0]},{grid_id[1]}) 的点云文件不存在") + self.logger.warning( + f"网格 ({grid_id[0]},{grid_id[1]}) 的点云文件不存在") kwargs = { 'all_inputs': " ".join(laz_files), 'output': os.path.join(self.output_dir, 'pointcloud.laz') } - subprocess.run('D:\\software\\LAStools\\bin\\lasmerge64.exe -i {all_inputs} -o "{output}"'.format(**kwargs)) - + subprocess.run( + 'D:\\software\\LAStools\\bin\\lasmerge64.exe -i {all_inputs} -o "{output}"'.format(**kwargs)) + except Exception as e: self.logger.error(f"PLY点云合并过程中发生错误: {str(e)}", exc_info=True) raise diff --git a/post_pro/merge_obj.py b/post_pro/merge_obj.py index 0f4c70a..0240f3e 100644 --- a/post_pro/merge_obj.py +++ b/post_pro/merge_obj.py @@ -268,8 +268,14 @@ class MergeObj: def merge_grid_obj(self, grid_points: Dict[tuple, pd.DataFrame], translations: Dict[tuple, tuple]): """合并所有网格的OBJ模型""" if len(grid_points) == 1: - self.logger.info("只有一个网格,无需合并") - return + grid_id = list(grid_points.keys())[0] + shutil.copytree(os.path.join(self.output_dir, + f"grid_{grid_id[0]}_{grid_id[1]}", + "project", + "odm_texturing"), + os.path.join(self.output_dir, "texturing")) + os.rename(os.path.join(self.output_dir, "texturing", "odm_textured_model_geo.obj"), + os.path.join(self.output_dir, "texturing", "textured_model.obj")) try: # 创建输出目录 diff --git a/post_pro/merge_tif.py b/post_pro/merge_tif.py index 210ff9d..4e42b9f 100644 --- a/post_pro/merge_tif.py +++ b/post_pro/merge_tif.py @@ -107,8 +107,15 @@ class MergeTif: self.logger.info(f"开始合并{product_name}") if len(grid_points) < 2: - self.logger.info("只有一个网格,无需合并") - return + grid_id = list(grid_points.keys())[0] + shutil.copy2(os.path.join(self.output_dir, + f"grid_{grid_id[0]}_{grid_id[1]}", + "project", + product_path, + filename), + os.path.join(self.output_dir, + product_info['output']) + ) input_tif1, input_tif2 = None, None merge_count = 0 @@ -129,7 +136,8 @@ class MergeTif: continue # 如果文件大于600MB,则不使用original文件 - file_size_mb = os.path.getsize(grid_tif) / (1024 * 1024) # 转换为MB + file_size_mb = os.path.getsize( + grid_tif) / (1024 * 1024) # 转换为MB if file_size_mb > 600: grid_tif = os.path.join( self.output_dir,