Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing black #13

Open
wants to merge 1 commit into
base: detect-enough-planes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions project/Visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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])
)
)

4 changes: 3 additions & 1 deletion project/annotators/Annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 10 additions & 3 deletions project/annotators/AnnotatorImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 1 addition & 3 deletions project/annotators/AnnotatorPointCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion project/associators/AssociatorAnnotNpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 21 additions & 7 deletions project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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,
)
from project.utils.quaternion import read_poses_csv

FORMAT_ICL_TUM = 1
Expand Down Expand Up @@ -74,8 +78,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

Expand Down Expand Up @@ -156,7 +170,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)
Expand Down Expand Up @@ -188,7 +201,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 = []
Expand Down Expand Up @@ -225,7 +240,6 @@ def main(
# graph_estimated_state = graph_estimated_state_landmarks
graph_estimated_state = read_poses_csv("pose_result.csv")


# measure_error = MeasureError(ds_filename_gt, len(annot_list), num_of_nodes)
# measure_error.measure_error(first_node, first_gt_node, graph_estimated_state)
#
Expand Down Expand Up @@ -255,7 +269,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"
Expand Down
6 changes: 1 addition & 5 deletions project/pcdBuilders/PcdBuilderPointCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion project/postprocessing/PlaneInfoPrinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 4 additions & 1 deletion project/postprocessing/PlaneRemover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion project/postprocessing/PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 :]
3 changes: 1 addition & 2 deletions project/slam/EigenPointsSLAMGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class EigenPointsSLAMGraph(SLAMGraph):

def _add_plane_node(self) -> int:
return self.graph.add_eigen_factor_plane()

Expand All @@ -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):
Expand Down
19 changes: 13 additions & 6 deletions project/slam/SLAMGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
10 changes: 6 additions & 4 deletions project/utils/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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))

Expand All @@ -43,5 +47,3 @@ def get_random_color():

def get_random_normalized_color():
return normalize_color(get_random_color())


11 changes: 4 additions & 7 deletions project/utils/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion project/utils/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def read_poses_csv(path_to_file: str) -> List[np.array]:
result = []
with open(path_to_file, 'r') as poses_file:
with open(path_to_file, "r") as poses_file:
for line in poses_file:
values = line.split(",")
x, y, z = list(map(lambda x: float(x), values[:3]))
Expand Down