#!/usr/pkg/bin/bash
# Copyright 2020, J.-P. Demailly <demailly@fourier.ujf-grenoble.fr>
# Licence : GPLv3

if test "$1" != ""
then
    LANG=$1
else
    LANG=eng
fi

TMPXPD=$HOME/.xpaint/tmp

# adapt to whatever OCR engine you prefer
if test "`which tesseract`" != ""
then
   tesseract -l $LANG $TMPXPD/xpaint_output.ppm $TMPXPD/xpaint_ocr_output txt
elif test "`which cuneiform`" != ""
then
   cuneiform -l $LANG $TMPXPD/xpaint_output.ppm -o $TMPXPD/xpaint_ocr_output.txt
elif test "`which ocrad`" != ""
then
   ocrad $TMPXPD/xpaint_output.ppm > $TMPXPD/xpaint_ocr_output.txt
else
   echo -e "tesseract/cuneiform/ocrad engines not available !!\n\
Please adapt the 'xpaint_ocr' script to the preferred OCR engine." \
        > $TMPXPD/xpaint_ocr_output.txt
fi

rm -f $TMPXPD/xpaint_output.ppm

