(img, tgt_patch, inputs_size)
| 32 | return tempimg |
| 33 | |
| 34 | def draw_patch_in_img(img, tgt_patch, inputs_size): |
| 35 | tl = 1 # thickness line |
| 36 | tf = max(tl-1,1) # font thickness |
| 37 | color = [0,255,0] # color |
| 38 | point_size = 4 |
| 39 | point_color = (255, 0, 0) # BGR |
| 40 | point_thickness = 4 # 可以为 0 、4、8 |
| 41 | tempimg = copy.deepcopy(img) |
| 42 | h, w = inputs_size |
| 43 | labels = tgt_patch['labels'].cpu() |
| 44 | patch_indexs = tgt_patch['patch_index'].cpu() |
| 45 | centers = tgt_patch['centers'].cpu() |
| 46 | w_num = w//16 |
| 47 | for patch_index, label, center in zip(patch_indexs, labels, centers): |
| 48 | point = (int(center[0]), int(center[1])) |
| 49 | cv2.circle(tempimg, point, point_size, point_color, point_thickness) |
| 50 | y_start_index = patch_index // w_num |
| 51 | x_start_index = patch_index - y_start_index*w_num |
| 52 | x_start = x_start_index * 16 |
| 53 | y_start = y_start_index * 16 |
| 54 | x_end = x_start + 16 |
| 55 | y_end = y_start + 16 |
| 56 | c1, c2 = (int(x_start), int(y_start)), (int(x_end), int(y_end)) |
| 57 | cv2.rectangle(tempimg,c1,c2,color,thickness=tl, lineType=cv2.LINE_AA) |
| 58 | label = str(int(label)) |
| 59 | t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0] |
| 60 | c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3 |
| 61 | cv2.rectangle(tempimg, c1, c2, color, -1, cv2.LINE_AA) # filled |
| 62 | cv2.putText(tempimg, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA) |
| 63 | return tempimg |
nothing calls this directly
no outgoing calls
no test coverage detected