zoukankan      html  css  js  c++  java
  • opencv-python-学习笔记二(利用opencv绘图)

    常见参数:

    color:颜色(255,255,0),BGR表示

    thickness:线宽px,-1代表填充

    linetype:圆边界类型。cv.LINE_4,cv.LINE_8,cv.LINE_AA,AA代表抗锯齿线

    shift:图形缩小倍数

    线

    常见函数:

    cv.arrowedLine()  箭头线

    cv.arrowedLine(img, pt1, pt2, color[, thickness[, line_type[, shift[, tipLength]]]])

    pt1:箭头起点(x,y)

    pt2:箭头终点(x,y)

    tipLength:

    import numpy as np
    import cv2 as cv
    # Create a black image
    img = np.zeros((512, 512, 3), np.uint8)
    cv.arrowedLine(img, (0, 0), (255, 255), (255, 255, 255))
    # cv.WINDOW_AUTOSIZE  cv.WINDOW_NORMAL
    cv.namedWindow('circle', cv.WINDOW_NORMAL)
    # 显示图像
    cv.imshow('circle', img)
    cv.waitKey(0)
    cv.destroyAllWindows()

    cv.line() 直线

    cv.line(img, pt1, pt2, color[, thickness[, lineType[, shift]]])

    pt1:起点(x,y)

    pt2:终点(x,y)

    import numpy as np
    import cv2 as cv
    # Create a black image
    img = np.zeros((512, 512, 3), np.uint8)

    cv.line(img, (255, 255), (274, 274), (240, 240, 240), 10) # cv.WINDOW_AUTOSIZE cv.WINDOW_NORMAL cv.namedWindow('circle', cv.WINDOW_NORMAL) # 显示图像 cv.imshow('circle', img) cv.waitKey(0) cv.destroyAllWindows()

    常见函数:

    cv.circle()  圆

    cv.circle(img, center, radius, color[, thickness[, lineType[, shift]]])

    img:

    center:圆心(x,y)

    radius:半径 int

    import numpy as np
    import cv2 as cv
    # Create a black image
    img = np.zeros((512, 512, 3), np.uint8)
    cv.circle(img, (447, 63), 63, (255, 255, 255), -1)
    # cv.WINDOW_AUTOSIZE  cv.WINDOW_NORMAL
    cv.namedWindow('circle', cv.WINDOW_NORMAL)
    # 显示图像
    cv.imshow('circle', img)
    cv.waitKey(0)
    cv.destroyAllWindows()

     

    矩形

    常见函数

    cv.rectangle

    cv.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]])

    pt1:对角,左上点

    pt2:对角,右下点

    import numpy as np
    import cv2 as cv
    # Create a black image
    img = np.zeros((512, 512, 3), np.uint8)
    cv.rectangle(img, ((10, 10), (40, 40)), (255, 255, 255))
    # cv.WINDOW_AUTOSIZE  cv.WINDOW_NORMAL
    cv.namedWindow('circle')
    # 显示图像
    cv.imshow('circle', img)
    cv.waitKey(0)
    cv.destroyAllWindows()

    其它

    常见函数

    cv.drawMarker() 在指定点出标记

    cv.drawMarker(img, position, color[, markerType[, markerSize[, thickness[, line_type]]]])

    position:点位置 (x,y)

    markerType:标记类型

    import numpy as np
    import cv2 as cv
    # Create a black image
    img = np.zeros((512, 512, 3), np.uint8)
    cv.drawMarker(img, (260, 260), (255, 255, 255)
    # cv.WINDOW_AUTOSIZE cv.WINDOW_NORMAL
    cv.namedWindow('circle')
    # 显示图像
    cv.imshow('circle', img)
    cv.waitKey(0)
    cv.destroyAllWindows()

     

    cv.putText() 绘制文本字符串

    cv.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])

    org:位置

    text:字符串内容

    fontFace:

      

     cv.FONT_HERSHEY_SIMPLEX

    normal size sans-serif font

    cv.FONT_HERSHEY_PLAIN

    small size sans-serif font

    cv.FONT_HERSHEY_DUPLEX

    normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX)

    cv.FONT_HERSHEY_COMPLEX

    normal size serif font

    cv.FONT_HERSHEY_TRIPLEX

    normal size serif font (more complex than FONT_HERSHEY_COMPLEX)

     cv.FONT_HERSHEY_COMPLEX_SMALL

    smaller version of FONT_HERSHEY_COMPLEX

    cv.FONT_HERSHEY_SCRIPT_SIMPLEX

    hand-writing style font

    cv.FONT_HERSHEY_SCRIPT_COMPLEX

    more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX

     cv.FONT_ITALIC

    flag for italic font

    fontScale:字体缩放倍数

    bottomLeftOrigin:true:。false:反转。

    import numpy as np
    import cv2 as cv
    # Create a black image
    img = np.zeros((512, 512, 3), np.uint8)
    # cv.circle(img, (447, 63), 63, (255, 255, 255), -1)
    # cv.arrowedLine(img, (0, 0), (255, 255), (255, 255, 255))
    # cv.drawMarker(img, (260, 260), (255, 255, 255)    )
    # cv.line(img, (255, 255), (274, 274), (240, 240, 240), 10)
    cv.putText(    img, "opencv", (200, 200), cv.FONT_HERSHEY_PLAIN, 1, (255, 255, 255))
    
    # cv.WINDOW_AUTOSIZE  cv.WINDOW_NORMAL
    cv.namedWindow('circle')
    # 显示图像
    cv.imshow('circle', img)
    cv.waitKey(0)
    cv.destroyAllWindows()

  • 相关阅读:
    Java开发中的23种设计模式详解
    Zookeeper基本知识
    Zookeeper命令
    ZooKeeper原理及使用
    几种java通信(rmi,http,hessian,webservice)协议性能比较
    linux 查看系统信息命令
    Zookeeper安装和配置
    Hive 接口介绍(Web UI/JDBC)
    窗口标志-外观
    pyqt5-QWidget-窗口状态(最大化最小化等)
  • 原文地址:https://www.cnblogs.com/blog-xyy/p/11142435.html
Copyright © 2011-2022 走看看