Skip to content

Commit

Permalink
bugfixing wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SirMDA committed Dec 5, 2024
1 parent 91004df commit 44864ac
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions code/perception/src/vision_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,30 +356,26 @@ def predict_ultralytics(self, image):
c_boxes = []
c_labels = []
c_colors = []
if hasattr(output[0], "masks") and output[0].masks is not None:
masks = output[0].masks.data
else:
masks = None

boxes = output[0].boxes
masks = output[0].masks.data
for box in boxes:
cls = box.cls.item() # class index of object
pixels = box.xyxy[0] # upper left and lower right pixel coords

# only run distance calc when dist_array is available
# this if is needed because the lidar starts
# publishing with a delay
if self.dist_arrays is None:
continue

# crop bounding box area out of depth image
distances = np.asarray(
self.dist_arrays[
int(pixels[1]) : int(pixels[3]) : 1,
int(pixels[0]) : int(pixels[2]) : 1,
::,
]
)
if self.dist_arrays is not None:

# crop bounding box area out of depth image
distances = np.asarray(
self.dist_arrays[
int(pixels[1]) : int(pixels[3]) : 1,
int(pixels[0]) : int(pixels[2]) : 1,
::,
]
)

# set all 0 (black) values to np.inf (necessary if
# you want to search for minimum)
Expand Down Expand Up @@ -458,18 +454,18 @@ def predict_ultralytics(self, image):
width=3,
font_size=12,
)
if masks is not None:
scaled_masks = np.squeeze(
scale_masks(masks.unsqueeze(1), cv_image.shape[:2], True).cpu().numpy(),
1,
)

drawn_images = draw_segmentation_masks(
drawn_images,
torch.from_numpy(scaled_masks > 0),
alpha=0.6,
colors=c_colors,
)
scaled_masks = np.squeeze(
scale_masks(masks.unsqueeze(1), cv_image.shape[:2], True).cpu().numpy(),
1,
)

drawn_images = draw_segmentation_masks(
drawn_images,
torch.from_numpy(scaled_masks > 0),
alpha=0.6,
colors=c_colors,
)

np_image = np.transpose(drawn_images.detach().numpy(), (1, 2, 0))
return cv2.cvtColor(np_image, cv2.COLOR_BGR2RGB)
Expand Down

0 comments on commit 44864ac

Please sign in to comment.