Skip to content

Commit

Permalink
fix: add default PIL font as fallback (ultralytics#7010)
Browse files Browse the repository at this point in the history
* fix: add default font as fallback

Add default font as fallback if the downloading of the Arial.ttf font
fails for some reason, e.g. no access to public internet.

* Update plots.py

Co-authored-by: Maximilian Strobel <Maximilian.Strobel@infineon.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
3 people authored Mar 17, 2022
1 parent 35fe1f0 commit 4b81e09
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion utils/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
from copy import copy
from pathlib import Path
from urllib.error import URLError

import cv2
import matplotlib
Expand Down Expand Up @@ -55,11 +56,13 @@ def check_pil_font(font=FONT, size=10):
try:
return ImageFont.truetype(str(font) if font.exists() else font.name, size)
except Exception: # download if missing
check_font(font)
try:
check_font(font)
return ImageFont.truetype(str(font), size)
except TypeError:
check_requirements('Pillow>=8.4.0') # known issue https://github.com/ultralytics/yolov5/issues/5374
except URLError: # not online
return ImageFont.load_default()


class Annotator:
Expand Down

0 comments on commit 4b81e09

Please sign in to comment.