ubuntu yolov5中文标签显示 OSError: cannot open resource

ubuntu OSError: cannot open resource

报错信息

ubuntu OSError: cannot open resource

fontText = ImageFont.truetype("simsun.ttc", textSize, 
encoding="utf-8")


  File "/project/ai/yolov5_detection/utils/plots.py", line 70, in plot_one_box
    im = cv2ImgAddText(im, label, c1[0], (c1[1] - 23), (255, 255, 255), 25)
  File "/project/ai/yolov5_detection/utils/plots.py", line 444, in cv2ImgAddText
    "simsun.ttc", textSize, encoding="utf-8")
  File "/root/anaconda3/envs/yolov5_detection/lib/python3.7/site-packages/PIL/ImageFont.py", line 853, in truetype
    return freetype(font)
  File "/root/anaconda3/envs/yolov5_detection/lib/python3.7/site-packages/PIL/ImageFont.py", line 850, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/root/anaconda3/envs/yolov5_detection/lib/python3.7/site-packages/PIL/ImageFont.py", line 210, in __init__
    font, size, index, encoding, layout_engine=layout_engine
OSError: cannot open resource

解决办法

cp simsun.ttc /usr/share/fonts/truetype/dejavu

将需要用到字体复制到ubuntu系统字体目录下

欢迎大家交流学习,任何问题都可以留言

你可能感兴趣的:(日常报错,python,ubuntu,yolov5,中文标签,目标检测)