Skip to content

Commit

Permalink
making folder consistent; still showing results if no bagfile
Browse files Browse the repository at this point in the history
  • Loading branch information
marinagmoreira committed Apr 9, 2024
1 parent 02b2f40 commit 5c9670c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 46 deletions.
2 changes: 1 addition & 1 deletion analyst/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
94 changes: 51 additions & 43 deletions anomaly/image_str/scripts/image_str/parse_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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")
Expand All @@ -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(
[
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/docker/docker_compose/analyst.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5c9670c

Please sign in to comment.