Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update parking_space_picker.py #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions parking_space_picker.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
import cv2 #till 24 min
import pickle

width,height=107,48
import cv2

width, height = 107, 48

try:
with open('CarParkPos','rb') as f:
posList=pickle.loads(f)
with open('CarParkPos', 'rb') as f:
posList = pickle.load(f)
except:
posList= []

path="Assets/carParkImg.png"
# print(img.shape)

#get mouse click
def mouseClick(events,x,y,flags,params):
if events==cv2.EVENT_LBUTTONDOWN:
posList.append((x,y))
if events==cv2.EVENT_RBUTTONDOWN:
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:
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)


with open('CarParkPos', 'wb') as f:
pickle.dump(posList, f)


while True:
img=cv2.imread(path)

img = cv2.imread('Assets/carParkImg.png')
for pos in posList:
cv2.rectangle(img,pos,(pos[0]+width,pos[1]+height),(255,43,67),2)

cv2.imshow("parking",img)
cv2.setMouseCallback("parking",mouseClick)
cv2.waitKey(1)
# if cv2.waitKey(1) & 0xff==ord('q'):
# break
cv2.rectangle(img, pos, (pos[0] + width, pos[1] + height), (255, 0, 255), 2)

cv2.imshow("Image", img)
cv2.setMouseCallback("Image", mouseClick)
if cv2.waitKey(1) & 0xff==ord('q'):
break