python opencv绘制矩形框
绘制矩形框
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)
####################
QQ 3087438119