IngRRD/lib/image
Vincent Riquer 3e976e643d fix OCR
* lighter convert pre transform
* make OCR more reliable
2015-02-21 00:06:01 +01:00

205 lines
6.0 KiB
Bash
Executable File

#!/bin/bash
# IngRRD (https://forge.riquer.fr/p/ingrrd/)
# Copyright (C) 2015 Vincent Riquer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
image() {
exec 2>&1
local timestamp=$2
declare -A values
tmpfile=$(mktemp --suffix=.tiff)
transform='-resize 300%x200% -contrast -channel green -threshold 50%'
if (( debug_import >= 3 ))
then
readarray -t tactout < <(convert $transform "$1" -format tiff - | tee "${1%.png}.tiff" | tesseract -l eng -psm 4 stdin stdout)
else
readarray -t tactout < <(convert $transform "$1" -format tiff - | tesseract -l eng -psm 4 stdin stdout)
fi
if ((debug_import >=2 ))
then
for index in ${!tactout[@]}
do
echo "${tactout[index]}"
done > "${1%.png}.txt"
fi
rm "$tmpfile"
for line in "${tactout[@]}"
do
case "$line" in
'Error, please try again.')
# Ingress failed when generating image, ignore file.
echo $'\tFailed capture, file removed.'
rm "$1"
return 3
;;
#14,522,411 AP 144mm AP
*' AP'*)
read value junk <<<"$line"
values[AP]=${value//,/}
;;
#Unique Portals Visited 718
'Unique Portals Visited'*)
value="${line#Unique Portals Visited }"
read values[Explorer] junk <<<"${value//,}"
;;
#Portals Discovered 9
'Portals Discovered'*)
value="${line#Portals Discovered }"
read values[Seer] junk <<<"${value//,/}"
;;
#XM Collected 130,908,527 XM
'XM Collected'*)
value="${line#XM Collected}"
read values[XM] junk <<<"${value//,/}"
;;
#Distance Walked 1,785 km
'Distance Walked'*)
value="${line#Distance Walked }"
read values[Walked] junk <<<"${value//,/}"
;;
#Resonators Deployed 24,451
'Resonators Deployed'*)
value="${line#Resonators Deployed }"
read values[Builder] junk <<<"${value//,/}"
;;
#Links Created 4,479
'Links Created'*)
value="${line#Links Created }"
read values[Connector] junk <<<"${value//,/}"
;;
#Control Fields Created 2,340
'Control Fields Created'*)
value="${line#Control Fields Created }"
read values[Mind_Controller] junk <<<"${value//,/}"
;;
#Mind Units Captured 155,815 MUs
'Mind Units Captured'*)
value="${line#Mind Units Captured }"
read values[MU] junk <<<"${value//,/}"
;;
#Longest Link Ever Created 3 km
'Longest Link Ever Created'*)
value="${line#Longest Link Ever Created }"
read values[Longest_Link] junk <<<"${value//,/}"
;;
#Largest Control Field 11,588 MUs
'Largest Control Field'*)
value="${line#Largest Control Field }"
read values[Largest_Field] junk <<<"${value//,/}"
;;
#XM Recharged 92,120,959 XM
'XM Recharged'*)
value="${line#XM Recharged }"
read values[Recharger] junk <<<"${value//,/}"
;;
#Portals Captured 2,022
'Portals Captured'*)
value="${line#Portals Captured }"
read values[Liberator] junk <<<"${value//,/}"
;;
#Unique Portals Captured 375
'Unique Portals Captured'*)
value="${line#Unique Portals Captured }"
read values[Pioneer] junk <<<"${value//,/}"
;;
#Mods Deployed 995
'Mods Deployed'*)
value="${line#Mods Deployed }"
read values[Engineer] junk <<<"${value//,/}"
;;
#Resonators Destroyed 15,855
'Resonators Destroyed'*)
value="${line#Resonators Destroyed }"
read values[Purifier] junk <<<"${value//,/}"
;;
#Portals Neutralized 2,145
'Portals Neutralized'*)
value="${line#Portals Neutralized }"
read values[Neutralized] junk <<<"${value//,/}"
;;
#Enemy Links Destroyed 2,725
'Enemy Links Destroyed'*)
value="${line#Enemy Links Destroyed }"
read values[Links_Destroyed] junk <<<"${value//,/}"
;;
#Enemy Control Fields Destroyed 1,418
'Enemy Control Fields Destroyed'*)
value="${line#Enemy Control Fields Destroyed }"
read values[Fields_Destroyed] junk <<<"${value//,/}"
;;
#Max Time Portal Held 105 days
'Max Time Portal Held'*)
value="${line#Max Time Portal Held }"
read values[Guardian] junk <<<"${value//,/}"
;;
#Max Time Link Maintained 75 days
'Max Time Link Maintained'*)
value="${line#Max Time Link Maintained }"
read values[Link_Maintained] junk <<<"${value//,/}"
;;
#Max Link Length x Days 89 km-days
'Max Link Length x Days'*)
value="${line#Max Link Length x Days }"
read values[Link_Length_x_Days] junk <<<"${value//,/}"
;;
#Max Time Field Held 55 days
'Max Time Field Held'*)
value="${line#Max Time Field Held }"
read values[Field_Held] junk <<<"${value//,/}"
;;
#Largest Field MUs x Days 58,959 MU-days
'Largest Field MUs x Days'*)
value="${line#Largest Field MUs x Days }"
read values[Field_x_Days] junk <<<"${value//,/}"
;;
#Unique Missions Completed 1
'Unique Missions Completed'*)
value="${line#Unique Missions Completed }"
read values[Mercenary] junk <<<"${value//,/}"
;;
#Hacks 25,741
'Hacks'*)
value="${line#Hacks }"
read values[Hacker] junk <<<"${value//,/}"
;;
#Glyph Hack Points 1,022
'Glyph Hack Points'*)
value="${line#Glyph Hack Points }"
read values[Translator] junk <<<"${value//,/}"
;;
#Agents Recruited 1
'Agents Recruited'*)
value="${line#Agents Recruited }"
read values[Recruiter] junk <<<"${value//,/}"
;;
esac
done
template="${!values[@]}"
updatevalues="${values[@]}"
if ((debug_import))
then
echo $'\t'"$template"
echo $'\t'"$updatevalues"
fi
rrdtool update "$rrdfile" -t "${template// /:}" "$timestamp:${updatevalues// /:}"
}