-
Notifications
You must be signed in to change notification settings - Fork 0
/
parkin.py
274 lines (194 loc) · 8.21 KB
/
parkin.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
from tkinter import *
from tkinter import messagebox
from openpyxl import *
import cv2
import pickle
import cvzone
import numpy as np
import os
root = Tk()
root.title("ParkiN")
root.geometry('925x500+300+200')
root.configure(bg='#fff')
root.resizable(False, False)
def book():
vehicleno = user.get()
phoneno = Phone.get()
gmailac = gmail.get()
if vehicleno == '' and phoneno == '' and gmailac == '':
messagebox.showerror("X", 'Please fill the details')
building = Toplevel(root)
building.title('Parkin!')
building.geometry('925x500+300+200')
building.configure(bg='#fff')
building.resizable(False, False)
Label(building, text='Please select Your Parking Space', fg='#57a1f8', bg='white',
font=('Microsoft Yahei UI Light', 20)).grid(row=0, column=0, columnspan=2, padx=285, pady=5)
Parking_A = Button(building, text='Parking A', pady=1, width=10, fg='black', border=0, bg='#FFFFEB',
font=('Microsoft Yahei UI Light', 14,), command=footage)
Parking_A.grid(row=1, column=0, padx=140, pady=10)
park1 = PhotoImage(file='parkingb.png')
park11 = Label(building, image=park1, border=0, bg='white')
park11.grid(row=2, column=0, padx=40, pady=10, sticky=W)
park11.image = park1
Parking_B = Button(building, text='Parking B', pady=1, width=10, fg='black', border=0, bg='#FFFFEB',
font=('Microsoft Yahei UI Light', 14,), command=build2)
Parking_B.grid(row=1, column=1, padx=140, pady=10)
park2 = PhotoImage(file='parkingb.png')
park22 = Label(building, image=park2, border=0, bg='white')
park22.grid(row=2, column=1, padx=40, pady=10, sticky=W)
park22.image = park2
Parking_C = Button(building, text='Parking C', pady=1, width=10, fg='black', border=0, bg='#FFFFEB',
font=('Microsoft Yahei UI Light', 14,), command=build3)
Parking_C.grid(row=3, column=0, padx=140, pady=10)
Parking_D = Button(building, text='Parking D', pady=1, width=10, fg='black', border=0, bg='#FFFFEB',
font=('Microsoft Yahei UI Light', 14,), command=build4)
Parking_D.grid(row=3, column=1, padx=140, pady=10)
img = PhotoImage(file='parking1.png')
Label(root, image=img, border=0, bg='white').place(x=-350, y=-265)
frame = Frame(root, width=400, height=390, bg='#fff')
frame.place(x=450, y=80)
heading = Label(frame, text='Welcome to Parkin!', fg="#57a1f8", bg="white", font=('Microsoft Yahei UI Light', 20,))
heading.place(x=120, y=5)
def insert():
# if user not fill any entry
# then print "empty input"
if (Phone.get() == "" or
user.get() == "" or
gmail.get() == ""):
print("Please fill all details")
else:
# assigning the max row and max column
# value upto which data is written
# in an excel sheet to the variable
current_row = sheet.max_row
current_column = sheet.max_column
# get method returns current text
# as string which we write into
# excel spreadsheet at particular location
sheet.cell(row=current_row + 1, column=1).value = Phone.get()
sheet.cell(row=current_row + 1, column=2).value = user.get()
sheet.cell(row=current_row + 1, column=3).value = gmail.get()
# save the file
wb.save('book1.xlsx')
# set focus on the name_field box
user.focus_set()
# call the clear() function
def footage():
cap = cv2.VideoCapture('carPark.mp4')
file_path = os.path.join('D:', 'Coding', 'C course', '.vscode', 'CarParkingPos')
with open(file_path, 'rb') as f:
posList = pickle.load(f)
width, height = 107, 46
def checkParkingSpace(imgPro):
spaceCounter = 0
for pos in posList:
x, y = pos
imgCrop = imgPro[y:y + height, x:x + width]
# cv2.imshow(str(x*y),imgCrop)
count = cv2.countNonZero(imgCrop) # The number in front of the boxes
if count < 900:
color = (0, 255, 0)
thickness = 5
else:
color = (0, 0, 255)
thickness = 2
cv2.rectangle(img, pos, (pos[0] + width, pos[1] + height), color, 2)
cvzone.putTextRect(img, str(count), (x, y + height - 3), scale=0.8, thickness=1, offset=0)
cvzone.putTextRect(img, str(count), (x, y + height - 3), scale=0.8, thickness=1, offset=0)
while True:
if cap.get(cv2.CAP_PROP_POS_FRAMES) == cap.get(cv2.CAP_PROP_FRAME_COUNT):
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
success, img = cap.read()
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imgBlur = cv2.GaussianBlur(imgGray, (3, 3), 1)
imgThreshold = cv2.adaptiveThreshold(imgBlur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 25,
16)
imgMedian = cv2.medianBlur(imgThreshold, 5)
kernel = np.ones((3, 3), np.uint8)
imgDilate = cv2.dilate(imgMedian, kernel, iterations=1)
checkParkingSpace(imgDilate)
cv2.imshow("Image", img)
cv2.imshow("ImageBlur", imgBlur)
cv2.imshow("ImageThres", imgMedian)
cv2.waitKey(50)
ok = Button(frame, text='Book', pady=1, width=25, fg='white', border=0, bg='#57a1f8',
font=('Microsoft Yahei UI Light', 14), command=lambda: [insert(), book()])
ok.place(x=115, y=250)
def on_enter(e):
user.delete(0, 'end')
def on_leave(e):
if user.get() == '':
user.insert(0, 'Vehicle Number ')
user = Entry(frame, width=25, fg="black", border=0, bg='white', font=('Microsoft Yahei UI Light', 13))
user.place(x=110, y=67)
# This input will be given by the parking coordinator
user.insert(0, 'Vehicle Number')
user.bind("<FocusIn>", on_enter)
user.bind("<FocusOut>", on_leave)
Frame(frame, width=295, height=2, bg='black').place(x=110, y=90)
def on_enter(e):
Phone.delete(0, 'end')
def on_leave(e):
if Phone.get() == '':
Phone.insert(0, 'Phone No.')
Phone = Entry(frame, width=25, fg="black", border=0, bg='white', font=('Microsoft Yahei UI Light', 13))
Phone.place(x=110, y=134)
Phone.insert(0, 'Phone No.')
Phone.bind("<FocusIn>", on_enter)
Phone.bind("<FocusOut>", on_leave)
Frame(frame, width=295, height=2, bg='black').place(x=110, y=160)
def on_enter(e):
gmail.delete(0, 'end')
def on_leave(e):
if gmail.get() == '':
gmail.insert(0, 'Enter your Gmail')
gmail = Entry(frame, width=25, fg="black", border=0, bg='white', font=('Microsoft Yahei UI Light', 13))
gmail.place(x=110, y=200)
gmail.insert(0, 'Enter your Gmail ')
gmail.bind("<FocusIn>", on_enter)
gmail.bind("<FocusOut>", on_leave)
Frame(frame, width=295, height=2, bg='black').place(x=110, y=230)
# For Parking A
def build1():
park_a=Toplevel(root)
park_a.title('Parkin!')
park_a.geometry('925x500+300+200')
park_a.configure(bg='#fff')
park_a.resizable(False,False)
# For Parking B
def build2():
park_b = Toplevel(root)
park_b.title('Parkin!')
park_b.geometry('925x500+300+200')
park_b.configure(bg='#fff')
park_b.resizable(False, False)
# For Parking C
def build3():
park_c = Toplevel(root)
park_c.title('Parkin!')
park_c.geometry('925x500+300+200')
park_c.configure(bg='#fff')
park_c.resizable(False, False)
# For Parking D
def build4():
park_d = Toplevel(root)
park_d.title('Parkin!')
park_d.geometry('925x500+300+200')
park_d.configure(bg='#fff')
park_d.resizable(False, False)
# create the sheet object
wb = load_workbook('book1.xlsx')
sheet = wb.active
def excel():
# resize the width of columns in
# excel spreadsheet
sheet.column_dimensions['A'].width = 20
sheet.column_dimensions['B'].width = 10
sheet.column_dimensions['C'].width = 30
# write given data to an excel spreadsheet
# at particular location
sheet.cell(row=1, column=1).value = "mobile no."
sheet.cell(row=1, column=2).value = "Vehicle No."
sheet.cell(row=1, column=3).value = "e-mail id"
root.mainloop()