-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcorrect_camera_timer.py
155 lines (59 loc) · 2.16 KB
/
correct_camera_timer.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
import cv2
import time
# SET THE COUNTDOWN TIMER
TIMER = int(5)
# Open the camera
cap = cv2.VideoCapture(0)
while True:
# Read and display each frame
ret, img = cap.read()
img1=cv2.flip(img,1)
cv2.imshow('camera', img1)
# check for the key pressed
k = cv2.waitKey(125)
# set the key for the countdown
# to begin. Here we set c
if k == ord('c'):
prev = time.time()
while TIMER >= 0:
ret, img = cap.read()
img1=cv2.flip(img,1)
# Display countdown on each frame
# specify the font and draw the
# countdown using puttext
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img1, str(TIMER),
(200, 250), font,
7, (0, 255, 255),
4, cv2.LINE_AA)
cv2.imshow('camera', img1)
cv2.waitKey(125)
# current time
cur = time.time()
# Update and keep track of Countdown
# if time elapsed is one second
# than decrese the counter
if cur-prev >= 1:
prev = cur
TIMER = TIMER-1
else:
ret, img = cap.read()
img1=cv2.flip(img,1)
# Display the clicked frame for 2
# sec.You can increase time in
# waitKey also
cv2.imshow('camera', img1)
# time for which image displayed
cv2.waitKey(2000)
# Save the frame
cv2.imwrite('camera.jpg', img1)
# HERE we can reset the Countdown timer
# if we want more Capture without closing
# the camera
# Press Esc to exit
elif k == 27:
break
# close the camera
cap.release()
# close all the opened windows
cv2.destroyAllWindows()