sikuli (1.0~x~rc3.tesseract3-dfsg1-5) tessdata.patch

Summary

 sikuli-script/CMakeLists.txt                                      |    2 -
 sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java |   10 ++------
 sikuli-script/src/main/native/tessocr.cpp                         |   12 +---------
 3 files changed, 6 insertions(+), 18 deletions(-)

    
download this patch

Patch contents

Description: Fix tessdata directory location
 The default path for the tessdata parent directory should be set to
 "/usr/share/tesseract-ocr/" except when overriden by the TESSDATA_PREFIX
 environment variable.
Author: Gilles Filippini <pini@debian.org>
Bug-Debian: http://bugs.debian.org/667513
Index: sikuli/sikuli-script/CMakeLists.txt
===================================================================
--- sikuli.orig/sikuli-script/CMakeLists.txt	2012-04-15 22:14:18.000000000 +0200
+++ sikuli/sikuli-script/CMakeLists.txt	2012-04-15 22:14:18.000000000 +0200
@@ -156,7 +156,7 @@
 add_dependencies(${JAR_FILE} 
         ${JAR_FILE}.classes-in-jar 
         #${JAR_FILE}.python-src-in-jar
-        ${JAR_FILE}.tessdata-in-jar
+        #${JAR_FILE}.tessdata-in-jar
         #${JAR_FILE}.libs-in-jar
         #${JAR_FILE}.includes-in-jar
         #${JAR_FILE}.jython-in-jar
Index: sikuli/sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java
===================================================================
--- sikuli.orig/sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java	2012-04-15 22:14:18.000000000 +0200
+++ sikuli/sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java	2012-04-15 22:54:45.000000000 +0200
@@ -11,6 +11,7 @@
 import java.util.Enumeration;
 import java.util.List;
 import java.util.LinkedList;
+import java.lang.System;
 
 import org.sikuli.script.natives.Mat;
 import org.sikuli.script.natives.Vision;
@@ -40,19 +41,14 @@
    public void init(){
       Debug.info("Text Recognizer inited.");
       try{
-         String path = ResourceExtractor.extract("tessdata");
-         // TESSDATA_PREFIX doesn't contain tessdata/
-         if(path.endsWith("tessdata/"))
-            path = path.substring(0,path.length()-9);
+         String path = System.getenv("TESSDATA_PREFIX");
          Settings.OcrDataPath = path;
          Debug.log(3, "OCR data path: " + path);
 
          Vision.initOCR(Settings.OcrDataPath);
          _init_succeeded = true;
       }
-      catch(IOException e){
-         e.printStackTrace();
-      }catch(Exception e){
+      catch(Exception e){
          e.printStackTrace();         
       }
    }
Index: sikuli/sikuli-script/src/main/native/tessocr.cpp
===================================================================
--- sikuli.orig/sikuli-script/src/main/native/tessocr.cpp	2012-04-15 22:14:18.000000000 +0200
+++ sikuli/sikuli-script/src/main/native/tessocr.cpp	2012-04-16 00:11:53.000000000 +0200
@@ -362,7 +362,7 @@
 }
 
 bool OCR::isInitialized = false;
-string OCR::_datapath = "tessdata";
+string OCR::_datapath = "/usr/share/tesseract-ocr/";
 string OCR::_lang = "eng";
 
 void OCR::setParameter(std::string param, std::string value){
@@ -394,16 +394,8 @@
    if (isInitialized)
       return;
    
-   _datapath = datapath;
+   if (datapath) _datapath = datapath;
 
-#ifdef WIN32
-   string env_datapath = string("TESSDATA_PREFIX=") + string(datapath);
-   putenv(const_cast<char*>(env_datapath.c_str()));
-#else
-   //putenv on Mac breaks the "open" command somehow.
-   //we have to use setenv instead.
-   setenv("TESSDATA_PREFIX", datapath, 1);
-#endif
    int ret = _tessAPI.Init(datapath, _lang.c_str(), OEM_TESSERACT_ONLY);
    //cout << (ret==0?"done":"failed") << endl;