Draw the category text on the image. Args: text (str): Text to be drawn. font (cv2.FONT_TYPE): The font type to be used to plot. Defaults to cv2.FONT_HERSHEY_SIMPLEX. pos (tuple): The drawing position. Defaults to (0, 0). size
(self,
text,
font=cv2.FONT_HERSHEY_SIMPLEX,
pos=(0, 0),
size=(0, 0),
font_scale=1,
font_thickness=2,
text_color=(0, 255, 0),
text_color_bg=(0, 0, 0))
| 29 | self.ALPHA = 0.75 |
| 30 | |
| 31 | def draw_text(self, |
| 32 | text, |
| 33 | font=cv2.FONT_HERSHEY_SIMPLEX, |
| 34 | pos=(0, 0), |
| 35 | size=(0, 0), |
| 36 | font_scale=1, |
| 37 | font_thickness=2, |
| 38 | text_color=(0, 255, 0), |
| 39 | text_color_bg=(0, 0, 0)): |
| 40 | """Draw the category text on the image. |
| 41 | |
| 42 | Args: |
| 43 | text (str): Text to be drawn. |
| 44 | font (cv2.FONT_TYPE): The font type to be used to plot. |
| 45 | Defaults to cv2.FONT_HERSHEY_SIMPLEX. |
| 46 | pos (tuple): The drawing position. Defaults to (0, 0). |
| 47 | size (tuple): Image size. Defaults to (0, 0). |
| 48 | font_scale (int): Font scale. Defaults to 1. |
| 49 | font_thickness (int): Font thickness. Defaults to 2. |
| 50 | text_color (tuple): Font color. Defaults to (0, 255, 0). |
| 51 | text_color_bg (tuple): Background color for drawing texts. |
| 52 | Defaults to (0, 0, 0). |
| 53 | """ |
| 54 | |
| 55 | x, y = pos |
| 56 | w, h = size |
| 57 | text_size, _ = cv2.getTextSize(text, font, font_scale, font_thickness) |
| 58 | text_w, text_h = text_size |
| 59 | if y * 2 > h: |
| 60 | dy = -10 |
| 61 | else: |
| 62 | dy = 10 |
| 63 | |
| 64 | try: |
| 65 | while self.occupied[y, x] or self.occupied[ |
| 66 | y, x + |
| 67 | text_w] or self.occupied[y + text_h, |
| 68 | x] or self.occupied[y + text_h, |
| 69 | x + text_w]: |
| 70 | y += dy |
| 71 | except: # noqa: E722 |
| 72 | pass |
| 73 | # TODO |
| 74 | cv2.rectangle(self.img, (x, y), (x + text_w, y + text_h), |
| 75 | text_color_bg, -1) |
| 76 | cv2.putText(self.img, text, (x, y + text_h + font_scale - 1), font, |
| 77 | font_scale, text_color, font_thickness) |
| 78 | |
| 79 | self.occupied[y:y + text_h, x:x + text_w] = True |
| 80 | |
| 81 | def draw_box3d(self, box, color, label, extrinsic, intrinsic): |
| 82 | """Draw 3D boxes on the image. |