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

Method draw_text

utils/visualizer.py:862–907  ·  view source on GitHub ↗

Args: text (str): class label position (tuple): a tuple of the x and y coordinates to place text on image. font_size (int, optional): font of the text. If not provided, a font size proportional to the image width is calculated and used.

(
        self,
        text,
        position,
        *,
        font_size=None,
        color="g",
        horizontal_alignment="center",
        rotation=0,
    )

Source from the content-addressed store, hash-verified

860 """
861
862 def draw_text(
863 self,
864 text,
865 position,
866 *,
867 font_size=None,
868 color="g",
869 horizontal_alignment="center",
870 rotation=0,
871 ):
872 """
873 Args:
874 text (str): class label
875 position (tuple): a tuple of the x and y coordinates to place text on image.
876 font_size (int, optional): font of the text. If not provided, a font size
877 proportional to the image width is calculated and used.
878 color: color of the text. Refer to `matplotlib.colors` for full list
879 of formats that are accepted.
880 horizontal_alignment (str): see `matplotlib.text.Text`
881 rotation: rotation angle in degrees CCW
882
883 Returns:
884 output (VisImage): image object with text drawn.
885 """
886 if not font_size:
887 font_size = self._default_font_size
888
889 # since the text background is dark, we don't want the text to be dark
890 color = np.maximum(list(mplc.to_rgb(color)), 0.2)
891 color[np.argmax(color)] = max(0.8, np.max(color))
892
893 x, y = position
894 self.output.ax.text(
895 x,
896 y,
897 text,
898 size=font_size * self.output.scale,
899 family="sans-serif",
900 bbox={"facecolor": "black", "alpha": 0.8, "pad": 0.7, "edgecolor": "none"},
901 verticalalignment="top",
902 horizontalalignment=horizontal_alignment,
903 color=color,
904 zorder=10,
905 rotation=rotation,
906 )
907 return self.output
908
909 def draw_box(self, box_coord, alpha=0.5, edge_color="g", line_style="-"):
910 """

Callers 3

overlay_instancesMethod · 0.95
_draw_text_in_maskMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected