Now let’s use our wrapper functions to draw a complicated image, not exactly same but similar to the OpenCV Icon, like Figure shown below.
A light-gray colored empty canvas of size 360 x 320 is created, same as above. cv2.ellipse() function will be used to draw the three non-closed circles, a start angle and an end angle can be specified for the ellipse.
cv2.putText() function will be used to draw the texts at the bottom. Below are the code snippets, the axes of the ellipse are defined as (50, 50) so it appears as a circle instead of an ellipse. The center of the three circles and start and end angles of each are defined based on the position of the OpenCV-like icon.
1 def draw_opencv_icon(image):
2 axes = (50, 50)
3 center_top_circle = (160, 70)
4 center_lowerleft_circle = ( center_top_circle[0]-80,
5 center_top_circle[1]+120 )
6 center_lowerright_circle = (center_top_circle[0]+80,
7 center_top_circle[1]+120 )
8 angle_top_circle = 90
9 angle_lowerleft_circle = -45
10 angle_lowerright_circle = -90
11 start_angle = 40
12 end_angle = 320
13 draw_ellipse(image,center_top_circle, axes,
14 angle_top_circle, start_angle, end_angle,
15 color=(0, 0, 255),
16 thickness=40)
17 draw_ellipse(image, center_lowerleft_circle, axes,
18 angle_lowerleft_circle, start_angle, end_angle,
19 color=(0, 255, 0),
20 thickness=40)
21 draw_ellipse(image,center_lowerright_circle,axes,
22 angle_lowerright_circle, start_angle, end_angle,
23 color=(255, 0, 0),
24 thickness=40)
25 draw_text(image, "OpenCV", (10,330), color=(0,0,0),
26 font_scale=2.4, thickness=5)
27
28 if __name__ == '__main__':
29 canvas = np.zeros((360,320,3), np.uint8)
30 canvas[:] = 235,235,235
31 draw_opencv_icon(canvas)
32 cv2.imshow("Canvas", canvas)
33 cv2.waitKey(0)
34 cv2.destroyAllWindows()
Execute the code, the result is shown in Figure at the beginning of the post.
0 comments:
Post a Comment