5、Rectangle and circle drawing

  1. Drawing of rectangle

rectangle (img, pt1, pt2, color, thickness=None, lineType=None, shift=None)

Parameter Description:

l img: canvas or carrier image.

l pt1, pt2: required parameters. The vertices of the rectangle represent the vertex and the diagonal vertex respectively, that is, the upper left corner and the lower right corner of the rectangle (these two vertices can determine a unique rectangle)

l color: required parameter. Used to set the color of the rectangle

l thickness: optional parameter. Used to set the width of the rectangular side. When the value is a negative number, it means filling the rectangle.

l lineType: optional parameter. Used to set the type of line segment, optional 8 (8 adjacent connecting lines - default), 4 (4 adjacent connecting lines) and cv2.LINE_AA is anti-aliasing

  1. Drawing of circles

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

Parameter Description:

l img: canvas or carrier image

l center: is the coordinate of the center of the circle, format: (50,50)

l radius: radius

l color: color

l thickness: line thickness. Defaults to 1. If -1, fill solid.

l lineType: line type. The default is 8, connection type. The following table explains

ParametersDescription
cv2.FILLEDfill
cv2.LINE_44 connection types
cv2.LINE_88 connection type
cv2.LINE_AAAnti-aliasing, this parameter will make the lines smoother
  1. Draw an ellipse

cv2.ellipse(img, center, axes, angle, StartAngle, endAngle, color[,thickness[,lineType]])

l center: center point of the ellipse, (x, x)

l axes: refers to the short radius and long radius, (x, x)

l angle: refers to the angle of counterclockwise rotation

l StartAngle: The angle of the starting angle of the arc

l endAngle: the angle of the arc’s end angle

l img and color can refer to the description of the circle.

# The fifth parameter refers to the angle at which the drawing starts counterclockwise, and the sixth parameter refers to the angle at which the drawing ends counterclockwise.

# If the 456 parameter is added with a sign, it represents the opposite direction, that is, clockwise.

  1. Draw polygons

cv2.polylines(img,[pts],isClosed, color[,thickness[,lineType]])

l pts: vertices of polygon

l isClosed: Whether it is closed. (True/False)

l Other parameters refer to the drawing parameters of the circle.

The code was run on jupyterlab