首页 > 编程语言 >python opencv绘制矩形框

python opencv绘制矩形框

时间:2023-03-12 20:36:08浏览次数:38  
标签:box draw font img python 矩形框 thickness opencv txt

绘制矩形框

def plot_one_box_PIL4(box,img, fontSize1,color=None, label=None, line_thickness=None):
    img = Image.fromarray(img)
    draw = ImageDraw.Draw(img)
    #line_thickness = line_thickness or max(int(min(img.size) / 200), 2)
    #draw.rectangle(box, width=line_thickness, outline=tuple(color))  # plot
    if label:
        #fontsize = max(round(max(img.size) / 90), 26)
        fontsize = fontSize1
        font = ImageFont.truetype("simhei.ttf", fontsize)
        txt_width, txt_height = font.getsize(label)
        draw.rectangle([box[0], box[1] - txt_height + 4, box[0] + txt_width, box[1]], fill=tuple(color))
        draw.text((box[0], box[1] - txt_height + 1), label, fill=(255, 255, 255), font=font)
    return np.asarray(img)

 

 

 

####################

标签:box,draw,font,img,python,矩形框,thickness,opencv,txt
From: https://www.cnblogs.com/herd/p/17208983.html

相关文章