美文网首页
python opencv基本使用1:标注矩形框bounding

python opencv基本使用1:标注矩形框bounding

作者: MiracleJQ | 来源:发表于2019-06-10 11:37 被阅读0次

    1. 函数

    用 OpenCV 标注 bounding box 主要用到下面两个工具——cv2.rectangle() 和 cv2.putText()。用法如下

    # cv2.rectangle()
    # 输入参数分别为图像、左上角坐标、右下角坐标、颜色数组、粗细
    cv2.rectangle(img, (x,y), (x+w,y+h), (B,G,R), Thickness)
    
    # cv2.putText()
    # 输入参数为图像、文本、位置、字体、大小、颜色数组、粗细
    cv2.putText(img, text, (x,y), Font, Size, (B,G,R), Thickness)
    

    2. Example

    import cv2
    
    fname = '001.jpg'
    img = cv2.imread(fname)
    # 画矩形框
    cv2.rectangle(img, (212,317), (290,436), (0,255,0), 4)
    # 标注文本
    font = cv2.FONT_HERSHEY_SUPLEX
    text = '001'
    cv2.putText(img, text, (212, 310), font, 2, (0,0,255), 1)
    cv2.imwrite('001_new.jpg', img)
    

    相关文章

      网友评论

          本文标题:python opencv基本使用1:标注矩形框bounding

          本文链接:https://www.haomeiwen.com/subject/rmoaxctx.html