forked from dlstreamer/dlstreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracking_ext.sh
executable file
·164 lines (148 loc) · 6.86 KB
/
tracking_ext.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# ==============================================================================
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
# ==============================================================================
print_description()
{
echo "This sample demonstrates how to track people and vehicles on a video stream with GVA"
echo "Tracker is especially useful for videos without frequent scene changes"
echo "Usage: ./tracking_ext.sh [OPTIONS] VIDEO_SOURCE"
echo "OPTIONS"
echo " -t=v, --tracking-type=v Tracking type(none, iou, short-term, zero-term)"
echo " -n=v, --every-nth-frame=v Detection on every nth frame only(int)"
echo " This option is supported correctly only by short-term tracker"
echo " -c, --console Don't render a video"
echo " -h, --help Show this chapter"
echo "VIDEO_SOURCE"
echo "$(supported_video_sources)"
}
###############################################################################
set -e
BASEDIR=$(dirname "$0")/../..
#import GET_MODEL_PATH and PROC_PATH
source $BASEDIR/scripts/path_extractor.sh
#import utility functions
source $BASEDIR/scripts/sample_utils.sh
###############################################################################
# parse input parameters
TRACKING_TYPE="short-term"
EVERY_NTH_FRAME=
VIDEO_SOURCE=
while [ "$1" != "" ]; do
case $1 in
"-t="* | "--tracking-type="* ) TRACKING_TYPE=$(get_option $1)
;;
"-n="* | "--every-nth-frame="* ) EVERY_NTH_FRAME=$(get_option $1)
;;
"-h" | "--help" ) print_description
exit 0
;;
"-c" | "--console" ) USE_CONSOLE_OUTPUT=1
;;
"-"* | "--"* ) echo -e "\e[31mERROR: unrecognized option '${1}'\e[0m"
echo "Try --help option for more information"
exit 1
;;
* ) SOURCE_ELEMENT=$(get_source_element "${1}")
break
;;
esac
shift
done
###############################################################################
# check if parameters are valid
# VIDEO_SOURCE is required
if [[ -z ${SOURCE_ELEMENT} ]]; then
echo -e "\e[31mERROR: VIDEO_SOURCE is not set\e[0m"
echo "Try --help option for more information"
exit 1
fi
if [[ ${TRACKING_TYPE} != 'short-term' ]] && [[ ${EVERY_NTH_FRAME} -gt 1 ]]; then
echo -e "\e[33mWARNING: --every-nth-frame > 1 is recommended only for short-term tracker\e[0m"
fi
###############################################################################
# detection for each frame is not nessesary if 'shor-term' tracker is used
# set EVERY_NTH_FRAME parameter to launch detection on every Nth frames only
if [[ -z ${EVERY_NTH_FRAME} ]]; then
if [ ${TRACKING_TYPE} == 'short-term' ]; then
EVERY_NTH_FRAME=10
else
EVERY_NTH_FRAME=1
fi
fi
# define the models used for detection and classification
DETECTION_MODEL=person-vehicle-bike-detection-crossroad-0078
PERSON_CLASSIFICATION_MODEL=person-attributes-recognition-crossroad-0230
VEHICLE_CLASSIFICATION_MODEL=vehicle-attributes-recognition-barrier-0039
# define other parameters for inference
DEVICE=CPU
SKIP_INTERVAL=10
# set up GST environment
if [ -n ${GST_SAMPLES_DIR} ]
then
source $BASEDIR/scripts/setup_env.sh
fi
source $BASEDIR/scripts/setlocale.sh
# print the parameters
echo -e "\e[32mRunning sample with the following parameters:\e[0m"
echo "SOURCE_ELEMENT=${SOURCE_ELEMENT}"
echo "TRACKING_TYPE=${TRACKING_TYPE}"
echo "EVERY_NTH_FRAME=${EVERY_NTH_FRAME}"
echo "USE_CONSOLE_OUTPUT=${USE_CONSOLE_OUTPUT}"
echo "GST_PLUGIN_PATH=${GST_PLUGIN_PATH}"
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
###############################################################################
# compose the pipeline from the following parts:
# VIDEO_SOURCE - read the video stream and decode it
VIDEO_SOURCE_STR=" ${SOURCE_ELEMENT} ! decodebin ! videoconvert ! video/x-raw,format=BGR "
# DETECTION - enable detection by including gvadetect into the pipeline
DETECTION_STR=" ! gvadetect model=$(GET_MODEL_PATH $DETECTION_MODEL) \
model-proc=$(PROC_PATH $DETECTION_MODEL) \
every-nth-frame=${EVERY_NTH_FRAME} \
device=$DEVICE pre-proc=ie "
# TRACKING - enable tracking by using of gvatrack
if [[ ${TRACKING_TYPE} != "none" ]]; then
TRACKING_STR="! gvatrack tracking-type=${TRACKING_TYPE} ! queue "
else
TRACKING_STR=
fi
# PERSON_CLASSIFICATION - enable classification of persons with gvaclassify
PERSON_CLASSIFICATION_STR=" ! gvaclassify skip-classified-objects=yes \
skip-interval=${SKIP_INTERVAL} \
model=$(GET_MODEL_PATH $PERSON_CLASSIFICATION_MODEL) \
model-proc=$(PROC_PATH $PERSON_CLASSIFICATION_MODEL) \
device=$DEVICE \
pre-proc=ie \
object-class=person "
# VEHICLE_CLASSIFICATION - enable classification of vehicles with gvaclassify
VEHICLE_CLASSIFICATION_STR=" ! gvaclassify skip-classified-objects=yes \
skip-interval=${SKIP_INTERVAL} \
model=$(GET_MODEL_PATH $VEHICLE_CLASSIFICATION_MODEL) \
model-proc=$(PROC_PATH $VEHICLE_CLASSIFICATION_MODEL) \
device=$DEVICE \
pre-proc=ie \
object-class=vehicle "
if [[ ${USE_CONSOLE_OUTPUT} -eq 0 ]]; then
# VIDEO_SINK - visualize the meta by gvawatermark and render the video stream
VIDEO_SINK_STR=" ! gvawatermark ! videoconvert ! fpsdisplaysink video-sink=xvimagesink sync=false "
else
# VIDEO_SINK - calculate average fps by gvafpscounter without rendering the video stream
VIDEO_SINK_STR=" ! gvafpscounter ! fakesink "
fi
###############################################################################
# join all the parts together
PIPELINE_STR="gst-launch-1.0 --gst-plugin-path ${GST_PLUGIN_PATH} \
${VIDEO_SOURCE_STR} \
${DETECTION_STR} ! queue \
${TRACKING_STR} \
${PERSON_CLASSIFICATION_STR} ! queue \
${VEHICLE_CLASSIFICATION_STR} ! queue \
${VIDEO_SINK_STR}"
# print the pipeline
echo -e "\e[32mPipeline\e[0m"
echo ${PIPELINE_STR}
# launch the pipeline
echo -e "\e[32mLaunch\e[0m"
${PIPELINE_STR}