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
50168a82
Commit
50168a82
authored
Jul 06, 2021
by
Methsarani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tracker.py
parent
734e8be5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
ObjectTraking/tracker.py
ObjectTraking/tracker.py
+53
-0
No files found.
ObjectTraking/tracker.py
0 → 100644
View file @
50168a82
import
math
class
EuclideanDistTracker
:
def
__init__
(
self
):
# Store the center positions of the objects
self
.
center_points
=
{}
# Keep the count of the IDs
# each time a new object id detected, the count will increase by one
self
.
id_count
=
0
def
update
(
self
,
objects_rect
):
# Objects boxes and ids
objects_bbs_ids
=
[]
# Get center point of new object
for
rect
in
objects_rect
:
x
,
y
,
w
,
h
=
rect
cx
=
(
x
+
x
+
w
)
//
2
cy
=
(
y
+
y
+
h
)
//
2
# Find out if that object was detected already
same_object_detected
=
False
for
id
,
pt
in
self
.
center_points
.
items
():
dist
=
math
.
hypot
(
cx
-
pt
[
0
],
cy
-
pt
[
1
])
if
dist
<
25
:
self
.
center_points
[
id
]
=
(
cx
,
cy
)
print
(
self
.
center_points
)
objects_bbs_ids
.
append
([
x
,
y
,
w
,
h
,
id
])
same_object_detected
=
True
break
# New object is detected we assign the ID to that object
if
same_object_detected
is
False
:
self
.
center_points
[
self
.
id_count
]
=
(
cx
,
cy
)
objects_bbs_ids
.
append
([
x
,
y
,
w
,
h
,
self
.
id_count
])
self
.
id_count
+=
1
# Clean the dictionary by center points to remove IDS not used anymore
new_center_points
=
{}
for
obj_bb_id
in
objects_bbs_ids
:
_
,
_
,
_
,
_
,
object_id
=
obj_bb_id
center
=
self
.
center_points
[
object_id
]
new_center_points
[
object_id
]
=
center
# Update dictionary with IDs not used removed
self
.
center_points
=
new_center_points
.
copy
()
return
objects_bbs_ids
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