Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Secure smart parking solution
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
0
Merge Requests
0
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
2021-122
Secure smart parking solution
Commits
42073605
Commit
42073605
authored
Jul 04, 2021
by
Methsarani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add object traking code
parent
cf29887d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
ObjectTraking/main.py
ObjectTraking/main.py
+50
-0
No files found.
ObjectTraking/main.py
0 → 100644
View file @
42073605
import
cv2
from
tracker
import
*
# Create tracker object
tracker
=
EuclideanDistTracker
()
cap
=
cv2
.
VideoCapture
(
"highway.mp4"
)
# Object detection from Stable camera
object_detector
=
cv2
.
createBackgroundSubtractorMOG2
(
history
=
100
,
varThreshold
=
40
)
while
True
:
ret
,
frame
=
cap
.
read
()
height
,
width
,
_
=
frame
.
shape
# Extract Region of interest
roi
=
frame
[
340
:
720
,
500
:
800
]
# 1. Object Detection
mask
=
object_detector
.
apply
(
roi
)
_
,
mask
=
cv2
.
threshold
(
mask
,
254
,
255
,
cv2
.
THRESH_BINARY
)
contours
,
_
=
cv2
.
findContours
(
mask
,
cv2
.
RETR_TREE
,
cv2
.
CHAIN_APPROX_SIMPLE
)
detections
=
[]
for
cnt
in
contours
:
# Calculate area and remove small elements
area
=
cv2
.
contourArea
(
cnt
)
if
area
>
100
:
#cv2.drawContours(roi, [cnt], -1, (0, 255, 0), 2)
x
,
y
,
w
,
h
=
cv2
.
boundingRect
(
cnt
)
detections
.
append
([
x
,
y
,
w
,
h
])
# 2. Object Tracking
boxes_ids
=
tracker
.
update
(
detections
)
for
box_id
in
boxes_ids
:
x
,
y
,
w
,
h
,
id
=
box_id
cv2
.
putText
(
roi
,
str
(
id
),
(
x
,
y
-
15
),
cv2
.
FONT_HERSHEY_PLAIN
,
2
,
(
255
,
0
,
0
),
2
)
cv2
.
rectangle
(
roi
,
(
x
,
y
),
(
x
+
w
,
y
+
h
),
(
0
,
255
,
0
),
3
)
cv2
.
imshow
(
"roi"
,
roi
)
cv2
.
imshow
(
"Frame"
,
frame
)
cv2
.
imshow
(
"Mask"
,
mask
)
key
=
cv2
.
waitKey
(
30
)
if
key
==
27
:
break
cap
.
release
()
cv2
.
destroyAllWindows
()
\ No newline at end of file
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