当前位置:   article > 正文

yolo v5显示中文标签乱码解决_yolo检测标签乱码与只显示编号

yolo检测标签乱码与只显示编号

1.在general.py,导入

from PIL import Image, ImageDraw, ImageFont

2.找到plot_one_labels

把 if label改为以下

  1. tf = max(tl - 1, 1) # font thickness
  2. t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0]
  3. font_size = t_size[1]
  4. font = ImageFont.truetype('msyh.ttc', font_size)
  5. t_size = font.getsize(label)
  6. c2 = c1[0] + t_size[0], c1[1] - t_size[1]
  7. cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA) # filled
  8. img_PIL = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
  9. draw = ImageDraw.Draw(img_PIL)
  10. draw.text((c1[0], c2[1] - 2), label, fill=(255, 255, 255), font=font)
  11. return cv2.cvtColor(np.array(img_PIL), cv2.COLOR_RGB2BGR)

3.找到plot_images

plot_one_box(box, mosaic, label=label, color=color, line_thickness=tl)

改为

mosaic = plot_one_box(box, mosaic, label=label, color=color, line_thickness=tl)

4.在detect.py中

plot_one_box(xyxy, im0, label=label, color=colors(c, True), line_thickness=3)

改为

im0 = plot_one_box(xyxy, im0, label=label, color=colors(c, True), line_thickness=3)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/797411
推荐阅读
  

闽ICP备14008679号