OpenCV Draw figure

Ref: https://docs.opencv.org/master/

Common options

  • @param img: np.ndarray
  • @param color: tuple (B, G, R)
  • @param thickness: int -1 ์ธ ๊ฒฝ์šฐ ๋„ํ˜• ๋‚ด๋ถ€๋ฅผ ์ฑ„์›€
  • @param lineType
    • cv.FILLED
    • cv.LINE_4
    • cv.LINE_8
    • cv.LINE_AA
  • @param shift: int ๋ชจ๋“  ์ขŒํ‘œ๋ฅผ (x, y) -> (xยท2^(-shift), yยท2^(-shift))๋กœ ๋ณ€ํ™˜

Line

img = cv.arrowedLine(img, pt1, pt2, color, thickness=1, line_type=cv.LINE_8, shift=0, tipLength=0.1)
img = cv.line(img, pt1, pt2, color, thickness=1, lineType=cv.LINE_8, shift=0)
  • @param pt1, pt2: tuple (x, y) start, end

Rectangle

img = cv.rectangle(img, pt1, pt2, color, thickness=1, lineType=cv.LINE_8, shift=0)
  • @param pt1, pt2: tuple (x, y) top-left, bottom-right

Polygone

img = cv.polylines(img, pts, isClosed, color, thickness=1, lineType=cv.LINE_8, shift=0)
img = cv.fillPoly(img, pts, color, lineType=cv.LINE_8, shift=0, offset=(0,0))
  • @param pts: list [np.ndarray([[],], dtype=np.int32),] ๊ผญ์ง€์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ 2์ฐจ์› ๋ฐฐ์—ด๋“ค์˜ ๋ฆฌ์ŠคํŠธ, ๋ฐฐ์—ด ์ˆ˜๋งŒํผ ๋„ํ˜• ์ƒ์„ฑ
  • @param isClosed: bool True : ์‹œ์ž‘์ ๊ณผ ๋์  ์—ฐ๊ฒฐ, False : ์‹œ์ž‘์ ๊ณผ ๋์  ์—ฐ๊ฒฐ ์•ˆํ•จ
  • @param offset: tuple (x, y)

Ellipse

img = cv.circle(img, center, radius, color, thickness=1, lineType=cv.LINE_8, shift=0)
img = cv.ellipse(img, center, axes, angle, startAngle, endAngle, color, thickness=1, lineType=cv.LINE_8, shift=0)
img = cv.ellipse(img, box, color, thickness=1, lineType=cv.LINE_8)
pts = cv.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta)
  • @param center
  • @param radius
  • @param axes
  • @param angle
  • @param startAngle
  • @param endAngle
  • @param box
  • @param delta

Marker

img = cv.drawMarker(img, position, color, markerType=cv.MARKER_CROSS, markerSize=20, thickness=1, line_type=cv.LINE_8)
  • @param position: tuple (x, y)
  • @param markerType
    • cv.MARKER_CROSS
    • cv.MARKER_TILTED_CROSS
    • cv.MARKER_STAR
    • cv.MARKER_DIAMOND
    • cv.MARKER_SQUARE
    • cv.MARKER_TRIANGLE_UP
    • cv.MARKER_TRIANGLE_DOWN

Text

img = cv.putText(img, text, org, fontFace, fontScale, color, thickness=1, lineType=cv.LINE_8, bottomLeftOrigin=False)
  • @param text: string
  • @param org: tuple ํ…์ŠคํŠธ ์œ„์น˜
  • @param fontFace
    • cv.FONT_HERSHEY_SIMPLEX
    • cv.FONT_HERSHEY_PLAIN
    • cv.FONT_HERSHEY_DUPLEX
    • cv.FONT_HERSHEY_COMPLEX
    • cv.FONT_HERSHEY_TRIPLEX
    • cv.FONT_HERSHEY_COMPLEX_SMALL
    • cv.FONT_HERSHEY_SCRIPT_SIMPLEX
    • cv.FONT_HERSHEY_SCRIPT_COMPLEX
    • cv.FONT_ITALIC
  • @param fontScale: float ๊ธฐ๋ณธ ํฌ๊ธฐ์— ๊ณฑํ•  ๋ฐฐ์œจ
  • @param bottomLeftOrigin: bool True : bottom-left, False : top-left
Last updated on