-
Notifications
You must be signed in to change notification settings - Fork 21
/
draw_images_shapes.py
102 lines (79 loc) · 3.5 KB
/
draw_images_shapes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 18 15:29:19 2016
@author: Karthick Perumal
"""
import cv2
import numpy as np
#########################################################################################################
### To create an image
#########################################################################################################
"""
## create a black image
image = np.zeros((512, 512, 3), np.uint8)
###we could also make it in black and white
image_bw = np.zeros((512, 512), np.uint8)
cv2.imshow("Black Rectangle (color)", image)
cv2.imshow("Black Rectangle (B&W)", image_bw)
cv2.waitKey(0)
cv2.destroyAllWindows()
"""
#########################################################################################################
### To draw a blue line of thickness of 5 pixels
#########################################################################################################
"""
image = np.zeros((512, 512, 3), np.uint8)
cv2.line(image, (0,0), (511, 511), (255, 127, 0), 5)
cv2.imshow("Blue Line", image)
cv2.waitKey()
cv2.destroyAllWindows()
"""
#########################################################################################################
### To draw a rectangle in the image
### cv2.rectangle(image, starting vertex, opposite vertex, color, thickness)
#########################################################################################################
"""
image = np.zeros((512, 512, 3), np.uint8)
cv2.rectangle(image, (100, 100), (300, 250), (127, 50, 127), 5) ## if instead of pixel size 5, if we use -1, it will fill the rectangle with that colour
cv2.imshow("Rectangle", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
"""
#########################################################################################################
### To draw a circle in the image
### cv2.circle(image, center, radius, color, fill)
#########################################################################################################
"""
image = np.zeros((512, 512, 3), np.uint8)
cv2.circle(image, (256, 256), 100, (15, 75, 50), -1)
cv2.imshow("Circle", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
"""
#########################################################################################################
### To draw a polygon in the image
### cv2.circle(image, center, radius, color, fill)
#########################################################################################################
"""
image = np.zeros((512, 512, 3), np.uint8)
## define the four point or the edges of the polygon
pts = np.array([[10, 50], [100, 50], [90, 200], [50, 300]], np.int32)
#print(pts)
### Let's reshape our points in form required by polylines/polygons
pts = pts.reshape((-1, 1, 2))
#print(pts)
cv2.polylines(image, [pts], True, (0, 0, 255), 3) ## True if we want the polygon closed or not
cv2.imshow("Polygon", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
"""
#########################################################################################################
### To add text
### cv2.putText(image, 'Text to Display', bottom left starting point, Font, Font size, Color, Thickness)
#########################################################################################################
image = np.zeros((512, 512, 3), np.uint8)
cv2.putText(image, "Hello World", (50, 260), cv2.FONT_HERSHEY_COMPLEX, 2, (250, 10, 0), 3)
cv2.imshow("Hello Karthick", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.waitKey(1)