From 7746b4fa0008b5daca1f5b899f1b2a0989525d70 Mon Sep 17 00:00:00 2001 From: DmiitriyJarosh Date: Mon, 14 Nov 2022 19:09:26 +0000 Subject: [PATCH] chore: fixing black --- .pre-commit-config.yaml | 2 +- project/Visualisation.py | 6 ++-- project/annotators/Annotator.py | 4 ++- project/annotators/AnnotatorImage.py | 13 +++++++-- project/annotators/AnnotatorPointCloud.py | 4 +-- project/associators/AssociatorAnnotNpy.py | 4 ++- project/main.py | 31 ++++++++++++++++----- project/pcdBuilders/PcdBuilderPointCloud.py | 6 +--- project/postprocessing/PlaneInfoPrinter.py | 4 ++- project/postprocessing/PlaneRemover.py | 5 +++- project/postprocessing/PostProcessing.py | 2 +- project/slam/EigenPointsSLAMGraph.py | 3 +- project/slam/SLAMGraph.py | 19 +++++++++---- project/utils/colors.py | 10 ++++--- project/utils/intervals.py | 11 +++----- 15 files changed, 77 insertions(+), 47 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6621d82..503796a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,6 +7,6 @@ repos: - id: trailing-whitespace - id: requirements-txt-fixer - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 22.10.0 hooks: - id: black diff --git a/project/Visualisation.py b/project/Visualisation.py index c8434fa..8801c7e 100644 --- a/project/Visualisation.py +++ b/project/Visualisation.py @@ -41,7 +41,7 @@ def visualize(self, pcd_s: List[Pcd], graph_estimated_state): ) pc_answ = o3d.geometry.PointCloud() - graph_estimated_state = graph_estimated_state[:len(pcd_s)] + graph_estimated_state = graph_estimated_state[: len(pcd_s)] for i in range(num_of_nodes): pc = self.visualize_pcd( pcd_s[-(i + 1)], [graph_estimated_state[-(i + 1)], reflection] @@ -69,8 +69,6 @@ def __draw_pcd(pcd: o3d.geometry.PointCloud): for point in picked_points: print( "Pont with position {0} picked. Color: {1}".format( - points[point], - denormalize_color(colors[point]) + points[point], denormalize_color(colors[point]) ) ) - diff --git a/project/annotators/Annotator.py b/project/annotators/Annotator.py index 49ad822..ccaa980 100644 --- a/project/annotators/Annotator.py +++ b/project/annotators/Annotator.py @@ -33,7 +33,9 @@ def annotate(self, pcd, depth_image_number: int): """ pcd.planes = self._get_planes( pcd, - self.array_path_to_annot[self._get_annot_image_number_by_depth(depth_image_number)] + self.array_path_to_annot[ + self._get_annot_image_number_by_depth(depth_image_number) + ], ) return pcd diff --git a/project/annotators/AnnotatorImage.py b/project/annotators/AnnotatorImage.py index f7ec7c7..9299281 100644 --- a/project/annotators/AnnotatorImage.py +++ b/project/annotators/AnnotatorImage.py @@ -12,9 +12,16 @@ class AnnotatorImage(Annotator): Extracts planes from annotation in rgb format """ - def __init__(self, array_path_annot: List[str], array_path_depth: List[str], is_office: bool = False): + def __init__( + self, + array_path_annot: List[str], + array_path_depth: List[str], + is_office: bool = False, + ): super().__init__(array_path_annot) - self.depth_to_rgb = AnnotatorImage.__match_rgb_with_depth(array_path_annot, array_path_depth, is_office) + self.depth_to_rgb = AnnotatorImage.__match_rgb_with_depth( + array_path_annot, array_path_depth, is_office + ) def _get_planes(self, pcd, image_colors: str): planes_of_image = [] @@ -45,7 +52,7 @@ def __match_rgb_with_depth(rgb_filenames, depth_filenames, is_office: bool) -> l depth_to_rgb_index = [] rgb_index = 0 depth_index = 0 - prev_delta = float('inf') + prev_delta = float("inf") while depth_index < len(depth_filenames) and rgb_index < len(rgb_filenames): if is_office: rgb_timestamp = float(rgb_filenames[rgb_index][-8:-4]) diff --git a/project/annotators/AnnotatorPointCloud.py b/project/annotators/AnnotatorPointCloud.py index f902ee3..1aaa9ba 100644 --- a/project/annotators/AnnotatorPointCloud.py +++ b/project/annotators/AnnotatorPointCloud.py @@ -28,9 +28,7 @@ def _get_planes(self, pcd, image_colors: str): equation = Plane.get_equation(plane_points) equations.append(equation) - plane = Plane( - equation, track=annot_num, color=None, indices=indices - ) + plane = Plane(equation, track=annot_num, color=None, indices=indices) planes.append(plane) return planes diff --git a/project/associators/AssociatorAnnotNpy.py b/project/associators/AssociatorAnnotNpy.py index b63a4b0..aabcd86 100644 --- a/project/associators/AssociatorAnnotNpy.py +++ b/project/associators/AssociatorAnnotNpy.py @@ -17,7 +17,9 @@ def associate(self, pcd_s: List[Pcd]): for pcd in pcd_s: for plane in pcd.planes: if plane.track not in self.__track_to_color: - self.__track_to_color[plane.track] = color_to_string(get_random_color()) + self.__track_to_color[plane.track] = color_to_string( + get_random_color() + ) plane.color = color_from_string(self.__track_to_color[plane.track]) return pcd_s diff --git a/project/main.py b/project/main.py index 28f899b..3c4cb3e 100644 --- a/project/main.py +++ b/project/main.py @@ -24,7 +24,11 @@ from project.postprocessing.SmallPlanesFilter import SmallPlanesFilter from project.slam.EigenPointsSLAMGraph import EigenPointsSLAMGraph from project.slam.LandmarksSLAMGraph import LandmarksSLAMGraph -from project.utils.intervals import load_evaluation_intervals, dump_evaluation_intervals, ids_list_to_intervals +from project.utils.intervals import ( + load_evaluation_intervals, + dump_evaluation_intervals, + ids_list_to_intervals, +) FORMAT_ICL_TUM = 1 FORMAT_ICL = 2 @@ -72,8 +76,18 @@ def create_main_lists_office(main_data_path: str): def create_main_and_annot_list_carla(main_data_path: str): files = os.listdir(main_data_path) - annot_list = list(map(lambda x: os.path.join(main_data_path, x), filter(lambda x: x.endswith(".npy"), files))) - main_data_list = list(map(lambda x: os.path.join(main_data_path, x), filter(lambda x: x.endswith(".pcd"), files))) + annot_list = list( + map( + lambda x: os.path.join(main_data_path, x), + filter(lambda x: x.endswith(".npy"), files), + ) + ) + main_data_list = list( + map( + lambda x: os.path.join(main_data_path, x), + filter(lambda x: x.endswith(".pcd"), files), + ) + ) return annot_list, main_data_list @@ -154,7 +168,6 @@ def main( # TODO: 1203,1285 living # TODO: 1300,1508 living - # in not normalized format (0-255 for RGB) ignore_color_strs = [ # # Associator.make_string_from_array([156, 244, 150]), # подушка-сидушка левая --- не влияет на первом интервале (380 -- 500) @@ -186,7 +199,9 @@ def main( enough_intervals = ids_list_to_intervals(pcd_enough_planes_ids) dump_evaluation_intervals("intervals.csv", enough_intervals) else: - enough_intervals = load_evaluation_intervals(intervals_source_path, total_frames) + enough_intervals = load_evaluation_intervals( + intervals_source_path, total_frames + ) for interval in enough_intervals: pcds = [] @@ -209,7 +224,9 @@ def main( slam_graph = EigenPointsSLAMGraph() # graph_estimated_state = slam_graph.estimate_graph(pcds, max_tracks) graph_estimated_state_landmarks = slam_graph_landmarks.estimate_graph(pcds) - graph_estimated_state = slam_graph.estimate_graph(pcds, initial_poses=graph_estimated_state_landmarks) + graph_estimated_state = slam_graph.estimate_graph( + pcds, initial_poses=graph_estimated_state_landmarks + ) # measure_error = MeasureError(ds_filename_gt, len(annot_list), num_of_nodes) # measure_error.measure_error(first_node, first_gt_node, graph_estimated_state) @@ -240,7 +257,7 @@ def main( "--evaluate_intervals_source_path", type=str, default=None, - help="Path to csv with intervals of frames to evaluate on" + help="Path to csv with intervals of frames to evaluate on", ) parser.add_argument( "first_gt_node", type=int, help="From what node gt references start" diff --git a/project/pcdBuilders/PcdBuilderPointCloud.py b/project/pcdBuilders/PcdBuilderPointCloud.py index 3c920fc..bffaf33 100644 --- a/project/pcdBuilders/PcdBuilderPointCloud.py +++ b/project/pcdBuilders/PcdBuilderPointCloud.py @@ -13,11 +13,7 @@ class PcdBuilderPointCloud(PcdBuilder): """ def __init__( - self, - camera: Camera, - annot: AnnotatorPointCloud, - reflection=None, - scale=1000 + self, camera: Camera, annot: AnnotatorPointCloud, reflection=None, scale=1000 ): super().__init__(camera, annot) self.reflection = reflection diff --git a/project/postprocessing/PlaneInfoPrinter.py b/project/postprocessing/PlaneInfoPrinter.py index ffab489..62a72cb 100644 --- a/project/postprocessing/PlaneInfoPrinter.py +++ b/project/postprocessing/PlaneInfoPrinter.py @@ -12,6 +12,8 @@ def print_planes_info(pcds: List[Pcd]): for plane in pcd.planes: color_str = color_to_string(plane.color) if color_str not in data: - data[color_str] = "id: {0}, pts_cnt: {1}".format(plane.track, len(plane.plane_indices)) + data[color_str] = "id: {0}, pts_cnt: {1}".format( + plane.track, len(plane.plane_indices) + ) print(data) diff --git a/project/postprocessing/PlaneRemover.py b/project/postprocessing/PlaneRemover.py index 9b1098b..f030480 100644 --- a/project/postprocessing/PlaneRemover.py +++ b/project/postprocessing/PlaneRemover.py @@ -9,7 +9,10 @@ class PlaneRemover: def remove_by_colors(pcd: Pcd, color_strs: List[str]) -> Pcd: result = Pcd(pcd.points) for plane in pcd.planes: - if plane.color is None or Associator.make_string_from_array(plane.color) not in color_strs: + if ( + plane.color is None + or Associator.make_string_from_array(plane.color) not in color_strs + ): result.planes.append(plane) return result diff --git a/project/postprocessing/PostProcessing.py b/project/postprocessing/PostProcessing.py index f153c9d..42b8c96 100644 --- a/project/postprocessing/PostProcessing.py +++ b/project/postprocessing/PostProcessing.py @@ -29,4 +29,4 @@ def post_process(pcd_s: List[Pcd], verbose=False): map_indx_to_max_num_points = sorted( indx_to_max_num_points, key=indx_to_max_num_points.get ) - return map_indx_to_max_num_points[-config.MAX_PLANES_COUNT:] + return map_indx_to_max_num_points[-config.MAX_PLANES_COUNT :] diff --git a/project/slam/EigenPointsSLAMGraph.py b/project/slam/EigenPointsSLAMGraph.py index 9224a81..d52708e 100644 --- a/project/slam/EigenPointsSLAMGraph.py +++ b/project/slam/EigenPointsSLAMGraph.py @@ -6,7 +6,6 @@ class EigenPointsSLAMGraph(SLAMGraph): - def _add_plane_node(self) -> int: return self.graph.add_eigen_factor_plane() @@ -22,7 +21,7 @@ def _add_planes(self, pcd_s: List[Pcd], needed_indices: List[int]): planeEigenId=cur_indx, nodePoseId=self.graph_trajectory[i], pointsArray=plane_points, - W=1.0 + W=1.0, ) def _solve(self): diff --git a/project/slam/SLAMGraph.py b/project/slam/SLAMGraph.py index bc470e6..fbdfea2 100644 --- a/project/slam/SLAMGraph.py +++ b/project/slam/SLAMGraph.py @@ -34,9 +34,15 @@ def _add_plane_node(self) -> int: def _solve(self): pass - def __build_graph(self, pcd_s: List[Pcd], needed_indices: List[int] = None, initial_poses=None): + def __build_graph( + self, pcd_s: List[Pcd], needed_indices: List[int] = None, initial_poses=None + ): for index, _ in enumerate(pcd_s): - item = geometry.SE3() if initial_poses is None else geometry.SE3(initial_poses[index]) + item = ( + geometry.SE3() + if initial_poses is None + else geometry.SE3(initial_poses[index]) + ) if index == 0: next_node = self.graph.add_node_pose_3d(item, mrob.NODE_ANCHOR) else: @@ -46,13 +52,14 @@ def __build_graph(self, pcd_s: List[Pcd], needed_indices: List[int] = None, init for pcd in pcd_s: for plane in pcd.planes: if ( - (needed_indices is None or plane.track in needed_indices) - and plane.track not in self.plane_index_to_real_index - ): + needed_indices is None or plane.track in needed_indices + ) and plane.track not in self.plane_index_to_real_index: real_index = self._add_plane_node() self.plane_index_to_real_index[plane.track] = real_index - def estimate_graph(self, pcd_s: List[Pcd], needed_indices: List[int] = None, initial_poses=None): + def estimate_graph( + self, pcd_s: List[Pcd], needed_indices: List[int] = None, initial_poses=None + ): self.__build_graph(pcd_s, needed_indices, initial_poses) self._add_planes(pcd_s, needed_indices) self._solve() diff --git a/project/utils/colors.py b/project/utils/colors.py index 8ca8ea6..d9545d3 100644 --- a/project/utils/colors.py +++ b/project/utils/colors.py @@ -7,7 +7,9 @@ def color_to_string(color_arr): def color_from_string(color_str): - return np.fromiter((float(channel_str) for channel_str in color_str.split(',')), dtype=np.float64) + return np.fromiter( + (float(channel_str) for channel_str in color_str.split(",")), dtype=np.float64 + ) def normalize_color(color): @@ -34,7 +36,9 @@ def denormalize_color_arr(color_arr): def get_random_color(): random_color = np.asarray(UNSEGMENTED_PCD_COLOR) while color_to_string(random_color) in produced_colors_set: - random_color = np.asarray([int(x) for x in np.random.choice(range(256), size=3)]) + random_color = np.asarray( + [int(x) for x in np.random.choice(range(256), size=3)] + ) produced_colors_set.add(color_to_string(random_color)) @@ -43,5 +47,3 @@ def get_random_color(): def get_random_normalized_color(): return normalize_color(get_random_color()) - - diff --git a/project/utils/intervals.py b/project/utils/intervals.py index 038a2ca..466b29e 100644 --- a/project/utils/intervals.py +++ b/project/utils/intervals.py @@ -4,8 +4,8 @@ def load_evaluation_intervals(path: str, total_frames: int) -> List[Tuple[int, int]]: result = [] - with open(path, 'r', newline='') as csvfile: - reader = csv.reader(csvfile, delimiter=',', quotechar='|') + with open(path, "r", newline="") as csvfile: + reader = csv.reader(csvfile, delimiter=",", quotechar="|") for row in reader: from_id, to_id = row[:2] result.append((int(from_id), int(to_id))) @@ -14,12 +14,9 @@ def load_evaluation_intervals(path: str, total_frames: int) -> List[Tuple[int, i def dump_evaluation_intervals(path: str, intervals: List[Tuple[int, int]]): - with open(path, 'w', newline='') as csvfile: + with open(path, "w", newline="") as csvfile: writer = csv.writer( - csvfile, - delimiter=',', - quotechar='|', - quoting=csv.QUOTE_MINIMAL + csvfile, delimiter=",", quotechar="|", quoting=csv.QUOTE_MINIMAL ) for interval in intervals: writer.writerow(interval)