|
11 | 11 | import cv2 |
12 | 12 | import math |
13 | 13 | from PIL import Image, ImageFont, ImageDraw |
14 | | -from opencv_tools.jade_opencv_process import GetRandomColor |
| 14 | +from opencv_tools.jade_opencv_process import GetRandomColor,ReadChinesePath |
15 | 15 | from jade import getOperationSystem |
16 | 16 | def get_color_map_list(num_classes): |
17 | 17 | """ |
@@ -246,6 +246,30 @@ def visualize_box_mask(im, results, mask_resolution=14,show_score=True,font_path |
246 | 246 | im = draw_lmk(im, results['landmark']) |
247 | 247 | return im |
248 | 248 |
|
| 249 | +def cv_visualize(image,results,show_score=True,font_path=None,thickness=2,linetype=2,font_size=24): |
| 250 | + if isinstance(image, str): |
| 251 | + image = ReadChinesePath(image) |
| 252 | + boxes = results["boxes"] |
| 253 | + scores = results["scores"] |
| 254 | + labels = results["labels"] |
| 255 | + colors = [GetRandomColor()] * labels.shape[0] |
| 256 | + for (box,score,label,color) in zip(boxes,scores,labels,colors): |
| 257 | + if label != -1: |
| 258 | + cv2.line(image, (int(box[0]), int(box[1])), (int(box[0]), int(box[1] + box[3])), color, thickness, |
| 259 | + thickness) |
| 260 | + cv2.line(image, (int(box[0]), int(box[1] + box[3])), (int(box[2]), int(box[1] + box[3])), color, thickness, |
| 261 | + thickness) |
| 262 | + cv2.line(image, (int(box[2]), int(box[1] + box[3])), (int(box[2]), int(box[1])), color, thickness, |
| 263 | + thickness) |
| 264 | + cv2.line(image, (int(box[2]), int(box[1])), (int(box[0]), int(box[1])), color, thickness, thickness) |
| 265 | + if show_score: |
| 266 | + image = Add_Chinese_Label(image, label+" SCORE:{}".format("%.2f"%score), (int(box[0]), int(box[1])), color, font_size, font_path) |
| 267 | + else: |
| 268 | + image = Add_Chinese_Label(image, label, (int(box[0]), int(box[1])), color, font_size, font_path) |
| 269 | + |
| 270 | + return image |
| 271 | + |
| 272 | + |
249 | 273 | def visualize(image_file, |
250 | 274 | results, |
251 | 275 | mask_resolution=14, |
|
0 commit comments