-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathutil.py
46 lines (29 loc) · 961 Bytes
/
util.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
import pickle
from skimage.transform import resize
import numpy as np
import cv2
EMPTY = True
NOT_EMPTY = False
MODEL = pickle.load(open("model.p", "rb"))
def empty_or_not(spot_bgr):
flat_data = []
img_resized = resize(spot_bgr, (15, 15, 3))
flat_data.append(img_resized.flatten())
flat_data = np.array(flat_data)
y_output = MODEL.predict(flat_data)
if y_output == 0:
return EMPTY
else:
return NOT_EMPTY
def get_parking_spots_bboxes(connected_components):
(totalLabels, label_ids, values, centroid) = connected_components
slots = []
coef = 1
for i in range(1, totalLabels):
# Now extract the coordinate points
x1 = int(values[i, cv2.CC_STAT_LEFT] * coef)
y1 = int(values[i, cv2.CC_STAT_TOP] * coef)
w = int(values[i, cv2.CC_STAT_WIDTH] * coef)
h = int(values[i, cv2.CC_STAT_HEIGHT] * coef)
slots.append([x1, y1, w, h])
return slots