Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
ce7fa81d
Unverified
提交
ce7fa81d
authored
9月 24, 2021
作者:
Jiacong Fang
提交者:
GitHub
9月 24, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid out-of-image class labels (#4902)
* Avoid out-of-image class labels * Update plots.py * Cleanup Co-authored-by:
Glenn Jocher
<
glenn.jocher@ultralytics.com
>
上级
dad86605
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
15 行增加
和
11 行删除
+15
-11
plots.py
utils/plots.py
+15
-11
没有找到文件。
utils/plots.py
浏览文件 @
ce7fa81d
...
...
@@ -73,7 +73,6 @@ class Annotator:
self
.
im
=
im
if
isinstance
(
im
,
Image
.
Image
)
else
Image
.
fromarray
(
im
)
self
.
draw
=
ImageDraw
.
Draw
(
self
.
im
)
self
.
font
=
check_font
(
font
,
size
=
font_size
or
max
(
round
(
sum
(
self
.
im
.
size
)
/
2
*
0.035
),
12
))
self
.
fh
=
self
.
font
.
getsize
(
'a'
)[
1
]
-
3
# font height
else
:
# use cv2
self
.
im
=
im
self
.
lw
=
line_width
or
max
(
round
(
sum
(
im
.
shape
)
/
2
*
0.003
),
2
)
# line width
...
...
@@ -83,20 +82,25 @@ class Annotator:
if
self
.
pil
or
not
is_ascii
(
label
):
self
.
draw
.
rectangle
(
box
,
width
=
self
.
lw
,
outline
=
color
)
# box
if
label
:
w
,
h
=
self
.
font
.
getsize
(
label
)
# text width
self
.
draw
.
rectangle
([
box
[
0
],
box
[
1
]
-
self
.
fh
,
box
[
0
]
+
w
+
1
,
box
[
1
]
+
1
],
fill
=
color
)
w
,
h
=
self
.
font
.
getsize
(
label
)
# text width, height
outside
=
box
[
1
]
-
h
>=
0
# label fits outside box
self
.
draw
.
rectangle
([
box
[
0
],
box
[
1
]
-
h
if
outside
else
box
[
1
],
box
[
0
]
+
w
+
1
,
box
[
1
]
+
1
if
outside
else
box
[
1
]
+
h
+
1
],
fill
=
color
)
# self.draw.text((box[0], box[1]), label, fill=txt_color, font=self.font, anchor='ls') # for PIL>8.0
self
.
draw
.
text
((
box
[
0
],
box
[
1
]
-
h
),
label
,
fill
=
txt_color
,
font
=
self
.
font
)
self
.
draw
.
text
((
box
[
0
],
box
[
1
]
-
h
if
outside
else
box
[
1
]
),
label
,
fill
=
txt_color
,
font
=
self
.
font
)
else
:
# cv2
c1
,
c
2
=
(
int
(
box
[
0
]),
int
(
box
[
1
])),
(
int
(
box
[
2
]),
int
(
box
[
3
]))
cv2
.
rectangle
(
self
.
im
,
c1
,
c
2
,
color
,
thickness
=
self
.
lw
,
lineType
=
cv2
.
LINE_AA
)
p1
,
p
2
=
(
int
(
box
[
0
]),
int
(
box
[
1
])),
(
int
(
box
[
2
]),
int
(
box
[
3
]))
cv2
.
rectangle
(
self
.
im
,
p1
,
p
2
,
color
,
thickness
=
self
.
lw
,
lineType
=
cv2
.
LINE_AA
)
if
label
:
tf
=
max
(
self
.
lw
-
1
,
1
)
# font thickness
w
,
h
=
cv2
.
getTextSize
(
label
,
0
,
fontScale
=
self
.
lw
/
3
,
thickness
=
tf
)[
0
]
c2
=
c1
[
0
]
+
w
,
c1
[
1
]
-
h
-
3
cv2
.
rectangle
(
self
.
im
,
c1
,
c2
,
color
,
-
1
,
cv2
.
LINE_AA
)
# filled
cv2
.
putText
(
self
.
im
,
label
,
(
c1
[
0
],
c1
[
1
]
-
2
),
0
,
self
.
lw
/
3
,
txt_color
,
thickness
=
tf
,
lineType
=
cv2
.
LINE_AA
)
w
,
h
=
cv2
.
getTextSize
(
label
,
0
,
fontScale
=
self
.
lw
/
3
,
thickness
=
tf
)[
0
]
# text width, height
outside
=
p1
[
1
]
-
h
-
3
>=
0
# label fits outside box
p2
=
p1
[
0
]
+
w
,
p1
[
1
]
-
h
-
3
if
outside
else
p1
[
1
]
+
h
+
3
cv2
.
rectangle
(
self
.
im
,
p1
,
p2
,
color
,
-
1
,
cv2
.
LINE_AA
)
# filled
cv2
.
putText
(
self
.
im
,
label
,
(
p1
[
0
],
p1
[
1
]
-
2
if
outside
else
p1
[
1
]
+
h
+
2
),
0
,
self
.
lw
/
3
,
txt_color
,
thickness
=
tf
,
lineType
=
cv2
.
LINE_AA
)
def
rectangle
(
self
,
xy
,
fill
=
None
,
outline
=
None
,
width
=
1
):
# Add rectangle to image (PIL-only)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论