add filter time_group_overlap

This commit is contained in:
Your Name 2025-01-04 15:19:23 +08:00
parent e49787b8b8
commit 0e29728126
2 changed files with 39 additions and 51 deletions

View File

@ -90,12 +90,8 @@ class TimeGroupOverlapFilter:
return intersection_area / smaller_area return intersection_area / smaller_area
return 0 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) time_groups = self._group_by_time(gps_points, time_threshold)

View File

@ -97,9 +97,8 @@ class ImagePreprocessor:
extractor = GPSExtractor(self.config.image_dir) extractor = GPSExtractor(self.config.image_dir)
self.gps_points = extractor.extract_all_gps() self.gps_points = extractor.extract_all_gps()
self.logger.info(f"成功提取 {len(self.gps_points)} 个GPS点") self.logger.info(f"成功提取 {len(self.gps_points)} 个GPS点")
return self.gps_points
def cluster(self) -> pd.DataFrame: def cluster(self):
"""使用DBSCAN对GPS点进行聚类只保留最大的类""" """使用DBSCAN对GPS点进行聚类只保留最大的类"""
self.logger.info("开始聚类") self.logger.info("开始聚类")
previous_points = self.gps_points.copy() previous_points = self.gps_points.copy()
@ -124,44 +123,10 @@ class ImagePreprocessor:
self.visualizer.visualize_filter_step( self.visualizer.visualize_filter_step(
self.gps_points, previous_points, "1-Clustering") self.gps_points, previous_points, "1-Clustering")
return self.gps_points def filter_isolated_points(self):
"""过滤孤立点"""
def filter_time_group_overlap(self) -> pd.DataFrame: self.logger.info("开始过滤孤立点")
"""过滤重叠的时间组"""
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点")
filter = GPSFilter(self.config.output_dir) filter = GPSFilter(self.config.output_dir)
# 过滤孤立点
previous_points = self.gps_points.copy() previous_points = self.gps_points.copy()
self.logger.info( self.logger.info(
f"开始过滤孤立点(距离阈值: {self.config.filter_distance_threshold}, " f"开始过滤孤立点(距离阈值: {self.config.filter_distance_threshold}, "
@ -176,7 +141,36 @@ class ImagePreprocessor:
# 可视化孤立点过滤结果 # 可视化孤立点过滤结果
self.visualizer.visualize_filter_step( 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() # previous_points = self.gps_points.copy()
@ -196,8 +190,6 @@ class ImagePreprocessor:
# self.visualizer.visualize_filter_step( # self.visualizer.visualize_filter_step(
# self.gps_points, previous_points, "4-Dense Points") # self.gps_points, previous_points, "4-Dense Points")
return self.gps_points
def divide_grids(self) -> Tuple[Dict[tuple, pd.DataFrame], Dict[tuple, tuple]]: def divide_grids(self) -> Tuple[Dict[tuple, pd.DataFrame], Dict[tuple, tuple]]:
"""划分网格 """划分网格
Returns: Returns:
@ -262,8 +254,8 @@ class ImagePreprocessor:
try: try:
self.extract_gps() self.extract_gps()
self.cluster() self.cluster()
# self.filter_time_group_overlap() self.filter_isolated_points()
self.filter_points() self.filter_time_group_overlap()
grid_points, translations = self.divide_grids() grid_points, translations = self.divide_grids()
self.copy_images(grid_points) self.copy_images(grid_points)
self.logger.info("预处理任务完成") self.logger.info("预处理任务完成")
@ -280,8 +272,8 @@ class ImagePreprocessor:
if __name__ == "__main__": if __name__ == "__main__":
# 创建配置 # 创建配置
config = PreprocessConfig( config = PreprocessConfig(
image_dir=r"/home/cug/datasets/1815/project/images", image_dir=r"/home/cug/datasets/134/code/images",
output_dir=r"/home/cug/ODM_output/1815", output_dir=r"/home/cug/ODM_output/134",
cluster_eps=0.01, cluster_eps=0.01,
cluster_min_samples=5, cluster_min_samples=5,