Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-238
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-238
2021-238
Commits
dadf1d96
Commit
dadf1d96
authored
Oct 18, 2021
by
Amanda Tennakoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload speed prediction File
parent
62fc0e37
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
vehicle_counting_tensorflow-master/utils/speed_and_direction_prediction_module/speed_prediction.py
...speed_and_direction_prediction_module/speed_prediction.py
+58
-0
No files found.
vehicle_counting_tensorflow-master/utils/speed_and_direction_prediction_module/speed_prediction.py
0 → 100644
View file @
dadf1d96
from
utils.image_utils
import
image_saver
is_vehicle_detected
=
[
0
]
current_frame_number_list
=
[
0
]
current_frame_number_list_2
=
[
0
]
bottom_position_of_detected_vehicle
=
[
0
]
def
predict_speed
(
top
,
bottom
,
right
,
left
,
current_frame_number
,
crop_img
,
roi_position
,
):
speed
=
'n.a.'
# means not available, it is just initialization
direction
=
'n.a.'
# means not available, it is just initialization
scale_constant
=
1
# manual scaling because we did not performed camera calibration
isInROI
=
True
# is the object that is inside Region Of Interest
update_csv
=
False
if
bottom
<
250
:
scale_constant
=
1
# scale_constant is used for manual scaling because we did not performed camera calibration
elif
bottom
>
250
and
bottom
<
320
:
scale_constant
=
2
# scale_constant is used for manual scaling because we did not performed camera calibration
else
:
isInROI
=
False
if
len
(
bottom_position_of_detected_vehicle
)
!=
0
and
bottom
\
-
bottom_position_of_detected_vehicle
[
0
]
>
0
and
195
\
<
bottom_position_of_detected_vehicle
[
0
]
\
and
bottom_position_of_detected_vehicle
[
0
]
<
240
\
and
roi_position
<
bottom
+
100
and
(
current_frame_number
-
current_frame_number_list_2
[
0
])
>
24
:
is_vehicle_detected
.
insert
(
0
,
1
)
update_csv
=
True
image_saver
.
save_image
(
crop_img
)
# save detected vehicle image
current_frame_number_list_2
.
insert
(
0
,
current_frame_number
)
# for debugging
# print("bottom_position_of_detected_vehicle[0]: " + str(bottom_position_of_detected_vehicle[0]))
# print("bottom: " + str(bottom))
if
bottom
>
bottom_position_of_detected_vehicle
[
0
]:
direction
=
'down'
else
:
direction
=
'up'
if
isInROI
:
pixel_length
=
bottom
-
bottom_position_of_detected_vehicle
[
0
]
scale_real_length
=
pixel_length
*
100
total_time_passed
=
current_frame_number
-
current_frame_number_list
[
0
]
scale_real_time_passed
=
total_time_passed
*
24
# get the elapsed total time for a vehicle to pass through ROI area (24 = fps)
if
scale_real_time_passed
!=
0
:
speed
=
scale_real_length
/
scale_real_time_passed
/
scale_constant
# performing manual scaling because we have not performed camera calibration
speed
=
speed
/
6
*
40
# use reference constant to get vehicle speed prediction in kilometer unit
current_frame_number_list
.
insert
(
0
,
current_frame_number
)
bottom_position_of_detected_vehicle
.
insert
(
0
,
bottom
)
return
(
direction
,
speed
,
is_vehicle_detected
,
update_csv
)
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