Last active
December 21, 2016 09:22
-
-
Save orotemo/3cc368e30cbb492db082db69a1a412f5 to your computer and use it in GitHub Desktop.
draws rectangles with labels. example input provided. expects the input image to have similarly named `.csv` file next to it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read base_name <<< $( echo $1 | awk -F "\." '{print $1}' ) | |
size=$(convert "$1" -print "%wx%h\n" /dev/null) | |
read width height <<< $( echo $size | awk -F'[x]' '{print $1" "$2}' ) | |
export IFS="," | |
prev_label="" | |
int_coord () { | |
read fi <<< $(echo "$1*$2" | bc) | |
echo $(printf '%.*f\n' 0 $fi) | |
} | |
cat "$base_name.csv" | while read label x0 y0 x1 y1; do | |
ix0=$( int_coord $x0 $width ) | |
iy0=$( int_coord $y0 $height ) | |
ix1=$( int_coord $x1 $width ) | |
iy1=$( int_coord $y1 $height ) | |
echo "these are the coords: ($ix0,$iy0) ($ix1,$iy1)" | |
convert $1 -fill none -stroke black -draw "rectangle $ix0,$iy0 $ix1,$iy1" $1 | |
if [ "$prev_label" != "$label" ] ; then | |
convert $1 -fill none -stroke black -annotate +$ix0+$iy0 "$label" $1 | |
prev_label=$label | |
fi | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
label | x0 | y0 | x1 | y1 | |
---|---|---|---|---|---|
Boots | 0.882147192955 | 0.808653116226 | 0.967409968376 | 1.00887334347 | |
Boots | 0.826834619045 | 0.831465601921 | 0.887189567089 | 0.990415334702 | |
Boots | 0.15965116024 | 0.856344044209 | 0.229738771915 | 0.98370474577 | |
Boots | 0.0980109274387 | 0.855636000633 | 0.184728354216 | 0.984177589417 | |
Dresses | 0.0 | 0.13127169013 | 0.274844318628 | 0.745087862015 | |
Coats | 0.706347346306 | 0.146474629641 | 0.981228232384 | 0.704934597015 | |
Coats | 0.521777749062 | 0.151276707649 | 0.758836388588 | 0.656416833401 | |
Dresses | 0.243550896645 | 0.15869012475 | 0.543184220791 | 0.681744217873 | |
Neclesses | 0.302464842796 | 0.185173735023 | 0.461443960667 | 0.317349016666 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment