-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic1.py
164 lines (138 loc) · 3.95 KB
/
basic1.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import numpy as np
import cv2
###########
# Loading an image
############
img_path = "./imgs/cat_img_2.jpg"
cv_img = cv2.imread(img_path)
#Displaying an image
#cv2.imshow('Simple cat image',cv_img)
# Wait for an input to close the window
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#############
# Saving an image
#############
safe_path_dir = "./created_data/"
filename = "saved_img.jpg"
cv2.imwrite(safe_path_dir + filename, cv_img)
print("Image was succesfully saved")
#Get the property of an image
print(cv_img.shape)
#########
# Changel color scheme
#########
gray_img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2GRAY)
#cv2.imshow('Gray scale image', gray_img)
#cv2.imshow('Original Image', cv_img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#############
# Change size of an image
############
resized_img = cv2.resize(cv_img,(400,400))
#############
# Displaying text on an img
############
img_with_text = cv2.putText(resized_img, "My Cat", (0, 200), cv2.FONT_HERSHEY_COMPLEX,1, (255, 0,0), 2)
###########
# Draw a line on a image
############
start_point = (0,0)
end_point = (400,200)
color = (0,255,0)
thickness = 4
img_with_line = cv2.line(resized_img, start_point, end_point, color, thickness)
# cv2.imshow('Resized_img with line', img_with_line)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
##############
# Draw a circle on an image
##############
center_point = (200,200)
radius = 50
color = (0,255,0)
thickness = 4
img_with_circle = cv2.circle(resized_img, center_point, radius, color, thickness)
# cv2.imshow('Resized_img with a circle', img_with_circle)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
##############
# Draw a rectangle on an image
##############
pt1 = (100,100)
pt2 = (150,250)
color = (0,255,0)
thickness = 4
img_with_rectangle = cv2.rectangle(resized_img,pt1, pt2, color, thickness)
# cv2.imshow('Resized_img with a rectangel', img_with_rectangle)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
################
# Draw an ellipse on the image
################
center_point = (300,300)
main_axis_size = (int(100/2), int(50/2))
rot_angle_dgr = 0
start_angle = 0
end_angle = 360
color = (0,255,0)
thickness = -1 # Fill the ellipses
# img_with_ellipse = cv2.ellipse(resized_img,center_point, main_axis_size, rot_angle_dgr, start_angle, end_angle, color, thickness)
# cv2.imshow('Resized_img with ellipse', img_with_ellipse)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#######
#Display the image in multiple mode (other option)
#######
cv_img_mode = cv2.imread(img_path, 0) # Greyscale
#Displaying an image
#cv2.imshow('Simple cat image',cv_img_mode)
# Wait for an input to close the window
# cv2.waitKey(0)
# cv2.destroyAllWindows()
########
# Videocamera
########
####
# Start the camera
######
# cap = cv2.VideoCapture(0) # Will initiate the webcam
# # while(True): # Start a loop to get every fram
# # ret, frame = cap.read()
# # cv2.imshow("Video Capture", frame)
# # if cv2.waitKey(1) & 0xFF == ord('q'):
# # cap.release()
# # break
# # cv2.destroyAllWindows()
# # Check if the video works
# if (cap.isOpened() == False):
# print("Camera could not be found")
# frame_width = int(cap.get(3))
# frame_height = int(cap.get(4))
# # video coded .... encoder and decoders
# video_cod = cv2.VideoWriter_fourcc(*'XVID')
# video_output = cv2.VideoWriter('Captured_video.mp4', video_cod, 30, (frame_width, frame_height))
# while(True): # Start a loop to get every fram
# ret, frame = cap.read()
# if ret == False:
# cap.release()
# break
# video_output.write(frame)
# cv2.imshow("Video Capture", frame)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# cap.release()
# break
# cv2.destroyAllWindows()
# print("The video was saved")
####
# Play a saved video
######
cap = cv2.VideoCapture('Captured_video.mp4')
while(True): # Start a loop to get every fram
ret, frame = cap.read()
cv2.imshow("Video Capture", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
cap.release()
break
cv2.destroyAllWindows()