Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add default PIL font as fallback #7010

Merged
merged 3 commits into from
Mar 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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