Getting error Region.text: text recognition is currently switched off

Asked by ashish on 2017-12-20

I have written a small code to read a text from an excel file but getting error

Code : public static void main(String[] args) throws FindFailed, InterruptedException {
  Screen screen = new Screen();
  Thread.sleep(5000);
  Region r = screen.find("C:\\Users\\KHANDELA1\\Pictures\\AssetName_excel.PNG").below(20);
  screen.hover(r);
  String read = r.text();
System.out.println("read"+read);

Error : [error] Region.text: text recognition is currently switched off
read--- no text ---

The solutions which i found are asking to set Settings.OcrTextRead=true .

But where exactly do I set this in the code. I set in my java code in eclipse it gives the error.

Please help

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-12-21
Last reply:
2017-12-21
RaiMan (raimund-hocke) said : #1

put it before you touch any SikuliX feature in your code

for example:

public static void main(String[] args) throws FindFailed, InterruptedException {
  Settings.OcrTextRead=true;
  Screen screen = new Screen();
  Thread.sleep(5000);
  Region r = screen.find("C:\\Users\\KHANDELA1\\Pictures\\AssetName_excel.PNG").below(20);
  screen.hover(r);
  String read = r.text();
  System.out.println("read"+read);

Be aware: the text feature has many problems and might not deliver what you expect.

Better use a library, that allows, to read XLS files directly (https://www.mkyong.com/java/apache-poi-reading-and-writing-excel-file-in-java/)

ashish (ashishkhandelwal) said : #2

Thanks for response.

I put the code as you have given above but apologize for my limited java knowledge the line Settings.OcrTextRead=true; gives error and is giving error as 'Settings.OcrTextRead cannot be resolved to a type' and suggesting solutions like
1) create a class Settings
2) create an interface Settings.

Please help as what to do.

I am trying to use OCR as opposed to Apache POI as I have to read data from both an XLS file and a PDF

RaiMan (raimund-hocke) said : #3

But why are you then working with Java in the first place? any reason?

Try out things in the SikuliX IDE and if you think, you can use the features, you might try to implement it in Java.

BTW: with SikuliX IDE xlrd is bundled (access XLS).

Generally I do not understand why people go the stony visual way with these problems. There are many free tools out there, to convert XLS and PDF to forms, that can be better read programmatically.

RaiMan (raimund-hocke) said : #4

your class Settings problem:

look for the Settings class in the sikulixapi and import it (basic Java knowledge - sorry).

Can you help with this problem?

Provide an answer of your own, or ask ashish for more information if necessary.

To post a message you must log in.