多线程处理场景主函数
(dataset_root, scenes, point_step)
| 139 | return False |
| 140 | |
| 141 | def process_scenes(dataset_root, scenes, point_step): |
| 142 | """多线程处理场景主函数""" |
| 143 | total_files = 0 |
| 144 | success_files = 0 |
| 145 | file_args = [] |
| 146 | |
| 147 | # 收集所有待处理文件(增加目录校验) |
| 148 | for scene in scenes: |
| 149 | scene_path = os.path.join(dataset_root, scene) |
| 150 | if not os.path.isdir(scene_path): |
| 151 | log_error(f"无效场景目录: {scene}") |
| 152 | continue |
| 153 | |
| 154 | for fragment in os.listdir(scene_path): |
| 155 | fragment_path = os.path.join(scene_path, fragment) |
| 156 | if not os.path.isdir(fragment_path): |
| 157 | continue |
| 158 | |
| 159 | front_lidar = os.path.join(fragment_path, 'front', 'lidar') |
| 160 | if not os.path.exists(front_lidar): |
| 161 | continue |
| 162 | |
| 163 | pcd_files = [f for f in os.listdir(front_lidar) if f.endswith('.pcd')] |
| 164 | for pcd_file in pcd_files: |
| 165 | file_args.append((fragment_path, pcd_file, point_step)) |
| 166 | total_files += 1 |
| 167 | |
| 168 | # 多线程处理 |
| 169 | with ThreadPoolExecutor(max_workers=os.cpu_count()*2) as executor: |
| 170 | futures = [executor.submit(process_single_file, arg) for arg in file_args] |
| 171 | |
| 172 | for future in tqdm(concurrent.futures.as_completed(futures), |
| 173 | total=total_files, |
| 174 | desc="处理进度", |
| 175 | bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [已用时{elapsed}]"): |
| 176 | try: |
| 177 | if future.result(): |
| 178 | success_files += 1 |
| 179 | except Exception as e: |
| 180 | log_error(f"处理异常: {str(e)}") |
| 181 | |
| 182 | # 打印统计信息 |
| 183 | log_info(f"{Colors.BOLD}=== 处理总结 ===") |
| 184 | log_info(f"总处理文件: {total_files}") |
| 185 | log_info(f"成功文件: {success_files} ({success_files/total_files:.1%})") |
| 186 | log_info(f"失败文件: {total_files-success_files} ({(total_files-success_files)/total_files:.1%})") |
| 187 | |
| 188 | def read_gps_csv(csv_path, target_time): |
| 189 | """从CSV读取GPS数据""" |