Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
e7d1842a
Unverified
提交
e7d1842a
authored
8月 30, 2021
作者:
Glenn Jocher
提交者:
GitHub
8月 30, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto-download Arial.ttf on init (#4606)
* Auto-download Arial.ttf on init * Fix ROOT
上级
bb4da083
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
5 行删除
+20
-5
__init__.py
utils/__init__.py
+16
-0
plots.py
utils/plots.py
+4
-5
没有找到文件。
utils/__init__.py
浏览文件 @
e7d1842a
from
pathlib
import
Path
import
torch
from
PIL
import
ImageFont
FILE
=
Path
(
__file__
)
.
absolute
()
ROOT
=
FILE
.
parents
[
1
]
# yolov5/ dir
# Check YOLOv5 Annotator font
font
=
'Arial.ttf'
try
:
ImageFont
.
truetype
(
font
)
except
Exception
as
e
:
# download if missing
url
=
"https://ultralytics.com/assets/"
+
font
print
(
f
'Downloading {url} to {ROOT / font}...'
)
torch
.
hub
.
download_url_to_file
(
url
,
str
(
ROOT
/
font
))
utils/plots.py
浏览文件 @
e7d1842a
...
...
@@ -48,7 +48,7 @@ colors = Colors() # create instance for 'from utils.plots import colors'
class
Annotator
:
# 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
):
assert
im
.
data
.
contiguous
,
'Image not contiguous. Apply np.ascontiguousarray(im) to
plot_on_box() input image
.'
assert
im
.
data
.
contiguous
,
'Image not contiguous. Apply np.ascontiguousarray(im) to
Annotator() input images
.'
self
.
pil
=
pil
if
self
.
pil
:
# use PIL
self
.
im
=
im
if
isinstance
(
im
,
Image
.
Image
)
else
Image
.
fromarray
(
im
)
...
...
@@ -57,11 +57,10 @@ class Annotator:
f
=
font_size
or
max
(
round
(
s
*
0.035
),
12
)
try
:
self
.
font
=
ImageFont
.
truetype
(
font
,
size
=
f
)
except
Exception
as
e
:
# download
TTF
if missing
print
(
f
'WARNING: Annotator font {font} not found: {e}'
)
url
=
"https://github.com/ultralytics/yolov5/releases/download/v1.0/"
+
font
except
Exception
as
e
:
# download if missing
url
=
"https://ultralytics.com/assets/"
+
font
print
(
f
'Downloading {url} to {font}...'
)
torch
.
hub
.
download_url_to_file
(
url
,
font
)
print
(
f
'Annotator font successfully downloaded from {url} to {font}'
)
self
.
font
=
ImageFont
.
truetype
(
font
,
size
=
f
)
self
.
fh
=
self
.
font
.
getsize
(
'a'
)[
1
]
-
3
# font height
else
:
# use cv2
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论