detect_tool.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:z1 作者: hustzxd 项目源码 文件源码
def draw_image(pic_name, boxes, namelist_file):
    name_list = get_names_from_file(namelist_file)
    color_list = get_color_from_file('ink.color')
    im = Image.open(pic_name)
    draw = ImageDraw.Draw(im)
    lena = mpimg.imread(pic_name)
    height, width = lena.shape[:2]
    for box in boxes:
        x = box.rect.corner.x
        y = box.rect.corner.y
        w = box.rect.width
        h = box.rect.height
        left = (x - w / 2) * width
        right = (x + w / 2) * width
        top = (y - h / 2) * height
        bot = (y + h / 2) * height
        if left < 0:
            left = 0
        if right > width - 1:
            right = width - 1
        if top < 0:
            top = 0
        if bot > height - 1:
            bot = height - 1
        category = name_list[box.category]
        color = color_list[box.category % color_list.__len__()]
        draw.line((left, top, right, top), fill=color, width=5)
        draw.line((right, top, right, bot), fill=color, width=5)
        draw.line((left, top, left, bot), fill=color, width=5)
        draw.line((left, bot, right, bot), fill=color, width=5)
        font_size = 20
        my_font = ImageFont.truetype("/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-M.ttf", size=font_size)
        draw.text([left + 5, top], category, font=my_font, fill=color)
    im.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号