Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
de534e92
Unverified
提交
de534e92
authored
8月 31, 2021
作者:
Glenn Jocher
提交者:
GitHub
8月 31, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix 3 for Arial.ttf redownloads with hub inference (#4629)
Fix 3 for Arial.ttf redownloads with hub inference, follow-on to #4628.
上级
a4e8f78c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
17 行增加
和
13 行删除
+17
-13
plots.py
utils/plots.py
+17
-13
没有找到文件。
utils/plots.py
浏览文件 @
de534e92
...
@@ -48,7 +48,22 @@ class Colors:
...
@@ -48,7 +48,22 @@ class Colors:
colors
=
Colors
()
# create instance for 'from utils.plots import colors'
colors
=
Colors
()
# create instance for 'from utils.plots import colors'
def
check_font
(
font
=
'Arial.ttf'
,
size
=
10
):
# Return a PIL TrueType Font, downloading to ROOT dir if necessary
font
=
Path
(
font
)
font
=
font
if
font
.
exists
()
else
(
ROOT
/
font
.
name
)
try
:
return
ImageFont
.
truetype
(
str
(
font
)
if
font
.
exists
()
else
font
.
name
,
size
)
except
Exception
as
e
:
# download if missing
url
=
"https://ultralytics.com/assets/"
+
font
.
name
print
(
f
'Downloading {url} to {font}...'
)
torch
.
hub
.
download_url_to_file
(
url
,
str
(
font
))
return
ImageFont
.
truetype
(
str
(
font
),
size
)
class
Annotator
:
class
Annotator
:
check_font
()
# download TTF if necessary
# YOLOv5 Annotator for train/val mosaics and jpgs and detect/hub inference annotations
# YOLOv5 Annotator for train/val mosaics and jpgs and detect/hub inference annotations
def
__init__
(
self
,
im
,
line_width
=
None
,
font_size
=
None
,
font
=
'Arial.ttf'
,
pil
=
True
):
def
__init__
(
self
,
im
,
line_width
=
None
,
font_size
=
None
,
font
=
'Arial.ttf'
,
pil
=
True
):
assert
im
.
data
.
contiguous
,
'Image not contiguous. Apply np.ascontiguousarray(im) to Annotator() input images.'
assert
im
.
data
.
contiguous
,
'Image not contiguous. Apply np.ascontiguousarray(im) to Annotator() input images.'
...
@@ -56,22 +71,11 @@ class Annotator:
...
@@ -56,22 +71,11 @@ class Annotator:
if
self
.
pil
:
# use PIL
if
self
.
pil
:
# use PIL
self
.
im
=
im
if
isinstance
(
im
,
Image
.
Image
)
else
Image
.
fromarray
(
im
)
self
.
im
=
im
if
isinstance
(
im
,
Image
.
Image
)
else
Image
.
fromarray
(
im
)
self
.
draw
=
ImageDraw
.
Draw
(
self
.
im
)
self
.
draw
=
ImageDraw
.
Draw
(
self
.
im
)
s
=
sum
(
self
.
im
.
size
)
/
2
# mean shape
self
.
font
=
check_font
(
font
,
size
=
font_size
or
max
(
round
(
sum
(
self
.
im
.
size
)
/
2
*
0.035
),
12
))
f
=
font_size
or
max
(
round
(
s
*
0.035
),
12
)
font
=
Path
(
font
)
# font handling
font
=
font
if
font
.
exists
()
else
(
ROOT
/
font
.
name
)
try
:
self
.
font
=
ImageFont
.
truetype
(
str
(
font
)
if
font
.
exists
()
else
font
.
name
,
size
=
f
)
except
Exception
as
e
:
# download if missing
url
=
"https://ultralytics.com/assets/"
+
font
.
name
print
(
f
'Downloading {url} to {font}...'
)
torch
.
hub
.
download_url_to_file
(
url
,
str
(
font
))
self
.
font
=
ImageFont
.
truetype
(
font
,
size
=
f
)
self
.
fh
=
self
.
font
.
getsize
(
'a'
)[
1
]
-
3
# font height
self
.
fh
=
self
.
font
.
getsize
(
'a'
)[
1
]
-
3
# font height
else
:
# use cv2
else
:
# use cv2
self
.
im
=
im
self
.
im
=
im
s
=
sum
(
im
.
shape
)
/
2
# mean shape
self
.
lw
=
line_width
or
max
(
round
(
sum
(
im
.
shape
)
/
2
*
0.003
),
2
)
# line width
self
.
lw
=
line_width
or
max
(
round
(
s
*
0.003
),
2
)
# line width
def
box_label
(
self
,
box
,
label
=
''
,
color
=
(
128
,
128
,
128
),
txt_color
=
(
255
,
255
,
255
)):
def
box_label
(
self
,
box
,
label
=
''
,
color
=
(
128
,
128
,
128
),
txt_color
=
(
255
,
255
,
255
)):
# Add one xyxy box to image with label
# Add one xyxy box to image with label
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论