#!/bin/bash
#
# ###############################################################################
#
# xsane2tess 1.0b
#
# *** tesseract made simple ***
#
# ###############################################################################
#
# xsane2tess is a TesseractOCR wrapper to be able to use tesseract with xsane
# This is a modified version by Hartmut Krummrei 03/2010 with Language in line 77
#
#
TEMP_DIR=~/tmp/ # folder for temporary files (TIFF & tesseract data)
ERRORLOG="xsane2tess.log" # file where STDERR goes
if [[ -z "$1" ]]
then
echo "Usage: $0 [OPTIONS]
xsane2tess converts files to TIF, scans them with TesseractOCR
and outputs the text in a file.
OPTIONS:
-i <file1> define input file (any image-format supported)
-o <file2> define output-file (*.txt)
Progress- & error-messages will be stored in this logfile:
$TEMP_DIR$ERRORLOG
xsane2tess depends on
- ImageMagick http://www.imagemagick.org/
- TesseractOCR http://code.google.com/p/tesseract-ocr/
V1.0b provided by p2pforum.it - http://linux.p2pforum.it
Some coding was stolen from 'ocube'
http://www.geocities.com/thierryguy/ocube.html
"
exit
fi
# get options...
while getopts ":i:o:" OPTION
do
case $OPTION in
i) # input filename (with path)
FILE_PATH="$OPTARG"
;;
o ) # output filename
FILE_OUT="$OPTARG"
;;
esac
done
# redirect STDOUT to FILE_OUT
exec 1>>"$FILE_OUT"
# redirect STDERR to ERRORLOG
exec 2>>$TEMP_DIR$ERRORLOG
# strip path from FILE_PATH, use filename only
#IN_FILE=${FILE_PATH##*/}
IN_FILE=`basename "$FILE_PATH"`
# Changed by Hartmut
OUT_FILE=`basename "$FILE_PATH"`
# Next line changed by Hartmut
# If the filename of IN_FILE is complicated, convert produces waste,
# so lets take the OUT_FILE-name
TIF_FILE="$TEMP_DIR""${OUT_FILE%.*}".tif
TXT_FILE="$TEMP_DIR""${IN_FILE%.*}"
# converting image into TIFF (ImageMagick)
convert "$FILE_PATH" -compress none "$TIF_FILE" 1>&2
# start OCR (tesseract expands output with *.txt)
tesseract "$TIF_FILE" "$TXT_FILE" -l deu 1>&2
# STDOUT scanned text => FILE_OUT
cat "$TXT_FILE".txt
# delete graphic file after use
rm "$TIF_FILE"
# delete tesseract workfiles
rm "$TXT_FILE".txt
rm "$TXT_FILE".raw
rm "$TXT_FILE".map
#show result
kwrite "$FILE_OUT" &
Spielwurm schrieb:Na, denn - ich kann Leute nicht leiden, die mich so billig breitschlagen!
Dem kann ich mich nur anschliessen, Funktioniert Prima.diethn16 schrieb:ich bin einer, von denen, die froh sind, dass Du Dich hast "so billig breitschlagen!" lassen. Deine Lösung ist Spitze. Ich meine sie ist einen Eintrag ins WIKI wert!!
Oder meinst Du nicht?
Das hatte ich damals auch festgestellt, konnte der Sache aber aufgrund von Zeitmangel nicht auf den Grund gehen. Danach hatte sich das für mich erledigt, da ich mir einen schönen Brother 4 in 1 zugelegt habe.Rainer Juhser schrieb:Aufgrund der Fehlermeldungen in der Log-Datei vermute ich als Übeltäter den seltsamen Dateinamen, den mein Epson-Scanner beim Scan in den Betrachter generiert.