Sunday, September 3, 2023

OpenCV basics continued...Draw Rectangles, Circles, Ellipses and Polylines Similarly draw

Similarly draw other shapes, now begin with defining our wrapper functions for drawing shapes, like the above draw_line() function.

1 def draw_rectangle(image, top_left, bottom_right,

2 color=(255,255,255),

3 thickness=1,

4 line_type=cv2.LINE_AA):

5 cv2.rectangle(image, top_left, bottom_right,

6 color, thickness, line_type)

7

8 def draw_circle(image, center, radius,

9 color=(255,255,255),

10 thickness=1,

11 line_type=cv2.LINE_AA):

12 cv2.circle(image, center, radius, color, thickness, line_type)

13 

14 def draw_ellipse(image, center, axes, angle, start_angle, end_angle,

15 color=(255,255,255),

16 thickness=1,

17 line_type=cv2.LINE_AA):

18 cv2.ellipse(image, center, axes, angle, start_angle, end_angle,

19 color, thickness, line_type)

20

21 def draw_polylines(image, points,

is_closed=True,

22 color=(255,255,255),

23 thickness=1,

24 line_type=cv2.LINE_AA ):

25 cv2.polylines(image, points, is_closed,

26 color, thickness, line_type)

The results look like Figure shown below-



Share:

0 comments:

Post a Comment