#!/bin/bash # Little OCR scan for payments code line in BVR # With PZ10 check for validity # Use netpbm, tesseract and xdotool # Could be freely distributable under term of GPL V3+ # (C) 2020 - F-Hauri.CH # # To be linked to special keyboard key shortcut... # DEVICE="-d net:scanhost:genesys" checkPz10() { if ! [[ "$1" =~ ^[0-9]+$ ]] ; then return false fi local pz=0 i tbl=(0 9 4 6 8 2 7 1 3 5) a=${1:0:-1} b=${1:${#1}-1} for ((i=0;i<${#a};i++));do pz=${tbl[($pz+${a:i:1})%10]} done pz=$((pz?10-pz:0)) [ "$pz" = "$b" ] } string=$( scanimage $DEVICE --mode Gray --resolution 600 -t 12 -l 1 -y 13 -x 150 | pnmscale .33333 2>/dev/null | pnmflip -r180 | tee /tmp/lastocr.pnm | tesseract - - txt 2>/dev/null | tr -d $'\r\n\f' ) [ "${string// }" ] || exit 121 for check in ${string//[>+]/ };do checkPz10 $check || exit 123 done xdostring="" for ((i=0;i<${#string};i++)) { char=${string:i:1} char=${char// /space} char=${char//>/greater} char=${char//+/plus} xdostring+=$char\ } xdotool key $xdostring Return