From 0e29728126fd8646800dee5273ee74081e3612f1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 4 Jan 2025 15:19:23 +0800 Subject: [PATCH] add filter time_group_overlap --- filter/time_group_overlap_filter.py | 6 +-- odm_preprocess.py | 84 +++++++++++++---------------- 2 files changed, 39 insertions(+), 51 deletions(-) diff --git a/filter/time_group_overlap_filter.py b/filter/time_group_overlap_filter.py index 15ece6f..9f7a4f9 100644 --- a/filter/time_group_overlap_filter.py +++ b/filter/time_group_overlap_filter.py @@ -90,12 +90,8 @@ class TimeGroupOverlapFilter: return intersection_area / smaller_area return 0 - def filter_overlapping_groups(self, time_threshold=timedelta(minutes=5)): + def filter_overlapping_groups(self, gps_points, time_threshold=timedelta(minutes=5)): """过滤重叠的时间组""" - # 提取GPS数据 - extractor = GPSExtractor(self.image_dir) - gps_points = extractor.extract_all_gps() - # 按时间分组 time_groups = self._group_by_time(gps_points, time_threshold) diff --git a/odm_preprocess.py b/odm_preprocess.py index 07e164c..103df42 100644 --- a/odm_preprocess.py +++ b/odm_preprocess.py @@ -97,9 +97,8 @@ class ImagePreprocessor: extractor = GPSExtractor(self.config.image_dir) self.gps_points = extractor.extract_all_gps() self.logger.info(f"成功提取 {len(self.gps_points)} 个GPS点") - return self.gps_points - def cluster(self) -> pd.DataFrame: + def cluster(self): """使用DBSCAN对GPS点进行聚类,只保留最大的类""" self.logger.info("开始聚类") previous_points = self.gps_points.copy() @@ -124,44 +123,10 @@ class ImagePreprocessor: self.visualizer.visualize_filter_step( self.gps_points, previous_points, "1-Clustering") - return self.gps_points - - def filter_time_group_overlap(self) -> pd.DataFrame: - """过滤重叠的时间组""" - self.logger.info("开始过滤重叠时间组") - - self.logger.info("开始过滤重叠时间组") - previous_points = self.gps_points.copy() - - filter = TimeGroupOverlapFilter( - self.config.image_dir, - self.config.output_dir, - overlap_threshold=self.config.time_group_overlap_threshold - ) - - deleted_files = filter.filter_overlapping_groups( - time_threshold=self.config.time_group_interval - ) - - # 更新GPS点数据,移除被删除的图像 - self.gps_points = self.gps_points[~self.gps_points['file'].isin( - deleted_files)] - self.logger.info(f"重叠时间组过滤后剩余 {len(self.gps_points)} 个GPS点") - - # 可视化过滤结果 - self.visualizer.visualize_filter_step( - self.gps_points, previous_points, "2-Time Group Overlap") - - return self.gps_points - - # TODO 过滤算法还需要更新 - def filter_points(self) -> pd.DataFrame: - """过滤GPS点""" - - self.logger.info("开始过滤GPS点") + def filter_isolated_points(self): + """过滤孤立点""" + self.logger.info("开始过滤孤立点") filter = GPSFilter(self.config.output_dir) - - # 过滤孤立点 previous_points = self.gps_points.copy() self.logger.info( f"开始过滤孤立点(距离阈值: {self.config.filter_distance_threshold}, " @@ -176,7 +141,36 @@ class ImagePreprocessor: # 可视化孤立点过滤结果 self.visualizer.visualize_filter_step( - self.gps_points, previous_points, "3-Isolated Points") + self.gps_points, previous_points, "2-Isolated Points") + + def filter_time_group_overlap(self): + """过滤重叠的时间组""" + self.logger.info("开始过滤重叠时间组") + previous_points = self.gps_points.copy() + + filter = TimeGroupOverlapFilter( + self.config.image_dir, + self.config.output_dir, + overlap_threshold=self.config.time_group_overlap_threshold + ) + + deleted_files = filter.filter_overlapping_groups( + self.gps_points, + time_threshold=self.config.time_group_interval + ) + + # 更新GPS点数据,移除被删除的图像 + self.gps_points = self.gps_points[~self.gps_points['file'].isin( + deleted_files)] + self.logger.info(f"重叠时间组过滤后剩余 {len(self.gps_points)} 个GPS点") + + # 可视化过滤结果 + self.visualizer.visualize_filter_step( + self.gps_points, previous_points, "3-Time Group Overlap") + + # # TODO 过滤密集点算法还需要更新 + # def filter_points(self): + # """过滤GPS点""" # # 过滤密集点 # previous_points = self.gps_points.copy() @@ -196,8 +190,6 @@ class ImagePreprocessor: # self.visualizer.visualize_filter_step( # self.gps_points, previous_points, "4-Dense Points") - return self.gps_points - def divide_grids(self) -> Tuple[Dict[tuple, pd.DataFrame], Dict[tuple, tuple]]: """划分网格 Returns: @@ -262,8 +254,8 @@ class ImagePreprocessor: try: self.extract_gps() self.cluster() - # self.filter_time_group_overlap() - self.filter_points() + self.filter_isolated_points() + self.filter_time_group_overlap() grid_points, translations = self.divide_grids() self.copy_images(grid_points) self.logger.info("预处理任务完成") @@ -280,8 +272,8 @@ class ImagePreprocessor: if __name__ == "__main__": # 创建配置 config = PreprocessConfig( - image_dir=r"/home/cug/datasets/1815/project/images", - output_dir=r"/home/cug/ODM_output/1815", + image_dir=r"/home/cug/datasets/134/code/images", + output_dir=r"/home/cug/ODM_output/134", cluster_eps=0.01, cluster_min_samples=5,