From 5c9670cb1d2c58f145bdf7d24c101eacd415b036 Mon Sep 17 00:00:00 2001 From: Marina Moreira Date: Tue, 9 Apr 2024 16:31:28 -0700 Subject: [PATCH] making folder consistent; still showing results if no bagfile --- analyst/readme.md | 2 +- .../image_str/scripts/image_str/parse_img.py | 94 ++++++++++--------- .../docker_compose/analyst.docker-compose.yml | 4 +- 3 files changed, 54 insertions(+), 46 deletions(-) diff --git a/analyst/readme.md b/analyst/readme.md index 26b835a6..b0f85039 100644 --- a/analyst/readme.md +++ b/analyst/readme.md @@ -5,7 +5,7 @@ **The jupyter notebooks will be able to access data that is in the `$HOME/data` and `$HOME/data/bags`, therefore, make sure all the relevant bag files are there** -**If you want to run the OCR, make sure there is a `$HOME/data/images` folder with all the data** +**If you want to run the OCR, make sure there is a `$HOME/data/str` folder with all the data** For the Analyst notebook to be functional, it needs to start side-by-side with the database and the IUI (ISAAC user interface). To do so, the recommended method is to use the remote docker images, as: diff --git a/anomaly/image_str/scripts/image_str/parse_img.py b/anomaly/image_str/scripts/image_str/parse_img.py index d4d16bf4..94d44b23 100755 --- a/anomaly/image_str/scripts/image_str/parse_img.py +++ b/anomaly/image_str/scripts/image_str/parse_img.py @@ -353,6 +353,8 @@ def __decode_image( h, w, _ = image.shape bag_name = None + ros_command = None + data = None # Set up the command to find_point_coordinate if self.bag_path is not None: @@ -538,18 +540,17 @@ def __decode_image( if increment: result_image = self.__display_all(image, df, result_path) - if bag_name is not None: - # Get the locations in the world frame - self.__get_all_locations( - df, - data, - ros_command, - all_locations, - result_path, - final_file, - image_path, - increment, - ) + # Get the locations in the world frame + self.__get_all_locations( + df, + data, + ros_command, + all_locations, + result_path, + final_file, + image_path, + increment, + ) def __get_location(self, data, new_location, ros_command): """ @@ -612,10 +613,13 @@ def __get_all_locations( header = ["label", "PCL Intersection", "Mesh Intersection", "image", "location"] f = None final = None - if result_path is not None and increment: + result_positions = None + if increment: f = open(result_path[:-4] + "_locations.csv", "w") writer = csv.writer(f, delimiter=";") writer.writerow(header) + if f is not None: + print("if f is not None") if final_file is not None: final = open(final_file, "a") @@ -625,33 +629,34 @@ def __get_all_locations( label = row["label"] new_location = row["location"] - result_positions = self.__get_location(data, new_location, ros_command) - if result_positions is None: - continue - location = tuple(result_positions["PCL Intersection"].values()) - duplicate = [loc for loc in all_locations if utils.duplicate(location, loc)] - if len(duplicate) != 0: - continue - - pcl = result_positions["PCL Intersection"] pcl_str = "" - if pcl is not None: - pcl = list(pcl.values()) - pcl_str = str(pcl) - - mesh = result_positions["Mesh Intersection"] mesh_str = "" - if mesh is not None: - mesh = list(mesh.values()) - mesh_str = str(mesh) + if data is not None: + result_positions = self.__get_location(data, new_location, ros_command) - self.dataframe.loc[len(self.dataframe)] = [ - label, - new_location, - image_path, - pcl, - mesh, - ] + location = tuple(result_positions["PCL Intersection"].values()) + duplicate = [ + loc for loc in all_locations if utils.duplicate(location, loc) + ] + if len(duplicate) != 0: + continue + + if result_positions["PCL Intersection"] is not None: + pcl = list(result_positions["PCL Intersection"].values()) + pcl_str = str(pcl) + + if result_positions["Mesh Intersection"] is not None: + mesh = list(result_positions["Mesh Intersection"].values()) + mesh_str = str(mesh) + + self.dataframe.loc[len(self.dataframe)] = [ + label, + new_location, + image_path, + pcl, + mesh, + ] + all_locations.add(location) line = np.array( [ @@ -668,8 +673,6 @@ def __get_all_locations( if final is not None: writer_final.writerow(line) - all_locations.add(location) - if f is not None: f.close() @@ -785,7 +788,7 @@ def find_label(self, label, display_img=True, jupyter=False): layout=widgets.Layout(height="100%", width="100%"), ) - def display_labels(fig, image_file, rect, result, title): + def display_labels(fig, image_file, rect, title, result): offset = 100 if display_img: image = cv2.imread(image_file) @@ -831,7 +834,7 @@ def callback_left_button(event): if index == 0: return index -= 1 - title = "Image: {:d}/{:d}".format(index + 1, len(results)) + title = "Image: {:d}/{:d}".format(index + 1, len(rectangles)) if display_img: fig = plt.gcf() display_labels( @@ -855,11 +858,11 @@ def callback_right_button(event): else: display_labels(None, None, None, results[index], title) - if len(results) == 0: + if len(rectangles) == 0: print("No results found") return - title = "Image: {:d}/{:d}".format(index + 1, len(results)) + title = "Image: {:d}/{:d}".format(index + 1, len(rectangles)) if display_img: fig, ax = plt.subplots(1, 2, figsize=(10, 5)) plt.tight_layout() @@ -967,6 +970,11 @@ def __find_image(self, image_file, df, label, display_img): continue rects.append(rectangles[i]) + # If no location available + if pos is None: + locations.append("") + continue + all_locations.add(tuple(pos)) # Create panorama link diff --git a/scripts/docker/docker_compose/analyst.docker-compose.yml b/scripts/docker/docker_compose/analyst.docker-compose.yml index a9d243f4..4052d381 100644 --- a/scripts/docker/docker_compose/analyst.docker-compose.yml +++ b/scripts/docker/docker_compose/analyst.docker-compose.yml @@ -38,8 +38,8 @@ services: source: ${BAGS_PATH:-$HOME/data/bags} target: /home/analyst/data/bags - type: bind - source: ${IMG_PATH:-$HOME/data/images} - target: /home/analyst/data/images + source: ${IMG_PATH:-$HOME/data/str} + target: /home/analyst/data/str links: - isaac