March 2019
Intermediate to advanced
532 pages
13h 2m
English
The signature for this function is as follows:
cv2.polylines(img, pts, isClosed, color, thickness=1, lineType=8, shift=0)
This function allows you to create polygonal curves. Here the key parameter is pts, where the array defining the polygonal curve should be provided. The shape of this parameter should be (number_vertex, 1, 2). So a common approach is to define it by using np.array to create the coordinates (of the np.int32 type) and, afterward, reshape it to match the aforementioned shape. For example, to create a triangle, the code will look like this:
# These points define a trianglepts = np.array([[250, 5], [220, 80], [280, 80]], np.int32)# Reshape to shape (number_vertex, 1, 2)pts = pts.reshape((-1, 1, 2))# Print the ...