-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarPark_initialize.py
51 lines (35 loc) · 1.16 KB
/
carPark_initialize.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
# TODO: Remove. Only kept for reference.
import cv2
import pickle
import numpy as np
from pathlib import Path
DATA_DIR = Path(Path().absolute(), "data")
img = cv2.imread(str(Path(DATA_DIR, "parking_img.png")))
width, height = (60, 30)
try:
with open("CarParkPos", "rb") as f:
posList = pickle.load(f)
except:
posList = []
def mouseclick(events, x, y, flags, params):
if events == cv2.EVENT_LBUTTONDOWN:
posList.append((x, y))
if events == cv2.EVENT_RBUTTONDOWN:
for i, pos in enumerate(posList):
x1, y1 = pos
if x1 < x < x1 + width and y1 < y < y1 + height:
posList.pop(i)
with open("CarParkPos", "wb") as f:
pickle.dump(posList, f)
return 0
def checkParkingSpace():
for pos in posList:
cv2.rectangle(img, pos, (pos[0] + width, pos[1] + height), (255, 0, 255), 2)
cv2.namedWindow("image", cv2.WINDOW_GUI_NORMAL)
while True:
img = cv2.imread(str(Path(DATA_DIR, "parking_img.png")))
# cv2.rectangle(img,(100,100),(200,150),(255,0,255),2)
checkParkingSpace()
cv2.imshow("image", img)
cv2.setMouseCallback("image", mouseclick)
cv2.waitKey(1)