Get text from screen in sikuli using offset

Asked by Mohammed Shehzan

Is there any way to read text next to an image match on the screen? I mean say I have an image img.png, is it possible for me to first find a match for this on screen and then get the text to the right of this up to a fixed distance?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
j (j-the-k) said :
#1

Use this:

find("img.png").right(100).text()

to extract the text that is in the area on the right of your image, with width 100px.
You can also use left(), below() or above() to search in other directions.

Be aware that text recognition is in many cases not precise.

Revision history for this message
j (j-the-k) said :
#2

Addition:
of course you have to assign the result to a variable, so it's

foundText = find("img.png").right(100).text()

And you should use foundText = foundText.strip() afterwards to get rid of any unwanted leading or trailing white spaces.

Revision history for this message
Slash31 (gsoundar31) said :
#3

I integrated Selenium with Sikuli and I'm trying to get text from an image but I'm not able to fetch. Here is my code.

  String text = screen.find( ".//SikuliSnapshots//HBOGO//Preview.png";).text();
  String Finaltext = text.trim();
  System.out.println(Finaltext);

Text is always null.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

*** Text is always null.
I guess you mean "empty", since the sequence (the extra ; is a typo???)
screen.find( ".//SikuliSnapshots//HBOGO//Preview.png").text();

should either throw a FindFailed or return a string (which might contain only whitespace), but never Java null.

If I am right, then the given text simply cannot be read with the current Sikuli X (there are many problems with OCR).

Revision history for this message
Rishabh Sharma (rish411) said :
#5

I have integrated sikuli with open script and I am also applying the same Code for capturing the text from application but its giving an error as :

String foundText;
foundText = find("img.png").right(100).text();

The method find(String) is undefined for the type script

Revision history for this message
Rishabh Sharma (rish411) said :
#6

The above error is resolved but while running i am getting this error.

OrderNumber.png looks like a file, but can't be found on the disk. Assume it's text.

Revision history for this message
Rishabh Sharma (rish411) said :
#7

?

Can you help with this problem?

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

To post a message you must log in.