Skip to content

Instantly share code, notes, and snippets.

@orotemo
Created December 1, 2016 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orotemo/63fd432be804b80469a80d2ee37362a8 to your computer and use it in GitHub Desktop.
Save orotemo/63fd432be804b80469a80d2ee37362a8 to your computer and use it in GitHub Desktop.
#!/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=""
cat "$base_name.csv" | while read label x0 y0 x1 y1; do
read fx0 <<< $(echo "$x0*$width" | bc)
ix0=$(printf '%.*f\n' 0 $fx0)
read fy0 <<< $(echo "$y0*$height" | bc)
iy0=$(printf '%.*f\n' 0 $fy0)
read fx1 <<< $(echo "$x1*$width" | bc)
ix1=$(printf '%.*f\n' 0 $fx1)
read fy1 <<< $(echo "$y1*$height" | bc)
iy1=$(printf '%.*f\n' 0 $fy1)
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
@orotemo
Copy link
Author

orotemo commented Dec 4, 2016

can transform using :

in2csv debug_images/FNx5c3sc2qrg5amtN20y.json | csvcut -c label,x0,y0,x1,y1 > debug_images/FNx5c3sc2qrg5amtN20y.csv

then ./draw_conv.sh FNx5c3sc2qrg5amtN20y.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment