Skip to content

Instantly share code, notes, and snippets.

@tuchella
Created July 31, 2019 16:15
Show Gist options
  • Save tuchella/90943a2b19c84f9645f57c2d8aaf3d3f to your computer and use it in GitHub Desktop.
Save tuchella/90943a2b19c84f9645f57c2d8aaf3d3f to your computer and use it in GitHub Desktop.
# Using awk we will find the bounding boxes from the detected points.
pushd $INPUT > /dev/null
ls -1 *.txt | \
while read fname; do
TFM=$(awk -F, 'BEGIN {
minX=1000;
maxX=0;
minY=1000;
maxY=0;
}
$1 > maxX { maxX=$1 }
$1 < minX { minX=$1 }
$2 > maxY { maxY=$2 }
$2 < minY { minY=$2 }
END {
scale=90/sqrt((minX-maxX)*(minY-maxY));
width=maxX-minX;
height=maxY-minY;
cenX=width/2;
cenY=height/2;
printf "%s %s %s %s\n",
FILENAME,
(minX-cenX)*scale,
(minY-cenY)*scale,
(scale)*100
}' $fname)
awk -F, -v left=$(echo $TFM | cut -f2 -d' ') \
-v top=$(echo $TFM | cut -f3 -d' ') \
-v scale=$(echo $TFM | cut -f4 -d' ') '{
s=scale/100;
x=($1*s)-left;
y=($2*s)-top;
printf "%.0f,%.0f\n", x, y}' $fname > $fname-scaled
echo $TFM
done > crop.tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment