~ubuntu-branches/ubuntu/utopic/sikuli/utopic

« back to all changes in this revision

Viewing changes to sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java

  • Committer: Package Import Robot
  • Author(s): Gilles Filippini
  • Date: 2012-02-15 15:17:58 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20120215151758-0waq2g0irnska3jf
Tags: 1.0~x~rc3.tesseract3-dfsg1-1
* Merge with the feature/tesseract3 branch from upstream
* debian/control: Build-Depends: libtesseract-dev instead of
  deprecated tesseract-ocr-dev (Closes: #659598)
* The upstream source code repository moved to github

* New patch:
  + tess3.patch:
    - Fix build with tesseract3
    - use OCR strategie OEM_TESSERACT_ONLY for now. Upstream has
      reported a 4x slowdown when using OEM_TESSERACT_CUBE_COMBINED
* Patch fix-cmake-sikuli-ide.patch:
  + Add a DEP3 style description
* debian/copyright:
  + Update DEP5 Format URL
  + Bump copyright years

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
import java.io.*;
10
10
import java.net.URL;
11
11
import java.util.Enumeration;
 
12
import java.util.List;
 
13
import java.util.LinkedList;
12
14
 
13
15
import org.sikuli.script.natives.Mat;
14
16
import org.sikuli.script.natives.Vision;
 
17
import org.sikuli.script.natives.OCRWord;
 
18
import org.sikuli.script.natives.OCRWords;
15
19
 
16
20
// Singleton
17
21
public class TextRecognizer {
59
63
      return _instance;
60
64
   }
61
65
 
 
66
   public enum ListTextMode {
 
67
      WORD, LINE, PARAGRAPH
 
68
   };
 
69
 
 
70
   public List<Match> listText(ScreenImage simg, Region parent){
 
71
      return listText(simg, parent, ListTextMode.WORD);
 
72
   }
 
73
 
 
74
   //TODO: support LINE and PARAGRAPH
 
75
   // listText only supports WORD mode now.
 
76
   public List<Match> listText(ScreenImage simg, Region parent, ListTextMode mode){
 
77
      Mat mat = OpenCV.convertBufferedImageToMat(simg.getImage());
 
78
      OCRWords words = Vision.recognize_as_ocrtext(mat).getWords();
 
79
      List<Match> ret = new LinkedList<Match>();
 
80
      for(int i=0;i<words.size();i++){
 
81
         OCRWord w = words.get(i);
 
82
         Match m = new Match(parent.x+w.getX(), parent.y+w.getY(), w.getWidth(), w.getHeight(), 
 
83
                             w.getScore(), parent.getScreen(), w.getString());
 
84
         ret.add(m);
 
85
      }
 
86
      return ret;
 
87
   }
 
88
 
 
89
 
62
90
   public String recognize(ScreenImage simg){
63
91
      BufferedImage img = simg.getImage();
64
92
      return recognize(img);
67
95
   public String recognize(BufferedImage img){
68
96
      if (_init_succeeded){
69
97
         Mat mat = OpenCV.convertBufferedImageToMat(img);
70
 
         return Vision.recognize(mat);
 
98
         return Vision.recognize(mat).trim();
 
99
      }else{
 
100
         return "";
 
101
      }
 
102
   }
 
103
 
 
104
   public String recognizeWord(ScreenImage simg){
 
105
      BufferedImage img = simg.getImage();
 
106
      return recognizeWord(img);
 
107
   }
 
108
 
 
109
   public String recognizeWord(BufferedImage img){
 
110
      if (_init_succeeded){
 
111
         Mat mat = OpenCV.convertBufferedImageToMat(img);
 
112
         return Vision.recognizeWord(mat).trim();
71
113
      }else{
72
114
         return "";
73
115
      }