fix: add default PIL font as fallback (#7010)
* 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>
This commit is contained in:
1 file changed
+4
-1
+4
-1
@@ -7,6 +7,7 @@ import math
|
|||||||
import os
|
import os
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from urllib.error import URLError
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import matplotlib
|
import matplotlib
|
||||||
@@ -55,11 +56,13 @@ def check_pil_font(font=FONT, size=10):
|
|||||||
try:
|
try:
|
||||||
return ImageFont.truetype(str(font) if font.exists() else font.name, size)
|
return ImageFont.truetype(str(font) if font.exists() else font.name, size)
|
||||||
except Exception: # download if missing
|
except Exception: # download if missing
|
||||||
check_font(font)
|
|
||||||
try:
|
try:
|
||||||
|
check_font(font)
|
||||||
return ImageFont.truetype(str(font), size)
|
return ImageFont.truetype(str(font), size)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
check_requirements('Pillow>=8.4.0') # known issue https://github.com/ultralytics/yolov5/issues/5374
|
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:
|
class Annotator:
|
||||||
|
|||||||
Reference in new issue
Block a user