-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.sh
executable file
·235 lines (218 loc) · 5.82 KB
/
main.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "VisTraSAS - Visual Traffic surveillance and Analytics System"
echo " "
echo "main.sh [options] application [arguments]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-e, --engine=ENGINE Specify engine file"
echo "-v, --verbose=VERBOSE Verbosity(0 or 1)"
echo "-c, --caffe-model=CAFFE_MODEL Specify caffe model (if engine not present)"
echo "-p, --caffe-proto=CAFFE_PROTO Specify caffe prototxt (if engine not present)"
echo "-P, --pipe-path=PIPE_PATH Path where the piping buffer should be created"
echo "-s, --segment-path=SEGMENT_PATH Location of generated segments"
echo "-l, --line-coord=LINE_COORD Line coordinates for camera (specific to camera)"
echo "-i, --intrinsics=CAM_PARAM Camara Intrinsic parameters (specific to camera)"
echo "-q, --qlength_conf=Q_CONF Configuration json for qlength (specific to camera)"
exit 0
;;
-e)
shift
if test $# -gt 0; then
export ENGINE=$1
else
echo "no engine file specified specified"
echo "WARNING::attempting to create engine file"
fi
shift
;;
--engine*)
export ENGINE=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-v)
shift
if test $# -gt 0; then
export VERBOSE=$1
else
echo "no verbosity specified (default to 0)"
fi
shift
;;
--verbose*)
export VERBOSE=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-c)
shift
if test $# -gt 0; then
export CAFFE_MODEL=$1
else
echo "no caffe-model specified specified"
echo "WARNING::Please provide engine file"
if [ -z $ENGINE]
then
exit 1
fi
fi
shift
;;
--caffe-model*)
export CAFFE_MODEL=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-p)
shift
if test $# -gt 0; then
export CAFFE_PROTO=$1
else
echo "no caffe-proto specified specified"
echo "WARNING::please provide engine file"
if [ -z $ENGINE]
then
exit 1
fi
fi
shift
;;
--caffe-proto*)
export CAFFE_PROTO=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-P)
shift
if test $# -gt 0; then
export PIPE_PATH=$1
else
echo "no pipe path specified specified"
exit 1
fi
shift
;;
--pipe-path*)
export PIPE_PATH=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-s)
shift
if test $# -gt 0; then
export SEGMENT_PATH=$1
else
echo "no Segment source specified"
exit 1
fi
shift
;;
--segment-path*)
export SEGMENT_PATH=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-l)
shift
if test $# -gt 0; then
export LINE_COORD=$1
else
echo "no line coordinates for counts"
exit 1
fi
shift
;;
--line-coord*)
export LINE_COORD=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-i)
shift
if test $# -gt 0; then
export CAM_PARAM=$1
else
echo "nocamera intrinsics for speeds"
exit 1
fi
shift
;;
--intrinsics*)
export CAM_PARAM=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-q)
shift
if test $# -gt 0; then
export Q_CONF=$1
else
echo "nocamera qlen config file"
exit 1
fi
shift
;;
--qlength_conf*)
export Q_CONF=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-r)
shift
if test $# -gt 0; then
export RTSP_STRM=$1
else
echo "rtsp stream has to be given for code to work"
exit 1
fi
shift
;;
--rtsp_strm*)
export RTSP_STRM=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
*)
break
;;
esac
done
mkdir -p segments/$SEGMENT_PATH
mkdir -p results/$SEGMENT_PATH
#mkdir -p pipes/$SEGMENT_PATH
# when link is provided uncomment
# ffmpeg -hide_banner -loglevel panic -i $RTSP_STRM -framerate 25 -an -vcodec copy -f segment -segment_time 300 -reset_timestamps 0 -strftime 1 ./segments/$SEGMENT_PATH/rtsp_%Y-%m-%d_%H-%M-%S.flv &
# ./bin/check_package.sh mutt
until ./bin/vid_gen.sh $RTSP_STRM $SEGMENT_PATH;
do
echo "ffmpeg has failed... Restarting ffmpeg" >&2;
# if you want email update (requires mutt)
curdate=$(date)
echo "FFMPEG has failed for $RTSP_STRM at $curdate" | mutt -s "VisTraSAS Alert" [email protected] -i -
sleep 1;
done &
# export PYTHONPATH=${PWD}/deep_sort:$PYTHONPATH
# checking if in python env
INVENV=$(python -c 'import sys; print ("1" if hasattr(sys, "real_prefix") else "0")')
if [ $INVENV -eq 1 ]
then echo "inside python environment"
else
echo "WARNING:: outside python environment"
workon all
fi
# checking if engine file is present
if [ ! -f $ENGINE ]; then
###### TODO ASSUME ENGINE IS CREATED
# ./install/createEngine --caffe-model=$CAFFE_MODEL --prototxt=$CAFFE_PROTO
echo "Engine file not found, Attempting to create one"
fi
echo $ENGINE
CUDA_VISIBLE_DEVICES=0 ./install/runYolov3 $ENGINE $PIPE_PATH ./segments/$SEGMENT_PATH &
# ./runYolov3 $ENGINE $PIPE_PATH ./segments/$SEGMENT_PATH &
# echo $PIPE_PATH $LINE_COORD $CAM_PARAM $Q_CONF
CUDA_VISIBLE_DEVICES=1 python3 main.py --segment_path=$SEGMENT_PATH --line_coordinates=$LINE_COORD --camera_intrinsics_file=$CAM_PARAM --q_length_config=$Q_CONF $PIPE_PATH &
# Clean up code
while true; do ls ./segments/$SEGMENT_PATH -1t | tail -n +11 | xargs -d '\n' rm -f; done &
# while true;
# do sleep 5;
# FFMPEG_PROC="$(ps aux | grep ffmpeg | grep test_cam | awk '{print $2}')"
# if [ -z "$FFMPEG_PROC" ]
# then
# ffmpeg -i $RTSP_STRM -framerate 25 -an -vcodec copy -f segment -segment_time 300 -reset_timestamps 0 -strftime 1 ./segments/$SEGMENT_PATH/rtsp_%Y-%m-%d_%H-%M-%S.flv &
# else echo "$SEGMENT_PATH stream stopped working at $(date)" >> stream_not_working.log
# fi
# done