如何修改visualization_utils.py以显示中文的class_name

问题描述

在visualize_Boxes_and_labels_on_image_array函数中:

       class_name = category_index[classes[i]]['name']
          if(class_name == 'a'):
                class_name = '我我我我'

在draw_bounding_Box_on_image函数中:

try:
    font = ImageFont.truetype('Arial.ttf',40)
  except IOError:
    font = ImageFont.load_default()

  # If the total height of the display strings added to the top of the bounding
  # Box exceeds the top of the image,stack the strings below the bounding Box
  # instead of above.
  display_str_heights = [font.getsize(ds)[1] for ds in display_str_list]
  # Each display_str has a top and bottom margin of 0.05x.
  total_display_str_height = (1 + 2 * 0.05) * sum(display_str_heights)

  if top > total_display_str_height:
    text_bottom = top
  else:
    text_bottom = bottom + total_display_str_height
  # Reverse list and print from bottom to top.
  for display_str in display_str_list[::-1]:
    text_width,text_height = font.getsize(display_str)
    margin = np.ceil(0.05 * text_height)
    draw.rectangle(
        [(left,text_bottom - text_height - 2 * margin),(left + text_width,text_bottom)],fill=color)
    draw.text(
        (left + margin,text_bottom - text_height - margin),display_str,fill='black',font=font)
    text_bottom -= text_height - 2 * margin

但是class_name将显示this

如何保存此问题?

谢谢

解决方法

我在上面的尝试中保存了使用MSfont.ttf ...