From e2bea65b731468793a93920ef3c781c417526461 Mon Sep 17 00:00:00 2001 From: Robert Theis Date: Thu, 19 Apr 2018 16:44:51 -0700 Subject: [PATCH] Catch Arabic/Hindi init misconfigurations. Closes #240. --- .../com/googlecode/tesseract/android/TessBaseAPI.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java b/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java index a11095d69..57b0718a2 100644 --- a/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java +++ b/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java @@ -337,6 +337,17 @@ public boolean init(String datapath, String language, @OcrEngineMode int ocrEngi languageCode + ".traineddata"); if (!datafile.exists()) throw new IllegalArgumentException("Data file not found at " + datafile); + + // Catch some common problematic initialization cases. + if (languageCode.equals("ara") || (languageCode.equals("hin") && + ocrEngineMode == OEM_DEFAULT)) { + boolean sampleCubeFileExists = new File(tessdata + + File.separator + languageCode + ".cube.params").exists(); + if (!sampleCubeFileExists) { + throw new IllegalArgumentException("Cube data files not found." + + " See https://github.com/rmtheis/tess-two/issues/239"); + } + } } } }