writeINRIAPersonSigset.sh
1.85 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
#!/bin/bash
# prints out a <presentation> element
# additional arguments after the first two are rectangle coordinates
# from that, it will create a nested <data:bbox> element (from the ViPER standard)
# http://viper-toolkit.sourceforge.net/docs/file/
writePresentation()
{
pres="\t\t<presentation Label=\"pos\" file-name=\"$1/pos/$2\""
if [ "$#" -eq 6 ]; then
pres="$pres>"
width=$(($5-$3))
height=$(($6-$4))
pres="$pres\n\t\t\t<data:bbox height=\"$height\" width=\"$width\" x=\"$3\" y=\"$4\" />"
pres="$pres\n\t\t</presentation>"
else
pres="$pres />"
fi
printf "$pres\n"
}
# export writePresentation so xargs can call it using bash -c below
export -f writePresentation
SEDREGEX='s/.*(\([0-9]*\), \([0-9]*\)) - (\([0-9]*\), \([0-9]*\))/writeIt \1 \2 \3 \4/'
echo '<?xml version="1.0" encoding="UTF-8"?>'
echo '<biometric-signature-set>'
# print out the positive image sigs
for fullpath in INRIAPerson/$1/pos/*; do
# get just the filename, minus the path
filename=$(basename "$fullpath")
echo -e "\t<biometric-signature name=\"${filename%.*}\">"
# if this folder has annotations, add bounding boxes
if [ -d INRIAPerson/$1/annotations ]; then
annotation="INRIAPerson/$1/annotations/${filename%.*}.txt"
grep 'Bounding box' $annotation | sed "$SEDREGEX" | xargs -n 5 bash -c "writePresentation $1 $filename \$@"
# otherwise, just the normal presentation
else
writePresentation $1 $filename
fi
echo -e '\t</biometric-signature>'
done
# print out the negative image sigs
for fullpath in INRIAPerson/$1/neg/*; do
filename=$(basename "$fullpath")
echo -e "\t<biometric-signature name=\"${filename%.*}\">"
echo -e "\t\t<presentation Label=\"neg\" file-name=\"$1/neg/$filename\" />"
echo -e '\t</biometric-signature>'
done
echo '</biometric-signature-set>'