Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SafeDrive Driver Assistant Application to Reduce Road Accidents
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CDAP TMP-2023-149
SafeDrive Driver Assistant Application to Reduce Road Accidents
Commits
008694f0
Commit
008694f0
authored
Oct 29, 2023
by
Arsath Farves
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
10bae847
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
Parkin Slot Detect
Parkin Slot Detect
+75
-0
No files found.
Parkin Slot Detect
0 → 100644
View file @
008694f0
import cv2
import pickle
cap = cv2.VideoCapture('parking_vehicle1.mp4')
with open('park_positions.unknown', 'rb') as f:
park_positions = pickle.load(f)
font = cv2.FONT_HERSHEY_COMPLEX_SMALL
# Parking space parameters
width, height = 40, 19
full = width * height
empty = 0.22
def parking_space_counter(img_processed):
global counter
counter = 0
for position in park_positions:
x, y = position
img_crop = img_processed[y:y + height, x:x + width]
count = cv2.countNonZero(img_crop)
ratio = count / full
if ratio < empty:
color = (0, 255, 0)
counter += 1
else:
color = (0, 0, 255)
cv2.rectangle(overlay, position, (position[0] + width, position[1] + height), color, -1)
cv2.putText(overlay, "{:.2f}".format(ratio), (x + 4, y + height - 4), font, 0.7, (255, 255, 255), 1, cv2.LINE_AA)
while True:
# Video looping
if cap.get(cv2.CAP_PROP_POS_FRAMES) == cap.get(cv2.CAP_PROP_FRAME_COUNT):
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
_, frame = cap.read()
frame = cv2.resize(frame, (1920, 1080))
overlay = frame.copy()
# Frame processing
img_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
img_blur = cv2.GaussianBlur(img_gray, (3, 3), 1)
img_thresh = cv2.adaptiveThreshold(img_blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 25, 16)
parking_space_counter(img_thresh)
alpha = 0.7
frame_new = cv2.addWeighted(overlay, alpha, frame, 1 - alpha, 0)
w, h = 220, 60
cv2.rectangle(frame_new, (0, 0), (w, h), (255, 0, 255), -1)
cv2.putText(frame_new, f"{counter}/{len(park_positions)}", (int(w / 10), int(h * 3 / 4)), font, 2, (255, 255, 255), 2, cv2.LINE_AA)
cv2.namedWindow('frame', cv2.WINDOW_NORMAL)
cv2.setWindowProperty('frame', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.imshow('frame', frame_new)
# cv2.imshow('image_blur', img_blur)
# cv2.imshow('image_thresh', img_thresh)
if cv2.waitKey(1) & 0xFF == 27:
break
cap.release()
cv2.destroyAllWindows()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment