Created
July 31, 2019 16:15
-
-
Save tuchella/90943a2b19c84f9645f57c2d8aaf3d3f to your computer and use it in GitHub Desktop.
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
# 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