MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / overlay_rotated_instances

Method overlay_rotated_instances

utils/visualizer.py:761–797  ·  view source on GitHub ↗

Args: boxes (ndarray): an Nx5 numpy array of (x_center, y_center, width, height, angle_degrees) format for the N objects in a single image. labels (list[str]): the text to be displayed for each instance. assigned_colors (li

(self, boxes=None, labels=None, assigned_colors=None)

Source from the content-addressed store, hash-verified

759 return self.output
760
761 def overlay_rotated_instances(self, boxes=None, labels=None, assigned_colors=None):
762 """
763 Args:
764 boxes (ndarray): an Nx5 numpy array of
765 (x_center, y_center, width, height, angle_degrees) format
766 for the N objects in a single image.
767 labels (list[str]): the text to be displayed for each instance.
768 assigned_colors (list[matplotlib.colors]): a list of colors, where each color
769 corresponds to each mask or box in the image. Refer to 'matplotlib.colors'
770 for full list of formats that the colors are accepted in.
771
772 Returns:
773 output (VisImage): image object with visualizations.
774 """
775 num_instances = len(boxes)
776
777 if assigned_colors is None:
778 assigned_colors = [random_color(rgb=True, maximum=1) for _ in range(num_instances)]
779 if num_instances == 0:
780 return self.output
781
782 # Display in largest to smallest order to reduce occlusion.
783 if boxes is not None:
784 areas = boxes[:, 2] * boxes[:, 3]
785
786 sorted_idxs = np.argsort(-areas).tolist()
787 # Re-order overlapped instances in descending order.
788 boxes = boxes[sorted_idxs]
789 labels = [labels[k] for k in sorted_idxs] if labels is not None else None
790 colors = [assigned_colors[idx] for idx in sorted_idxs]
791
792 for i in range(num_instances):
793 self.draw_rotated_box_with_label(
794 boxes[i], edge_color=colors[i], label=labels[i] if labels is not None else None
795 )
796
797 return self.output
798
799 def draw_and_connect_keypoints(self, keypoints):
800 """

Callers 1

overlay_instancesMethod · 0.95

Calls 1

Tested by

no test coverage detected