Last active
March 1, 2022 17:01
-
-
Save kba/be8a9633dbdbc3cc068386ab93b18e18 to your computer and use it in GitHub Desktop.
This file contains 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 | |
ocrd () { | |
"C:/Users/kb/AppData/Local/Programs/Python/Python39/Scripts/ocrd.exe" "$@" |tr -d '\r' | |
} | |
layouteval () { | |
set -x | |
"/cygdrive/c/Users/kb/Downloads/LayoutEvalCmd_1-9-106/LayoutEvalCmd 1.9/layoutevalcmd-1-9-106.exe" \ | |
-printWarnings \ | |
-csvValues \ | |
-csvHeaders \ | |
-profile "C:\Users\kb\Downloads\LayoutEvalCmd_1-9-106\LayoutEvalCmd 1.9\data\profiles\\$profile.evx" \ | |
"${@/\//\\}" \ | |
|tr -d '\r' | |
set +x | |
} | |
help () { | |
echo "$0 [options]" | |
echo "" | |
echo "Defaults:" | |
echo " --gt-grp '$gt_grp'" | |
echo " --bin-grp '$bin_grp" | |
echo " --mimetype '$mimetype" | |
echo " --compare-grps '$compare_grps'" | |
echo " --profile '$profile'" | |
} | |
gt_grp="OCR-D-OCR-GT" | |
bin_grp="OCR-D-IMG-BIN" | |
mimetype_page="application/vnd.prima.page+xml" | |
mimetype_alto="application/alto+xml" | |
compare_grps="OCR-D-OCR-ABBYY12 OCR-D-OCR-CALAMARI OCR-D-OCR-CCS-TESS OCR-D-OCR-GOOGLEVISION OCR-D-OCR-OMNIPAGE OCR-D-OCR-ORIGINAL OCR-D-OCR-TESS OCR-D-OCR-TRANSKRIBUS" | |
profile="Document Structure (no reading order)" | |
while [[ $1 = -* ]];do | |
case $1 in | |
--gt-grp) gt_grp=$2; shift;; | |
--bin-grp) bin_grp=$2; shift;; | |
--compare-grps) compare_grps="$2"; shift;; | |
--profile) profile="$2"; shift;; | |
*) help; exit ;; | |
esac | |
shift | |
done | |
for pageid in $(ocrd workspace list-page);do | |
# for pageid in p0001;do | |
echo "PAGE: $pageid" | |
gt=$(ocrd workspace find -g $pageid -G $gt_grp) | |
for compare_grp in $compare_grps;do | |
ocrd workspace find -g $pageid -G $compare_grp | |
compare=$(ocrd workspace find -g $pageid -G $compare_grp -m $mimetype_page) | |
if [[ -z "$compare" ]];then | |
compare=$(ocrd workspace find -g $pageid -G $compare_grp -m $mimetype_alto) | |
if [[ -z "$compare" ]];then | |
echo "No results to evaluate for page $pageid in $compare_grp" | |
continue | |
fi | |
fi | |
echo "Evaluating $compare against $gt" | |
img=$(ocrd workspace find -g $pageid -G $bin_grp) | |
resultdir="EVAL-PRIMALAYOUTEVAL-$compare_grp" | |
result_evx="$resultdir/$(basename $gt)_vs_$(basename $compare).evx" | |
result_csv="$resultdir/$(basename $gt)_vs_$(basename $compare).csv" | |
mkdir -p $resultdir | |
echo layouteval -gt "$gt" -res "$compare" -img $img -evalRes "$result_evx" | |
date | |
layouteval -gt "$gt" -res "$compare" -img $img -evalRes "$result_evx" > "$result_csv" | |
date | |
# doesn't work because atomicwrites and chmod | |
# ocrd workspace add -g $pageid -G $resultdir -m text/csv -i $(basename $resultfile) $resultfile | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment