Skip to content

Commit 4368b1c

Browse files
committed
* 解决text box获取字体大小不正确的bug
1 parent 60893d3 commit 4368b1c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
### 更新日志
22

33

4-
#### OpencvToolsV1.2.9 - 2024-02-26
5-
* 解决PIL中的警告,使用textbbox替代textsize
4+
#### OpencvToolsV1.3.0 - 2024-02-26
5+
* 解决text box获取字体大小不正确的bug
66
---
77

88
<details onclose>
99
<summary>查看更多更新日志</summary>
1010

11+
#### OpencvToolsV1.2.9 - 2024-02-26
12+
* 解决PIL中的警告,使用textbbox替代textsize
13+
---
1114

1215
#### OpencvToolsV1.2.8 - 2023-04-07
1316
* 新增cv_show方法

opencv_tools/jade_visualize.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ def draw_box(im, results,show_score=True,font_path=None,font_size=24):
8080
else:
8181
text = "{} ".format(labels_text[i,])
8282
font = ImageFont.truetype(get_font_path(font_path), font_size, encoding="utf-8") # 参数1:字体文件路径,参数2:字体大小
83-
x1,y1,w,h = draw.textbbox((0, 0), text, font=font)
84-
draw.rectangle(
85-
[(xmin + x1, ymin - y1), (xmin + w , ymin)], fill=color)
86-
draw.text((xmin, ymin - x1), text, fill=(255, 255, 255),font=font)
83+
bbox = draw.textbbox((0, 0), text, font=font)
84+
text_width = bbox[2] - bbox[0]
85+
text_height = bbox[3] - bbox[1]
86+
draw.rectangle([(xmin + 1, ymin - text_height), (xmin + text_width + 1, ymin)], fill=color)
87+
draw.text((xmin + 1, ymin - text_height), text, fill=(255, 255, 255),font=font)
8788
im = np.array(im)
8889
return im
8990

0 commit comments

Comments
 (0)