blob: eabefa576ede57818cd238b551612fa3c5ce6d66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#!/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
|