(img_path, output_path, elem_list, record_mode=False, dark_mode=False)
| 28 | |
| 29 | |
| 30 | def draw_bbox_multi(img_path, output_path, elem_list, record_mode=False, dark_mode=False): |
| 31 | imgcv = cv2.imread(img_path) |
| 32 | count = 1 |
| 33 | for elem in elem_list: |
| 34 | try: |
| 35 | top_left = elem.bbox[0] |
| 36 | bottom_right = elem.bbox[1] |
| 37 | left, top = top_left[0], top_left[1] |
| 38 | right, bottom = bottom_right[0], bottom_right[1] |
| 39 | label = str(count) |
| 40 | if record_mode: |
| 41 | if elem.attrib == "clickable": |
| 42 | color = (250, 0, 0) |
| 43 | elif elem.attrib == "focusable": |
| 44 | color = (0, 0, 250) |
| 45 | else: |
| 46 | color = (0, 250, 0) |
| 47 | imgcv = ps.putBText(imgcv, label, text_offset_x=(left + right) // 2 + 10, text_offset_y=(top + bottom) // 2 + 10, |
| 48 | vspace=10, hspace=10, font_scale=1, thickness=2, background_RGB=color, |
| 49 | text_RGB=(255, 250, 250), alpha=0.5) |
| 50 | else: |
| 51 | text_color = (10, 10, 10) if dark_mode else (255, 250, 250) |
| 52 | bg_color = (255, 250, 250) if dark_mode else (10, 10, 10) |
| 53 | imgcv = ps.putBText(imgcv, label, text_offset_x=(left + right) // 2 + 10, text_offset_y=(top + bottom) // 2 + 10, |
| 54 | vspace=10, hspace=10, font_scale=1, thickness=2, background_RGB=bg_color, |
| 55 | text_RGB=text_color, alpha=0.5) |
| 56 | except Exception as e: |
| 57 | print_with_color(f"ERROR: An exception occurs while labeling the image\n{e}", "red") |
| 58 | count += 1 |
| 59 | cv2.imwrite(output_path, imgcv) |
| 60 | return imgcv |
| 61 | |
| 62 | |
| 63 | def draw_grid(img_path, output_path): |
no test coverage detected