[sikuli] 373/385: added a feature to inject string parameters into libVisionProxy and used it to allow to tell the TextRecognizer to use a different language for the Tesseract train data file (usage in script: import org.sikuli.script.TextRecognizer as TR; Settings.OcrLanguage = "deu"; TR.reset() )
Gilles Filippini
pini at moszumanska.debian.org
Sun Jun 29 19:26:38 UTC 2014
This is an automated email from the git hooks/post-receive script.
pini pushed a commit to tag upstream/1.1.0_beta1
in repository sikuli.
commit a6913fb2b14894f7760e0ad743dd1984674ece90
Author: Raimund Hocke <info at its-me-raiman.de>
Date: Tue Apr 29 09:21:24 2014 +0200
added a feature to inject string parameters into libVisionProxy and used it to allow to tell the TextRecognizer to use a different language for the Tesseract train data file (usage in script: import org.sikuli.script.TextRecognizer as TR; Settings.OcrLanguage = "deu"; TR.reset() )
---
.gitignore | 1 +
.../java/org/sikuli/script/TextRecognizer.java | 5 +
.../src/main/java/org/sikuli/basics/Settings.java | 1 +
Libs/build/mac/runBuildNatives.sh | 8 +-
.../META-INF/libs/mac/libs64/libVisionProxy.dylib | Bin 435168 -> 442024 bytes
Libs/xbuild.xml | 18 +-
.../java/org/sikuli/natives/DebugCategories.java | 2 +-
.../main/java/org/sikuli/natives/FindInput.java | 2 +-
.../main/java/org/sikuli/natives/FindResult.java | 2 +-
.../main/java/org/sikuli/natives/FindResults.java | 2 +-
Natives/src/main/java/org/sikuli/natives/Mat.java | 2 +-
Natives/src/main/java/org/sikuli/natives/OCR.java | 2 +-
.../src/main/java/org/sikuli/natives/OCRChar.java | 2 +-
.../src/main/java/org/sikuli/natives/OCRChars.java | 2 +-
.../src/main/java/org/sikuli/natives/OCRLine.java | 2 +-
.../src/main/java/org/sikuli/natives/OCRLines.java | 2 +-
.../main/java/org/sikuli/natives/OCRParagraph.java | 2 +-
.../java/org/sikuli/natives/OCRParagraphs.java | 2 +-
.../src/main/java/org/sikuli/natives/OCRRect.java | 2 +-
.../src/main/java/org/sikuli/natives/OCRText.java | 2 +-
.../src/main/java/org/sikuli/natives/OCRWord.java | 2 +-
.../src/main/java/org/sikuli/natives/OCRWords.java | 2 +-
.../main/java/org/sikuli/natives/TARGET_TYPE.java | 2 +-
.../src/main/java/org/sikuli/natives/Vision.java | 10 +-
.../main/java/org/sikuli/natives/VisionProxy.java | 2 +-
.../java/org/sikuli/natives/VisionProxyJNI.java | 4 +-
Natives/src/main/native/Vision/vision.cpp | 202 +++++++++++----------
Natives/src/main/native/Vision/vision.h | 64 ++++---
Natives/src/main/native/Vision/vision.swig | 4 +-
Natives/src/main/native/Vision/visionJAVA_wrap.cxx | 71 ++++++--
30 files changed, 256 insertions(+), 168 deletions(-)
diff --git a/.gitignore b/.gitignore
index f53b88d..143e172 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ nb*
*.iml
stuff/
*.versionsBackup
+*.log
diff --git a/API/src/main/java/org/sikuli/script/TextRecognizer.java b/API/src/main/java/org/sikuli/script/TextRecognizer.java
index 48c1b69..177fb96 100755
--- a/API/src/main/java/org/sikuli/script/TextRecognizer.java
+++ b/API/src/main/java/org/sikuli/script/TextRecognizer.java
@@ -69,6 +69,11 @@ public class TextRecognizer {
return _instance;
}
+ public static void reset() {
+ _instance = null;
+ Vision.setSParameter("OCRLang", Settings.OcrLanguage);
+ }
+
public enum ListTextMode {
WORD, LINE, PARAGRAPH
};
diff --git a/Basics/src/main/java/org/sikuli/basics/Settings.java b/Basics/src/main/java/org/sikuli/basics/Settings.java
index c21194d..fe874bc 100644
--- a/Basics/src/main/java/org/sikuli/basics/Settings.java
+++ b/Basics/src/main/java/org/sikuli/basics/Settings.java
@@ -227,6 +227,7 @@ public class Settings {
public static String BundlePath = null;
public static boolean OcrTextSearch = false;
public static boolean OcrTextRead = false;
+ public static String OcrLanguage = "eng";
/**
* true = start slow motion mode, false: stop it (default: false) show a visual for SlowMotionDelay seconds (default:
diff --git a/Libs/build/mac/runBuildNatives.sh b/Libs/build/mac/runBuildNatives.sh
index 2db5a34..7692244 100644
--- a/Libs/build/mac/runBuildNatives.sh
+++ b/Libs/build/mac/runBuildNatives.sh
@@ -9,7 +9,7 @@ export DEVNATIVE=../../../Natives/src/main/native
export DEVLIBS=../../src/main/resources/META-INF/libs/mac/libs$1
echo ----- create JNI header for MacUtil
-. runJNISetupForMacUtil.sh
+#. runJNISetupForMacUtil.sh
echo ----- build libMacUtil.dylib
. runBuildMacUtil.sh
@@ -17,13 +17,13 @@ echo ----- build libMacUtil.dylib
echo ----- create JNI header for MacHotkeyManager
#. runJNISetupForMacHotkeyManager.sh
-echo ----- build libMacHotkeyManager.dylib
-. runBuildMacHotkeyManager.sh
+echo ----- build libMacHotkeyManager.dylib
+#. runBuildMacHotkeyManager.sh
echo ----- use SWIG to create Java interface sources and native wrapper for VisionProxy
. runSwigForVision.sh
-echo ----- build libVisionProxy.dylib
+echo ----- build libVisionProxy.dylib
. runBuildVisionProxy.sh
echo ----- switch external refs to point to @loader_path/
diff --git a/Libs/src/main/resources/META-INF/libs/mac/libs64/libVisionProxy.dylib b/Libs/src/main/resources/META-INF/libs/mac/libs64/libVisionProxy.dylib
index 0b9ee18..3421956 100755
Binary files a/Libs/src/main/resources/META-INF/libs/mac/libs64/libVisionProxy.dylib and b/Libs/src/main/resources/META-INF/libs/mac/libs64/libVisionProxy.dylib differ
diff --git a/Libs/xbuild.xml b/Libs/xbuild.xml
index f9e9c15..863a66e 100644
--- a/Libs/xbuild.xml
+++ b/Libs/xbuild.xml
@@ -2,18 +2,18 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <groupId>org.sikuli</groupId>
- <artifactId>SikuliX</artifactId>
- <version>1.1.0</version>
- <relativePath>../</relativePath>
- </parent>
+ <groupId>org.sikuli</groupId>
+ <artifactId>SikuliX-Project</artifactId>
+ <version>1.1.0</version>
+ <relativePath>../</relativePath>
+ </parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.sikuli</groupId>
<artifactId>SikuliX-Libs</artifactId>
<version>1.1.0</version>
-
+
<profiles>
<profile>
<id>Windows</id>
@@ -35,7 +35,7 @@
<os>
<family>unix</family>
<arch>x86</arch>
- </os>
+ </os>
</activation>
<properties>
<buildfolder>build/linux</buildfolder>
@@ -89,7 +89,7 @@
</properties>
</profile>
</profiles>
-
+
<build>
<defaultGoal>install</defaultGoal>
<plugins>
@@ -114,7 +114,7 @@
</configuration>
</execution>
</executions>
- </plugin>
+ </plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
diff --git a/Natives/src/main/java/org/sikuli/natives/DebugCategories.java b/Natives/src/main/java/org/sikuli/natives/DebugCategories.java
index 66cd350..4bbea51 100644
--- a/Natives/src/main/java/org/sikuli/natives/DebugCategories.java
+++ b/Natives/src/main/java/org/sikuli/natives/DebugCategories.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/FindInput.java b/Natives/src/main/java/org/sikuli/natives/FindInput.java
index 6f62269..2f04b74 100644
--- a/Natives/src/main/java/org/sikuli/natives/FindInput.java
+++ b/Natives/src/main/java/org/sikuli/natives/FindInput.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/FindResult.java b/Natives/src/main/java/org/sikuli/natives/FindResult.java
index a713cf0..3f60ac3 100644
--- a/Natives/src/main/java/org/sikuli/natives/FindResult.java
+++ b/Natives/src/main/java/org/sikuli/natives/FindResult.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/FindResults.java b/Natives/src/main/java/org/sikuli/natives/FindResults.java
index d1e62dc..fbf7d72 100644
--- a/Natives/src/main/java/org/sikuli/natives/FindResults.java
+++ b/Natives/src/main/java/org/sikuli/natives/FindResults.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/Mat.java b/Natives/src/main/java/org/sikuli/natives/Mat.java
index 4e572c2..2de0271 100644
--- a/Natives/src/main/java/org/sikuli/natives/Mat.java
+++ b/Natives/src/main/java/org/sikuli/natives/Mat.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCR.java b/Natives/src/main/java/org/sikuli/natives/OCR.java
index 7eab2a4..8cf5cba 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCR.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCR.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRChar.java b/Natives/src/main/java/org/sikuli/natives/OCRChar.java
index dcb90db..13c66bc 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRChar.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRChar.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRChars.java b/Natives/src/main/java/org/sikuli/natives/OCRChars.java
index f2e3d63..d65748c 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRChars.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRChars.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRLine.java b/Natives/src/main/java/org/sikuli/natives/OCRLine.java
index 108488d..620ea8b 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRLine.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRLine.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRLines.java b/Natives/src/main/java/org/sikuli/natives/OCRLines.java
index 1e22ecb..155c503 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRLines.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRLines.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRParagraph.java b/Natives/src/main/java/org/sikuli/natives/OCRParagraph.java
index 30156b8..f6d1521 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRParagraph.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRParagraph.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRParagraphs.java b/Natives/src/main/java/org/sikuli/natives/OCRParagraphs.java
index 2cbcdd5..841d39b 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRParagraphs.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRParagraphs.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRRect.java b/Natives/src/main/java/org/sikuli/natives/OCRRect.java
index 5bd7082..6b084e7 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRRect.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRRect.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRText.java b/Natives/src/main/java/org/sikuli/natives/OCRText.java
index fa2ab49..64bb797 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRText.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRText.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRWord.java b/Natives/src/main/java/org/sikuli/natives/OCRWord.java
index 8202dba..0a2f6f4 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRWord.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRWord.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/OCRWords.java b/Natives/src/main/java/org/sikuli/natives/OCRWords.java
index 0354d8a..20f80e0 100644
--- a/Natives/src/main/java/org/sikuli/natives/OCRWords.java
+++ b/Natives/src/main/java/org/sikuli/natives/OCRWords.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/TARGET_TYPE.java b/Natives/src/main/java/org/sikuli/natives/TARGET_TYPE.java
index 58450c1..209e8d6 100644
--- a/Natives/src/main/java/org/sikuli/natives/TARGET_TYPE.java
+++ b/Natives/src/main/java/org/sikuli/natives/TARGET_TYPE.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/Vision.java b/Natives/src/main/java/org/sikuli/natives/Vision.java
index 055cc81..3ef624a 100644
--- a/Natives/src/main/java/org/sikuli/natives/Vision.java
+++ b/Natives/src/main/java/org/sikuli/natives/Vision.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
@@ -75,6 +75,14 @@ public class Vision {
return VisionProxyJNI.Vision_getParameter(param);
}
+ public static void setSParameter(String param, String val) {
+ VisionProxyJNI.Vision_setSParameter(param, val);
+ }
+
+ public static String getSParameter(String param) {
+ return VisionProxyJNI.Vision_getSParameter(param);
+ }
+
public Vision() {
this(VisionProxyJNI.new_Vision(), true);
}
diff --git a/Natives/src/main/java/org/sikuli/natives/VisionProxy.java b/Natives/src/main/java/org/sikuli/natives/VisionProxy.java
index e797a19..b7bb568 100644
--- a/Natives/src/main/java/org/sikuli/natives/VisionProxy.java
+++ b/Natives/src/main/java/org/sikuli/natives/VisionProxy.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
diff --git a/Natives/src/main/java/org/sikuli/natives/VisionProxyJNI.java b/Natives/src/main/java/org/sikuli/natives/VisionProxyJNI.java
index 1130de2..457dab0 100644
--- a/Natives/src/main/java/org/sikuli/natives/VisionProxyJNI.java
+++ b/Natives/src/main/java/org/sikuli/natives/VisionProxyJNI.java
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
+ * Version 2.0.12
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
@@ -144,6 +144,8 @@ public class VisionProxyJNI {
public final static native long Vision_createMat(int jarg1, int jarg2, byte[] jarg3);
public final static native void Vision_setParameter(String jarg1, float jarg2);
public final static native float Vision_getParameter(String jarg1);
+ public final static native void Vision_setSParameter(String jarg1, String jarg2);
+ public final static native String Vision_getSParameter(String jarg1);
public final static native long new_Vision();
public final static native void delete_Vision(long jarg1);
public final static native void setDebug(int jarg1, int jarg2);
diff --git a/Natives/src/main/native/Vision/vision.cpp b/Natives/src/main/native/Vision/vision.cpp
index 5ae3450..62332a6 100755
--- a/Natives/src/main/native/Vision/vision.cpp
+++ b/Natives/src/main/native/Vision/vision.cpp
@@ -9,12 +9,13 @@
#include "finder.h"
#include "tessocr.h"
//#include "imgdb.h" not used currently
-#include <sys/stat.h>
+#include <sys/stat.h>
using namespace sikuli;
std::map<std::string, float> Vision::_params;
+std::map<std::string, std::string> Vision::_sparams;
bool fileExists(const char* strFilename){
struct stat stFileInfo;
@@ -66,7 +67,7 @@ FindInput::FindInput(Mat source_, const FindInput other){
limit = other.limit;
}
-void
+void
FindInput::init(){
target_type = TARGET_TYPE_IMAGE;
target_text = "";
@@ -81,11 +82,11 @@ void FindInput::setSource(const char* source_filename){
}
void FindInput::setTarget(int target_type_, const char* target_string){
- target_type = target_type_;
- if (target_type == TARGET_TYPE_TEXT
+ target_type = target_type_;
+ if (target_type == TARGET_TYPE_TEXT
|| target_type == TARGET_TYPE_BUTTON){
target_text = target_string;
- } else if (target_type == TARGET_TYPE_IMAGE){
+ } else if (target_type == TARGET_TYPE_IMAGE){
if(fileExists(target_string))
target = cv::imread(target_string,1);
}
@@ -100,53 +101,53 @@ void FindInput::setTarget(Mat target_){
target = target_;
}
-Mat
+Mat
FindInput::getSourceMat(){
return source;
}
-Mat
+Mat
FindInput::getTargetMat(){
return target;
}
-int
+int
FindInput::getTargetType(){
return target_type;
}
-void
+void
FindInput::setFindAll(bool all){
bFindingAll = all;
}
-bool
+bool
FindInput::isFindingAll(){
return bFindingAll;
}
-void
+void
FindInput::setLimit(int limit_){
limit = limit_;
}
-int
+int
FindInput::getLimit(){
return limit;
}
-void
+void
FindInput::setSimilarity(double similarity_){
similarity = similarity_;
}
-double
+double
FindInput::getSimilarity(){
return similarity;
}
-std::string
+std::string
FindInput::getTargetText(){
return target_text;
}
@@ -154,23 +155,24 @@ FindInput::getTargetText(){
void
Vision::initOCR(const char* ocrDataPath) {
+ OCR::setParameter("lang", getSParameter("OCRLang"));
OCR::init(ocrDataPath);
}
//#include "cvgui.h" not used currently
#include "tessocr.h"
-static vector<FindResult>
+static vector<FindResult>
find_text(FindInput& input){
-
+
vector<FindResult> results;
-
+
Mat source = input.getSourceMat();
- if(!source.rows || !source.cols)
+ if(!source.rows || !source.cols)
return results;
-
+
TextFinder f(source);
if (input.isFindingAll()){
-
+
int maxReturn = Vision::getParameter("FindAllMaxReturn");
f.find_all(input.getTargetText().c_str(), input.getSimilarity());
while (f.hasNext() && results.size() < maxReturn){
@@ -182,30 +184,30 @@ find_text(FindInput& input){
if (f.hasNext())
results.push_back(f.next());
}
-
-
-/*
+
+
+/*
Mat result_image = source * 0.5;
for (vector<FindResult>::iterator it = results.begin();
it != results.end(); ++it){
-
+
FindResult& r = *it;
-
+
Point pt(r.x,r.y);
- putText(result_image, input.getTargetText(), pt,
+ putText(result_image, input.getTargetText(), pt,
FONT_HERSHEY_SIMPLEX, 0.3, Color::RED);
-
+
}
VisualLogger::setEnabled(enable_visual_log);
sualLogger::log("FindText-Result", result_image);
*/
-
+
return results;
}
-static vector<FindResult>
-find_image(FindInput& input){
+static vector<FindResult>
+find_image(FindInput& input){
vector<FindResult> results;
Mat source = input.getSourceMat();
Mat image = input.getTargetMat();
@@ -228,78 +230,78 @@ find_image(FindInput& input){
}
/* not used currently
-static vector<FindResult>
+static vector<FindResult>
find_button(FindInput& input){
-
+
vector<FindResult> results;
-
+
Mat screen = input.getSourceMat();
-
+
vector<Blob> blobs;
cvgui::findBoxes(screen, blobs);
-
-
+
+
VisualLogger::setEnabled(false);
-
+
for (vector<Blob>::iterator it = blobs.begin();
it != blobs.end(); ++it){
Blob& blob = *it;
-
-
+
+
if (blob.width < 10)
continue;
-
+
Util::growRect(blob, -3, 0, screen);
-
+
Mat blob_image(screen, blob);
-
- FindResult result(blob.x,blob.y,blob.width,blob.height,1);
+
+ FindResult result(blob.x,blob.y,blob.width,blob.height,1);
result.text = Vision::recognize(blob_image);
-
+
if (result.text.empty())
continue;
-
-
+
+
string target_text = input.getTargetText();
if (!target_text.empty()){
-
+
int d;
d = OCR::findEditDistance(target_text.c_str(),
result.text.c_str(),
3);
-
+
if (d < 2){
- results.push_back(result);
+ results.push_back(result);
}
}else{
results.push_back(result);
}
-
+
// if we only need to find one result, and we already have one result
if (!input.isFindingAll() && !results.empty()){
break;
}
-
+
}
-
-
+
+
Mat result_image = screen * 0.5;
for (vector<FindResult>::iterator it = results.begin();
it != results.end(); ++it){
-
+
FindResult& r = *it;
-
+
Point pt(r.x,r.y);
- putText(result_image, r.text, pt,
+ putText(result_image, r.text, pt,
FONT_HERSHEY_SIMPLEX, 0.3, Color::RED);
-
-
-
+
+
+
}
-
+
VisualLogger::setEnabled(enable_visual_log);
VisualLogger::log("Buttons-OCR", result_image);
-
+
return results;
}
*/
@@ -309,37 +311,37 @@ find_button(FindInput& input){
double
Vision::compare(Mat im1, Mat im2){
-
+
Mat gray1;
Mat gray2;
-
+
// convert image from RGB to grayscale
cvtColor(im1, gray1, CV_RGB2GRAY);
cvtColor(im2, gray2, CV_RGB2GRAY);
-
+
Mat diff1;
absdiff(gray1,gray2,diff1);
-
+
typedef uchar T;
Size size = diff1.size();
-
+
int diff_cnt = 0;
for( int i = 0; i < size.height; i++ )
{
const T* ptr1 = diff1.ptr<T>(i);
for( int j = 0; j < size.width; j += 4 )
- {
+ {
if (ptr1[j] > PIXEL_DIFF_THRESHOLD)
diff_cnt++;
}
}
-
+
// ratio of pixels that are different
double score = 1.0 * diff_cnt / (im1.rows * im1.cols);
return score;
}
-vector<FindResult>
+vector<FindResult>
Vision::find(FindInput input){
vector<FindResult> results;
if (input.getTargetType() == TARGET_TYPE_IMAGE ||
@@ -359,7 +361,7 @@ Vision::find(FindInput input){
return final_results;
}
-vector<FindResult>
+vector<FindResult>
Vision::findChanges(FindInput input){
vector<FindResult> results;
Mat source = input.getSourceMat();
@@ -368,7 +370,7 @@ Vision::findChanges(FindInput input){
f.find(image);
while (f.hasNext() && (results.size() < input.getLimit())){
results.push_back(f.next());
- }
+ }
vector<FindResult> final_results;
int n = input.getLimit();
if(n < results.size()){
@@ -395,27 +397,27 @@ Vision::recognize(Mat image){
/* not used currently
string
Vision::query(const char* index_filename, cv::Mat image){
-
- Database db;
+
+ Database db;
ifstream in(index_filename, ios::binary);
db.read(in);
in.close();
-
-
+
+
string ret = "";
-
- vector<ImageRecord> results = db.find(image);
- for (vector<ImageRecord>::iterator r = results.begin();
+
+ vector<ImageRecord> results = db.find(image);
+ for (vector<ImageRecord>::iterator r = results.begin();
r != results.end(); ++r){
-
+
ImageRecord& record = *r;
-
+
//cout << "ui" << record.id << " ";
char buf[50];
sprintf(buf,"ui%d",record.id);
ret = ret + string(buf) + " ";
}
-
+
return ret;
}
*/
@@ -434,29 +436,29 @@ Vision::findTextBlobs(const cv::Mat& image){
vector<FindResult>
Vision::findBlobs(const cv::Mat& image, bool textOnly){
-
+
vector<FindResult> results;
vector<Blob> out_text_blobs;
vector<Blob> out_img_blobs;
-
+
cvgui::segmentScreenshot(image, out_text_blobs, out_img_blobs);
-
-
+
+
for (vector<Blob>::iterator i = out_text_blobs.begin();
i != out_text_blobs.end(); ++i){
-
+
Blob& b = *i;
FindResult fr(b.x,b.y,b.width,b.height,1);
results.push_back(fr);
}
-
+
if(!textOnly){
- for (vector<Blob>::iterator i = out_img_blobs.begin();
+ for (vector<Blob>::iterator i = out_img_blobs.begin();
i != out_img_blobs.end(); ++i){
Blob& b = *i;
- FindResult fr(b.x,b.y,b.width,b.height,1);
- results.push_back(fr);
+ FindResult fr(b.x,b.y,b.width,b.height,1);
+ results.push_back(fr);
}
}
@@ -482,7 +484,6 @@ void Vision::setParameter(string param, float val){
void Vision::initParameters(){
_params["MinTargetSize"] = DEFAULT_PYRAMID_MIM_TARGET_DIMENSION;
_params["FindAllMaxReturn"] = DEFAULT_FIND_ALL_MAX_RETURN;
-
}
float Vision::getParameter(string param){
@@ -490,3 +491,20 @@ float Vision::getParameter(string param){
Vision::initParameters();
return _params[param];
}
+
+void Vision::setSParameter(string param, string val){
+ if(_sparams.empty())
+ Vision::initSParameters();
+ _sparams[param] = val;
+}
+
+void Vision::initSParameters(){
+ _sparams["OCRLang"] = "eng";
+ _sparams["OCRDataPath"] = "tessdata";
+}
+
+string Vision::getSParameter(string param){
+ if(_sparams.empty())
+ Vision::initSParameters();
+ return _sparams[param];
+}
diff --git a/Natives/src/main/native/Vision/vision.h b/Natives/src/main/native/Vision/vision.h
index f4d93a8..6cb8fd5 100755
--- a/Natives/src/main/native/Vision/vision.h
+++ b/Natives/src/main/native/Vision/vision.h
@@ -11,32 +11,32 @@
#include "find-result.h"
#include "opencv.hpp"
#include "tessocr.h"
-//#include "cvgui.h" not used
+//#include "cvgui.h" not used
using namespace cv;
namespace sikuli {
-
+
enum TARGET_TYPE{
TARGET_TYPE_MAT,
TARGET_TYPE_IMAGE,
TARGET_TYPE_TEXT,
TARGET_TYPE_BUTTON
};
-
+
class FindInput{
-
+
public:
-
+
FindInput();
FindInput(Mat source, Mat target);
FindInput(Mat source, int target_type, const char* target);
-
+
FindInput(const char* source_filename, int target_type, const char* target);
-
+
FindInput(Mat source, int target_type);
FindInput(const char* source_filename, int target_type);
-
+
// copy everything in 'other' except for the source image
FindInput(Mat source, const FindInput other);
@@ -45,66 +45,68 @@ public:
void setSource(Mat source);
void setTarget(Mat target);
-
+
Mat getSourceMat();
Mat getTargetMat();
-
+
void setFindAll(bool all);
bool isFindingAll();
void setLimit(int limit);
int getLimit();
-
+
void setSimilarity(double similarity);
double getSimilarity();
-
+
int getTargetType();
-
+
std::string getTargetText();
-
+
private:
-
+
void init();
-
+
Mat source;
Mat target;
std::string target_text;
-
+
int limit;
double similarity;
int target_type;
-
+
int ordering;
int position;
-
+
bool bFindingAll;
};
class Vision{
static std::map<std::string, float> _params;
- static void initParameters();
+ static std::map<std::string, std::string> _sparams;
+ static void initParameters();
+ static void initSParameters();
public:
-
+
static std::vector<FindResult> find(FindInput q);
static std::vector<FindResult> findChanges(FindInput q);
-
+
static double compare(cv::Mat m1, cv::Mat m2);
-
+
static void initOCR(const char* ocrDataPath);
-
-
+
+
// not used currently
static string query(const char* index_filename, cv::Mat image);
-
+
static OCRText recognize_as_ocrtext(cv::Mat image);
-
+
// not used currently
static std::vector<FindResult> findBlobs(const cv::Mat& image, bool textOnly=false);
// not used currently
static std::vector<FindResult> findTextBlobs(const cv::Mat& image);
-
+
static std::string recognize(cv::Mat image);
static std::string recognizeWord(cv::Mat image);
@@ -113,9 +115,11 @@ public:
static void setParameter(std::string param, float val);
static float getParameter(std::string param);
+ static void setSParameter(std::string param, std::string val);
+ static std::string getSParameter(std::string param);
+
+private:
-private:
-
};
}
diff --git a/Natives/src/main/native/Vision/vision.swig b/Natives/src/main/native/Vision/vision.swig
index bfaef5a..dc75b5e 100755
--- a/Natives/src/main/native/Vision/vision.swig
+++ b/Natives/src/main/native/Vision/vision.swig
@@ -4,7 +4,7 @@
#include "sikuli-debug.h"
#include <iostream>
#include "opencv.hpp"
-//#include "cvgui.h" not used
+//#include "cvgui.h" not used
#include "tessocr.h"
%}
@@ -219,6 +219,8 @@ namespace sikuli {
static void setParameter(std::string param, float val);
static float getParameter(std::string param);
+ static void setSParameter(std::string param, std::string val);
+ static std::string getSParameter(std::string param);
private:
diff --git a/Natives/src/main/native/Vision/visionJAVA_wrap.cxx b/Natives/src/main/native/Vision/visionJAVA_wrap.cxx
index a289a5e..4867239 100755
--- a/Natives/src/main/native/Vision/visionJAVA_wrap.cxx
+++ b/Natives/src/main/native/Vision/visionJAVA_wrap.cxx
@@ -1,11 +1,11 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.7
- *
- * This file is not intended to be easily readable and contains a number of
+ * Version 2.0.12
+ *
+ * This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
+ * changes to this file unless you know what you are doing--modify the SWIG
+ * interface file instead.
* ----------------------------------------------------------------------------- */
#define SWIGJAVA
@@ -65,28 +65,28 @@ template <typename T> T SwigValueInit() {
#ifndef SWIGUNUSED
# if defined(__GNUC__)
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
-# define SWIGUNUSED __attribute__ ((__unused__))
+# define SWIGUNUSED __attribute__ ((__unused__))
# else
# define SWIGUNUSED
# endif
# elif defined(__ICC)
-# define SWIGUNUSED __attribute__ ((__unused__))
+# define SWIGUNUSED __attribute__ ((__unused__))
# else
-# define SWIGUNUSED
+# define SWIGUNUSED
# endif
#endif
#ifndef SWIG_MSC_UNSUPPRESS_4505
# if defined(_MSC_VER)
# pragma warning(disable : 4505) /* unreferenced local function has been removed */
-# endif
+# endif
#endif
#ifndef SWIGUNUSEDPARM
# ifdef __cplusplus
# define SWIGUNUSEDPARM(p)
# else
-# define SWIGUNUSEDPARM(p) p SWIGUNUSED
+# define SWIGUNUSEDPARM(p) p SWIGUNUSED
# endif
#endif
@@ -129,7 +129,7 @@ template <typename T> T SwigValueInit() {
# define SWIGSTDCALL __stdcall
# else
# define SWIGSTDCALL
-# endif
+# endif
#endif
/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
@@ -215,7 +215,7 @@ static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionC
#include "sikuli-debug.h"
#include <iostream>
#include "opencv.hpp"
-//#include "cvgui.h" not used
+//#include "cvgui.h" not used
#include "tessocr.h"
@@ -2484,6 +2484,53 @@ SWIGEXPORT jfloat JNICALL Java_org_sikuli_natives_VisionProxyJNI_Vision_1getPara
}
+SWIGEXPORT void JNICALL Java_org_sikuli_natives_VisionProxyJNI_Vision_1setSParameter(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2) {
+ std::string arg1 ;
+ std::string arg2 ;
+
+ (void)jenv;
+ (void)jcls;
+ if(!jarg1) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
+ return ;
+ }
+ const char *arg1_pstr = (const char *)jenv->GetStringUTFChars(jarg1, 0);
+ if (!arg1_pstr) return ;
+ (&arg1)->assign(arg1_pstr);
+ jenv->ReleaseStringUTFChars(jarg1, arg1_pstr);
+ if(!jarg2) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
+ return ;
+ }
+ const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0);
+ if (!arg2_pstr) return ;
+ (&arg2)->assign(arg2_pstr);
+ jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
+ sikuli::Vision::setSParameter(arg1,arg2);
+}
+
+
+SWIGEXPORT jstring JNICALL Java_org_sikuli_natives_VisionProxyJNI_Vision_1getSParameter(JNIEnv *jenv, jclass jcls, jstring jarg1) {
+ jstring jresult = 0 ;
+ std::string arg1 ;
+ std::string result;
+
+ (void)jenv;
+ (void)jcls;
+ if(!jarg1) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
+ return 0;
+ }
+ const char *arg1_pstr = (const char *)jenv->GetStringUTFChars(jarg1, 0);
+ if (!arg1_pstr) return 0;
+ (&arg1)->assign(arg1_pstr);
+ jenv->ReleaseStringUTFChars(jarg1, arg1_pstr);
+ result = sikuli::Vision::getSParameter(arg1);
+ jresult = jenv->NewStringUTF((&result)->c_str());
+ return jresult;
+}
+
+
SWIGEXPORT jlong JNICALL Java_org_sikuli_natives_VisionProxyJNI_new_1Vision(JNIEnv *jenv, jclass jcls) {
jlong jresult = 0 ;
sikuli::Vision *result = 0 ;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/sikuli.git
More information about the pkg-java-commits
mailing list