#!/bin/sh set -e # get frames path from cli args framespath=${1:-} [ -z "$framespath" ] && echo "no framespath provided" && exit 1 # draw random pic mkdir -p test imageName=$(find "$framespath" -type f | sort -R | tail -1) shavedName="test/"$(basename "$imageName") echo "working with $imageName" # detect image border: increment=5 x=150 limitX=400 y=50 colorFuzz=.04 borderColor="#f7d9ac" while true do pixelColor=$(magick convert "$imageName" -crop 1x1+$x+$y -depth 8 txt:- | awk ' NR==2 {print $3}') colorDiff=$(magick compare -metric RMSE xc:"$borderColor" xc:"$pixelColor" null: 2>&1 | sed "s/.*(\(.*\))/\1/") # break condition success echo "fuzz: $colorFuzz; diff: $colorDiff; point: $x:$y" [ 1 -eq "$(echo "$colorFuzz > $colorDiff" | bc)" ] && echo "found border: $x:$y" \ && magick convert "$imageName" -colorspace Gray -shave "${x}x0" "$shavedName" \ && break # break condition fail [ "$x" -gt "$limitX" ] && echo "failed to find border" && break # update point x=$((x+increment)) done # generate bunch of cut and gray images # two param types: scale and bottom crop scaleX=400 scaleInc=20 bottomCrop=10 bottomInc=10 # both limits are reached in 20 runs loopRunLimit=20 loop=0 # first change only scale # then only bottomCrop # then both while true do # break condition [ "$loop" -gt "$loopRunLimit" ] && break resizeName="test/${shavedName}_${scaleX}_0.png" chopName="test/${shavedName}_0_${bottomCrop}.png" resizeChopName="test/${shavedName}_${scaleX}_${bottomCrop}.png" magick convert "$shavedName" -adaptive-resize ${scaleX}x "$resizeName" magick convert "$shavedName" -gravity South -chop 0x${bottomCrop} "$chopName" magick convert "$shavedName" -gravity South -chop 0x${bottomCrop} -adaptive-resize ${scaleX}x "$resizeChopName" scaleX=$((scaleX+scaleInc)) bottomCrop=$((bottomCrop+bottomInc)) loop=$((loop+1)) done # convert every new image to text mkdir -p test_text for img in test/* do outName=$(basename "$img") tesseract -l deu "$img" "test_text/$outName" done # quality check text files for t in test_text/* do ./quality_check.py "$t" >> quality_out done