Доброго времени суток.
Имеется скрипт следующего содержания:
Показать
#!/bin/bash
for file in $(ls)
do
FILENAME=`cat $file | awk '/Image filename/ {if(sub(/"/,"")){if(sub(/"/,"")){print $4}}}'`
COUNT=`cat $file | awk '/Objects with ground truth/ {print $6}'`
#printf "%s %d " $FILENAME $COUNT
for i in `seq 1 $COUNT`;
do
X=`cat $file | tr -d '(,' |awk '/Bounding box for object '$i'/ {print $13}'`
Y=`cat $file | tr -d '),' |awk '/Bounding box for object '$i'/ {print $14}'`
echo $Y
WIDTH=`cat $file | tr -d '(,' |awk '/Bounding box for object '$i'/ {print $16}'`
#echo $WIDTH
WIDTH=$[$WIDTH - $X]
#echo $WIDTH
#echo $file
#echo $i
HEIGHT=`cat $file | tr -d '),' |awk '/Bounding box for object '$i'/ {print $17}'`
echo $HEIGHT
HEIGHT=$[$HEIGHT - $Y]
echo $HEIGHT
#printf "%d %d %d %d " $X $Y $WIDTH $HEIGHT
done
#printf "\n"
done
Вот так выполняется:
[console]
$...> ls
FudanPed00001.txt script.sh
$...> ./script.sh
182
431
- 182")syntax error: invalid arithmetic operator (error token is "
[/console]
А задумано было вот так:
[console]
...
$...> ./script.sh
182
431
249
[/console]
Не вижу как прикрепить файл, поэтому вот содержимое файла, с которым скрипт работает:
Показать
# Compatible with PASCAL Annotation Version 1.00
Image filename : "PennFudanPed/PNGImages/FudanPed00001.png"
Image size (X x Y x C) : 559 x 536 x 3
Database : "The Penn-Fudan-Pedestrian Database"
Objects with ground truth : 2 { "PASpersonWalking" "PASpersonWalking" }
# Note there may be some objects not included in the ground truth list for they are severe-occluded
# or have very small size.
# Top left pixel co-ordinates : (1, 1)
# Details for pedestrian 1 ("PASpersonWalking")
Original label for object 1 "PASpersonWalking" : "PennFudanPed"
Bounding box for object 1 "PASpersonWalking" (Xmin, Ymin) - (Xmax, Ymax) : (160, 182) - (302, 431)
Pixel mask for object 1 "PASpersonWalking" : "PennFudanPed/PedMasks/FudanPed00001_mask.png"
# Details for pedestrian 2 ("PASpersonWalking")
Original label for object 2 "PASpersonWalking" : "PennFudanPed"
Bounding box for object 2 "PASpersonWalking" (Xmin, Ymin) - (Xmax, Ymax) : (420, 171) - (535, 486)
Pixel mask for object 2 "PASpersonWalking" : "PennFudanPed/PedMasks/FudanPed00001_mask.png"
Не вижу принципиальных отличий в инициализации переменных WIDTH и HEIGHT. Не могу понять почему ширину считает правильно, а высоту нет. Может быть вы заметите ошибку?