-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_MotionTracker.sh
More file actions
153 lines (131 loc) · 3.77 KB
/
Copy pathscript_MotionTracker.sh
File metadata and controls
153 lines (131 loc) · 3.77 KB
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
#! /bin/bash
# script inspired by http://www.raspberrypi.org/phpBB3/viewtopic.php?p=453746#p453746
OUTPUT_FILE="image.jpg"
OPTION="-rot 180 -q 10 -o $OUTPUT_FILE -w 1200 -h 896 -s -t "
TIME_FILE="time.left"
DATE=$(date +%Y%m%d-%H%M%S)
FOLDER="/media/motiondetect_imgrepo"
LOG_FILE="cap.log"
PID=`pgrep raspistill`
TIME_FILE="time.left"
isRunning=1
CameraMoved=0
IMG_IN_JPG="image.jpg"
IMG_IN_BMP="image.bmp"
IMG_1_BMP="img1_comp.bmp"
IMG_2_BMP="img2_comp.bmp"
IMG_SmallJPG="image_small.jpg"
RESOL_COMPARE="150x112"
RESOL_MINI="300x224"
test -x /usr/bin/raspistill || exit 0
case "$1" in
start)
nom_process=$(basename "$0")
nom_process=${nom_process:0:15}
nb_process=$(pgrep $nom_process | wc -l)
if [ "$nb_process" -gt 2 ]; then
echo "Process Already Running"
else
echo "raspistill shadow process started for $(($2 * 60000)) seconds ($2 minutes)"
/usr/bin/raspistill $OPTION $(($2 * 60000)) &
./script_timer_in_min.sh $2 &
sleep 2
echo "Started at $DATE"
echo "Started at $DATE" >> $FOLDER/$LOG_FILE
#prendre la capture OLD
kill -USR1 $PID
sleep 0.3
#echo "capturing first file"
#créer le BMP pour detection
gm mogrify -format bmp -size $RESOL_COMPARE $IMG_IN_JPG
mv $IMG_IN_BMP $IMG_1_BMP
while [ $isRunning -eq 1 ]; do
#prendre la capture NEW
kill -USR1 $PID
sleep 0.1
#créer le BMP pour detection
gm mogrify -format bmp -size $RESOL_COMPARE $IMG_IN_JPG
mv $IMG_IN_BMP $IMG_2_BMP
#créer le jpg reduit affichage
cp $IMG_IN_JPG $IMG_SmallJPG
gm mogrify -size $RESOL_MINI $IMG_SmallJPG
#copie des jpg pour surveillance
cp $IMG_SmallJPG $FOLDER/small
DATE=$(date +%Y%m%d-%H%M%S)
if [ $CameraMoved -eq 0 ];
then
#comparing files
resultat=$(./ImgDiff)
c=$((resultat+0))
if [ "$c" -gt 5 ]; then
echo "Move detected : $c"
echo "$DATE" >> $FOLDER/$LOG_FILE
cammove=$(($c/5))
echo "Cam Move : $cammove to right"
sudo python movecamera.py $cammove &
echo "Move right @ $DATE" >> $FOLDER/$LOG_FILE &
CameraMoved=1
cp $IMG_IN_JPG $FOLDER/IMG_$DATE.jpg &
fi
if [ "$c" -lt -5 ]; then
echo "Move detected : $c"
echo "$DATE" >> $FOLDER/$LOG_FILE
cammove=$(($c/5))
echo "Cam Move : $cammove to left"
sudo python movecamera.py $cammove &
echo "Move left @ $DATE" >> $FOLDER/$LOG_FILE &
CameraMoved=1
cp $IMG_IN_JPG $FOLDER/IMG_$DATE.jpg &
fi
PID=`pgrep raspistill`
if [[ -n $PID ]]; then
#echo "Raspberry Pi Camera Module Fast Capture Daemon is at" `pgrep raspistill`
isRunning=1
else
echo "Raspberry Pi Camera Module Fast Capture Daemon is Not Running"
isRunning=0
fi
if [ -f $TIME_FILE ]; then
A=10
cp $TIME_FILE $FOLDER/$TIME_FILE &
fi
else #du if [ $CameraMoved -eq 0 ];
CameraMoved=0
fi
rm $IMG_1_BMP
mv $IMG_2_BMP $IMG_1_BMP
done
DATE=$(date +%Y%m%d-%H%M%S)
echo "Stopped at $DATE"
echo "Stopped at $DATE" >> $FOLDER/$LOG_FILE
fi
;;
stop)
pkill raspistill
pkill script_timer_in
rm -f TIME_FILE
;;
# restart)
# pkill raspistill
# pkill script_timer_in
# rm -f TIME_FILE
# echo "raspistill shadow process started for $(($2 * 60000)) seconds ($2 minutes)"
# /usr/bin/raspistill $OPTION $(($2 * 60000)) &
# ./script_timer_in_min.sh $2 &
# ;;
pid)
if [[ -n $(pgrep raspistill) ]]; then
echo `pgrep raspistill`
else
echo "0"
fi
;;
capture)
kill -USR1 `pgrep raspistill`
;;
*)
echo "Usage: $0 {start <nb of minuteof running>|stop|restart<nb of minuteof running>|pid|capture}"
exit 1
;;
esac
exit 0