generally works

This commit is contained in:
adam 2023-11-08 11:01:17 -05:00
parent dded60ad2c
commit cc0e88c3f4

View File

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
# echo "#"
# phase 1: take screenshots echo "# phase 1: take screenshots"
# echo "#"
if [ ! -d "screenshots" ]; then if [ ! -d "screenshots" ]; then
mkdir screenshots mkdir screenshots
@ -13,12 +13,12 @@ do
filename=$(basename -- "$file") filename=$(basename -- "$file")
#extension="${filename##*.}" #extension="${filename##*.}"
filename="${filename%.*}" filename="${filename%.*}"
ffmpeg -ss 0 -i $file -vf fps=0.5 ./screenshots/$filename%d.png ffmpeg -ss 0 -i $file -vf fps=0.5 ./screenshots/$filename-%d.png
done done
# echo "#"
# phase 2: img preprocess echo "# phase 2: img preprocess"
# echo "#"
if [ ! -d "preproccessed" ]; then if [ ! -d "preproccessed" ]; then
mkdir preproccessed mkdir preproccessed
@ -28,12 +28,12 @@ do
filename=$(basename -- "$file") filename=$(basename -- "$file")
extension="${filename##*.}" extension="${filename##*.}"
filename="${filename%.*}" filename="${filename%.*}"
convert "$file" -gravity SouthWest -crop 560x60+0+0 -fuzz 12% +transparent "#edf1c9" "preproccessed/$filename.png" convert "$file" -gravity SouthWest -crop 560x48+0+8 -fuzz 12% +transparent "#edf1c9" "preproccessed/$filename.png"
done done
# echo "#"
# phase 3: ocr echo "# phase 3: ocr"
# echo "#"
if [ ! -d "ocr" ]; then if [ ! -d "ocr" ]; then
mkdir ocr mkdir ocr
@ -43,14 +43,14 @@ do
filename=$(basename -- "$file") filename=$(basename -- "$file")
extension="${filename##*.}" extension="${filename##*.}"
filename="${filename%.*}" filename="${filename%.*}"
tesseract $file "ocr/$filename" tesseract $file "ocr/$filename" -c tessedit_char_whitelist=" 0123456789KM/HNW."
sed -i 's/ //g' "ocr/$filename.txt"
done done
# echo "#"
# phase 4: prep for geotagging echo "# phase 4: prep for geotagging"
# echo "#"
if [ ! -d "tagged" ]; then if [ ! -d "tagged" ]; then
mkdir tagged mkdir tagged
fi fi
@ -60,5 +60,38 @@ do
extension="${filename##*.}" extension="${filename##*.}"
filename="${filename%.*}" filename="${filename%.*}"
convert $file "tagged/$filename.jpg" convert $file "tagged/$filename.jpg"
exiftool -overwrite_original -TagsFromFile ./knowngood.jpg -All:All "tagged/$filename.jpg"
done done
exiftool -overwrite_original -TagsFromFile ./knowngood.jpg -All:All "tagged/*.jpg"
echo "#"
echo "# phase 5: if ocr was good, geotag. Otherwise, reject."
echo "#"
goodreads=0
badreads=0
if [ ! -d "badread" ]; then
mkdir badread
fi
find "ocr" -iname "*.txt" -print0 | while read -d $'\0' file
do
filename=$(basename -- "$file")
extension="${filename##*.}"
filename="${filename%.*}"
n=$(grep -Poh "(?<=N)[0-9]{2}\\.[0-9]+" "$file")
w=$(grep -Poh "(?<=W)[0-9]{2}\\.[0-9]+" "$file")
if [ -n "$n" ] && [ -n "$w" ]; then
goodreads=$(($goodreads+1))
echo "$filename was OCR'd well; $goodreads good so far"
exiftool -overwrite_original -gpslatitude="$n" -gpslongitude="-$w" -GPSLatitudeRef="North" -GPSLongitudeRef="West" "tagged/$filename.jpg"
else
badreads=$(($badreads+1))
echo "$filename is not perfect; $badreads bad so far"
mv "tagged/$filename.jpg" "badread/$filename.jpg"
mv "ocr/$filename.txt" "badread/$filename.txt"
mv "preproccessed/$filename.png" "badread/$filename.png"
fi
done
echo "$goodreads good, $badreads bad. accuracy:"
bc <<< "scale=4; goodreads=$goodreads; badreads=$badreads; ratio=100*goodreads/(goodreads+badreads);ratio"