From bfc45b4d27d5c014ad5472e660b118a9dc9c6773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E6=BE=B3?= Date: Thu, 2 Jan 2025 16:39:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- odm_preprocess.py | 29 ++++++++++++++++------------- odm_preprocess_fast.py | 17 +++++++++-------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/odm_preprocess.py b/odm_preprocess.py index 6760433..c128261 100644 --- a/odm_preprocess.py +++ b/odm_preprocess.py @@ -198,7 +198,12 @@ class ImagePreprocessor: return self.gps_points def divide_grids(self) -> Tuple[Dict[tuple, pd.DataFrame], Dict[tuple, tuple]]: - """划分网格""" + """划分网格 + Returns: + tuple: (grid_points, translations) + - grid_points: 网格点数据字典 + - translations: 网格平移量字典 + """ self.logger.info(f"开始划分网格 (重叠率: {self.config.grid_overlap})") grid_divider = GridDivider( overlap=self.config.grid_overlap, @@ -208,8 +213,6 @@ class ImagePreprocessor: self.gps_points, grid_size=self.config.grid_size ) grid_points = grid_divider.assign_to_grids(self.gps_points, grids) - - # -1是因为包含了grid_divider self.logger.info(f"成功划分为 {len(grid_points)} 个网格") return grid_points, translations @@ -219,37 +222,37 @@ class ImagePreprocessor: self.logger.info("开始复制图像文件") for grid_id, points in grid_points.items(): - output_dir = os.path.join( self.config.output_dir, f"grid_{grid_id[0]}_{grid_id[1]}", "project", "images" ) os.makedirs(output_dir, exist_ok=True) - for point in tqdm(points, desc=f"复制网格 {grid_id} 的图像"): + for point in tqdm(points, desc=f"复制网格 ({grid_id[0]},{grid_id[1]}) 的图像"): src = os.path.join(self.config.image_dir, point["file"]) dst = os.path.join(output_dir, point["file"]) shutil.copy(src, dst) - self.logger.info(f"网格 {grid_id} 包含 {len(points)} 张图像") + self.logger.info( + f"网格 ({grid_id[0]},{grid_id[1]}) 包含 {len(points)} 张图像") - def merge_tif(self, grid_points: Dict[int, pd.DataFrame]): + def merge_tif(self, grid_points: Dict[tuple, pd.DataFrame]): """合并所有网格的影像产品""" self.logger.info("开始合并所有影像产品") merger = MergeTif(self.config.output_dir) merger.merge_all_tifs(grid_points) + def merge_ply(self, grid_points: Dict[tuple, pd.DataFrame]): + """合并所有网格的PLY点云""" + self.logger.info("开始合并PLY点云") + merger = MergePly(self.config.output_dir) + merger.merge_grid_laz(grid_points) + def merge_obj(self, grid_points: Dict[tuple, pd.DataFrame], translations: Dict[tuple, tuple]): """合并所有网格的OBJ模型""" self.logger.info("开始合并OBJ模型") merger = MergeObj(self.config.output_dir) merger.merge_grid_obj(grid_points, translations) - def merge_ply(self, grid_points: Dict[int, pd.DataFrame]): - """合并所有网格的PLY点云""" - self.logger.info("开始合并PLY点云") - merger = MergePly(self.config.output_dir) - merger.merge_grid_laz(grid_points) - def process(self): """执行完整的预处理流程""" try: diff --git a/odm_preprocess_fast.py b/odm_preprocess_fast.py index 0903226..59e3b59 100644 --- a/odm_preprocess_fast.py +++ b/odm_preprocess_fast.py @@ -232,7 +232,8 @@ class ImagePreprocessor: src = os.path.join(self.config.image_dir, point["file"]) dst = os.path.join(output_dir, point["file"]) shutil.copy(src, dst) - self.logger.info(f"网格 ({grid_id[0]},{grid_id[1]}) 包含 {len(points)} 张图像") + self.logger.info( + f"网格 ({grid_id[0]},{grid_id[1]}) 包含 {len(points)} 张图像") def merge_tif(self, grid_points: Dict[tuple, pd.DataFrame]): """合并所有网格的影像产品""" @@ -240,18 +241,18 @@ class ImagePreprocessor: merger = MergeTif(self.config.output_dir) merger.merge_all_tifs(grid_points) - def merge_obj(self, grid_points: Dict[tuple, pd.DataFrame], translations: Dict[tuple, tuple]): - """合并所有网格的OBJ模型""" - self.logger.info("开始合并OBJ模型") - merger = MergeObj(self.config.output_dir) - merger.merge_grid_obj(grid_points, translations) - def merge_ply(self, grid_points: Dict[tuple, pd.DataFrame]): """合并所有网格的PLY点云""" self.logger.info("开始合并PLY点云") merger = MergePly(self.config.output_dir) merger.merge_grid_laz(grid_points) + def merge_obj(self, grid_points: Dict[tuple, pd.DataFrame], translations: Dict[tuple, tuple]): + """合并所有网格的OBJ模型""" + self.logger.info("开始合并OBJ模型") + merger = MergeObj(self.config.output_dir) + merger.merge_grid_obj(grid_points, translations) + def process(self): """执行完整的预处理流程""" try: @@ -292,7 +293,7 @@ if __name__ == "__main__": filter_dense_distance_threshold=10, filter_time_threshold=timedelta(minutes=5), - grid_size=300, + grid_size=500, grid_overlap=0.1,