未验证 提交 dc4602c7 编写于 作者: J jaycecd 提交者: GitHub

display probability scores on visualization (#5854)

* display probability scores on visualization

* display probability scores on visualization
上级 cfd884d2
...@@ -429,6 +429,7 @@ def draw_ocr_box_txt(image, ...@@ -429,6 +429,7 @@ def draw_ocr_box_txt(image,
boxes, boxes,
txts, txts,
scores=None, scores=None,
show_score=False,
drop_score=0.5, drop_score=0.5,
font_path="./doc/simfang.ttf"): font_path="./doc/simfang.ttf"):
h, w = image.height, image.width h, w = image.height, image.width
...@@ -440,7 +441,7 @@ def draw_ocr_box_txt(image, ...@@ -440,7 +441,7 @@ def draw_ocr_box_txt(image,
random.seed(0) random.seed(0)
draw_left = ImageDraw.Draw(img_left) draw_left = ImageDraw.Draw(img_left)
draw_right = ImageDraw.Draw(img_right) draw_right = ImageDraw.Draw(img_right)
for idx, (box, txt) in enumerate(zip(boxes, txts)): for idx, (box, txt, score) in enumerate(zip(boxes, txts, scores)):
if scores is not None and scores[idx] < drop_score: if scores is not None and scores[idx] < drop_score:
continue continue
color = (random.randint(0, 255), random.randint(0, 255), color = (random.randint(0, 255), random.randint(0, 255),
...@@ -456,6 +457,8 @@ def draw_ocr_box_txt(image, ...@@ -456,6 +457,8 @@ def draw_ocr_box_txt(image,
1])**2) 1])**2)
box_width = math.sqrt((box[0][0] - box[1][0])**2 + (box[0][1] - box[1][ box_width = math.sqrt((box[0][0] - box[1][0])**2 + (box[0][1] - box[1][
1])**2) 1])**2)
if show_score:
txt = txt + ':' + str(score)
if box_height > 2 * box_width: if box_height > 2 * box_width:
font_size = max(int(box_width * 0.9), 10) font_size = max(int(box_width * 0.9), 10)
font = ImageFont.truetype(font_path, font_size, encoding="utf-8") font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册