2017-04-08 00:43:18 +00:00
|
|
|
{ stdenv, fetchFromGitHub, autoreconfHook, pkgconfig
|
|
|
|
, leptonica, libpng, libtiff, icu, pango, opencl-headers
|
2017-04-07 21:05:04 +00:00
|
|
|
|
|
|
|
# Supported list of languages or `null' for all available languages
|
|
|
|
, enableLanguages ? null
|
2015-05-22 05:45:59 +00:00
|
|
|
}:
|
|
|
|
|
2013-06-11 17:22:30 +00:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
name = "tesseract-${version}";
|
2017-04-08 00:43:18 +00:00
|
|
|
version = "3.05.00";
|
2011-04-24 18:04:07 +00:00
|
|
|
|
2016-12-19 12:05:30 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "tesseract-ocr";
|
|
|
|
repo = "tesseract";
|
|
|
|
rev = version;
|
2017-04-08 00:43:18 +00:00
|
|
|
sha256 = "11wrpcfl118wxsv2c3w2scznwb48c4547qml42s2bpdz079g8y30";
|
2011-04-24 18:04:07 +00:00
|
|
|
};
|
|
|
|
|
2016-12-19 12:05:30 +00:00
|
|
|
tessdata = fetchFromGitHub {
|
|
|
|
owner = "tesseract-ocr";
|
|
|
|
repo = "tessdata";
|
|
|
|
rev = "3cf1e2df1fe1d1da29295c9ef0983796c7958b7d";
|
|
|
|
sha256 = "1v4b63v5nzcxr2y3635r19l7lj5smjmc9vfk0wmxlryxncb4vpg7";
|
|
|
|
};
|
2012-06-11 10:28:28 +00:00
|
|
|
|
2017-04-08 00:43:18 +00:00
|
|
|
nativeBuildInputs = [ pkgconfig autoreconfHook ];
|
2016-12-19 12:05:30 +00:00
|
|
|
buildInputs = [ leptonica libpng libtiff icu pango opencl-headers ];
|
2016-02-20 22:33:10 +00:00
|
|
|
|
2016-12-19 12:05:30 +00:00
|
|
|
LIBLEPT_HEADERSDIR = "${leptonica}/include";
|
2011-04-24 18:04:07 +00:00
|
|
|
|
2017-04-07 21:05:04 +00:00
|
|
|
# Copy the .traineddata files of the languages specified in enableLanguages
|
|
|
|
# into `$out/share/tessdata' and check afterwards if copying was successful.
|
|
|
|
postInstall = let
|
|
|
|
mkArg = lang: "-iname ${stdenv.lib.escapeShellArg "${lang}.traineddata"}";
|
|
|
|
mkFindArgs = stdenv.lib.concatMapStringsSep " -o " mkArg;
|
|
|
|
findLangArgs = if enableLanguages != null
|
|
|
|
then "\\( ${mkFindArgs enableLanguages} \\)"
|
|
|
|
else "-iname '*.traineddata'";
|
|
|
|
in ''
|
|
|
|
numLangs="$(find "$tessdata" -mindepth 1 -maxdepth 1 -type f \
|
|
|
|
${findLangArgs} -exec cp -t "$out/share/tessdata" {} + -print | wc -l)"
|
|
|
|
|
|
|
|
${if enableLanguages != null then ''
|
|
|
|
expected=${toString (builtins.length enableLanguages)}
|
|
|
|
'' else ''
|
|
|
|
expected="$(ls -1 "$tessdata/"*.traineddata | wc -l)"
|
|
|
|
''}
|
|
|
|
|
|
|
|
if [ "$numLangs" -ne "$expected" ]; then
|
|
|
|
echo "Expected $expected languages, but $numLangs" \
|
|
|
|
"were copied to \`$out/share/tessdata'" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
2011-04-24 20:01:19 +00:00
|
|
|
|
2011-04-24 18:04:07 +00:00
|
|
|
meta = {
|
|
|
|
description = "OCR engine";
|
|
|
|
homepage = http://code.google.com/p/tesseract-ocr/;
|
2014-06-19 04:19:00 +00:00
|
|
|
license = stdenv.lib.licenses.asl20;
|
2011-04-24 18:04:07 +00:00
|
|
|
maintainers = with stdenv.lib.maintainers; [viric];
|
|
|
|
platforms = with stdenv.lib.platforms; linux;
|
|
|
|
};
|
|
|
|
}
|