#!/bin/sh #-------------------------------------------------------#----------------------# # Author : Maros RAJNOCH # GNU LINUX # # Email : rajnoch@sophia.dtp.fmph.uniba.sk # .~. # # Homeserver : http://sophia.dtp.fmph.uniba.sk/~rajnoch # /V\ # # ----------------------------------------------------- # // \\ # # Usage : aocr # /( )\ # # Examples : aocr img.png # ^`~'^ # # Version : ${version} # B E F R E E # #=======================================================#======================# # # Heavily patched by Ondrej Jombik at 11th September 2002 # Copyright (c) 2002 Platon SDG, http://www.platon.sk/ # Note, that `perl' is needed, but it should work fine anyway. # VERSION='0.002.platon' # # Help printing # if [ "X$1" = "X" ]; then echo " AOCR - Version ${VERSION} Usage: aocr aocr -d aocr -d -v where: -d DEBUGE MOD -v VERBOSE MOD " exit; fi # # `convert' binary test # CONVERT=`which convert | sed 's/.*[ ]\([^ ]*\)$/\1/g'`; if [ "X$CONVERT" = "X" ]; then echo "Sorry, 'convert' binary not found, aocr.sh cannot run."; exit; fi # # Input parameters parsing # PICTURE="$1"; DEBUG="0"; VERBOSE="0"; if [ "X$2" = "X-d" ]; then DEBUG="1"; fi if [ "X$2" = "X-v" ]; then VERBOSE="1"; fi # # Color tables # FA0='4,6,4,4,4,4,6,4' ; FA1='2,3,10,10,1,1' ; FA2='2,4,5,4,4,5,5,3' FA3='2,4,2,3,3,7,7,3' ; FA4='2,3,3,3,3,10,10,1' ; FA5='6,7,4,3,3,5,6,3' FA6='6,8,5,3,3,6,6,2' ; FA7='3,4,3,3,3,3,4,3' ; FA8='3,7,7,3,3,7,7,3' FA9='2,6,6,3,3,5,8,6' # # Frequency color analyse # FACLR=$( "${CONVERT}" "${PICTURE}" txt:- |\ cut -d'#' -f2 |\ sort |\ uniq -c |\ sort -rn |\ sed -n '2p' |\ sed 's/^ *//g' |\ cut -f2 |\ sed 's/...$//g' ) if [ "X$DEBUG" = "X1" ]; then echo "FACLR = $FACLR"; fi # # Frequency font analyse # FAFNT=$( "${CONVERT}" "${PICTURE}" txt:- |\ egrep "${FACLR}" |\ cut -d: -f1 |\ cut -d, -f1 |\ sort -n |\ uniq -c |\ perl -a -e'while(<>){split;$__.=",".$_[0];}print"$__\n"' |\ sed -e 's/^,*//' ) if [ "X$DEBUG" = "X1" ]; then echo "FAFNT = $FAFNT"; fi # # Comparing analysed data with color table # indexa=10 while [ "$((indexa-=1))" -ge "0" ]; do maska="FA${indexa}" ; eval maska=\$$maska echo "${FAFNT}" | egrep "^${maska:0:7}" &> /dev/null && break done indexb=10 while [ "$((indexb-=1))" -ge "0" ]; do maska="FA${indexb}" ; eval maska=\$$maska echo "${FAFNT}" | egrep "^...........*${maska:2:9}.............*$" &> /dev/null && break done indexc=10 while [ "$((indexc-=1))" -ge "0" ]; do maska="FA${indexc}" ; eval maska=\$$maska echo "${FAFNT}" | egrep "${maska:4}$" &> /dev/null && break done # # Additional debug info # if [ "X$DEBUG" = "X1" ]; then foo=foo.$$ convert "${PICTURE}" txt:- |\ egrep "${FACLR}" |\ cut -d: -f1 |\ sed -e "s/\([0-9]*\),\([0-9]*\)/\2;\1/" \ -e 's/^/echo -e "\\\033[/' \ -e 's/$/H*"/' > "${foo}" clear bash "${foo}" rm -rf "${foo}" fi # # Additional verbose info # if [ "X$VERBOSE" = "X1" ]; then echo "${FAFNT}" for index in "${indexa}" "${indexb}" "${indexc}" do maska="FA${index}" ; eval maska=\$$maska echo "${maska}" done fi # # Output printing # echo "$indexa$indexb$indexc" | sed 's/-1/-/g' exit 0