opencv puttext 文本框填充颜色


def drawtext(image,pt1,pt2,text):

    fontFace = cv.FONT_HERSHEY_COMPLEX_SMALL
    fontScale = 1
    thickness = 1
    # 绘制矩形框
    hei=(255, 255, 255)
    bai=(0,0,0)
    cv.rectangle(image, pt1, pt2, thickness=2, color=hei)
    # 计算文本的宽高,baseLine
    retval, baseLine = cv.getTextSize(text,fontFace=fontFace,fontScale=fontScale, thickness=thickness)
    # 计算覆盖文本的矩形框坐标
    topleft = (pt1[0], pt1[1] - retval[1]-5)
    bottomright = (topleft[0] + retval[0], topleft[1] + retval[1]+5)
    cv.rectangle(image, (topleft[0], topleft[1] - baseLine), bottomright,thickness=-1, color=hei)
    # 绘制文本
    cv.putText(image, text, (pt1[0], pt1[1]-baseLine), fontScale=fontScale,fontFace=fontFace, thickness=thickness, color=bai)

你可能感兴趣的:(机器学习+数学,学习工具及问题记录,opencv,计算机视觉,css)