(cv2_img, prob, boxes, output_dir)
| 104 | cv2.imwrite(fname, im) |
| 105 | |
| 106 | def plot_results(cv2_img, prob, boxes, output_dir): |
| 107 | tl = 3 # thickness line |
| 108 | tf = max(tl-1,1) # font thickness |
| 109 | tempimg = copy.deepcopy(cv2_img) |
| 110 | color = [0,0,255] |
| 111 | for p, (xmin, ymin, xmax, ymax) in zip(prob, boxes.tolist()): |
| 112 | c1, c2 = (int(xmin), int(ymin)), (int(xmax), int(ymax)) |
| 113 | cv2.rectangle(tempimg, c1, c2, color, tl, cv2.LINE_AA) |
| 114 | cl = p.argmax() |
| 115 | text = f'{CLASSES[cl]}: {p[cl]:0.2f}' |
| 116 | t_size = cv2.getTextSize(text, 0, fontScale=tl / 3, thickness=tf)[0] |
| 117 | c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3 |
| 118 | cv2.rectangle(tempimg, c1, c2, color, -1, cv2.LINE_AA) # filled |
| 119 | cv2.putText(tempimg, text, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA) |
| 120 | fname = os.path.join(output_dir,'pred_img.png') |
| 121 | cv2.imwrite(fname, tempimg) |
| 122 | print(f"{fname} saved.") |
| 123 | |
| 124 | def increment_path(path, exist_ok=False, sep='', mkdir=False): |
| 125 | # Increment file or directory path, i.e. runs/exp --> runs/exp{sep}2, runs/exp{sep}3, ... etc. |
no test coverage detected