[Java] FindFailed with Pattern().similar(0.7) on the screen

Asked by Naveen

I am trying to execute the following block of code
Pattern imgPattern= new Pattern("E:\\TestSikuli\\nav.JPG");
    Rectangle rect= new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    Region region= new Region(rect);
    Screen screen=(Screen) region.getScreen();
I am getting the following exception FindFailed: can not find Pattern("E:\TestSikuli\nav.JPG").similar(0.7) on the screen.
Line ?, in File ?
 at org.sikuli.script.Region.handleFindFailed(Region.java:420)
 at org.sikuli.script.Region.wait(Region.java:511)
 at org.sikuli.script.Region.find(Region.java:381)
 at org.sikuli.script.Region.getLocationFromPSRML(Region.java:1129)
 at org.sikuli.script.Region.click(Region.java:606)
 at org.sikuli.script.Region.click(Region.java:593)
 at com.SampleRead.main(SampleRead.java:37)

**I am using windows7 , Java 6 .

Please let me know if anything is needed .

Any help in this regard is very much appreciated .

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
RaiMan (raimund-hocke) said :
#1

The usual way to do this is:
Screen scr = new Screen();
Match m = scr.find("E:\\TestSikuli\\nav.JPG");

But is it really a JPG file?

Sikuli in the standard uses .png files, I am not sure, wether JPG's work too.

Revision history for this message
Naveen (naveennannapaneni1) said :
#2

Hi Raiman !
Thnx for the swift response . I have chnged my code like this :

Screen screen= new Screen();

    try{
     Match match=screen.find("E:\\TestSikuli\\nav.png");

     screen.click(match);

(I have even chnged the type of the image)

Still I end up getting the following error :

FindFailed: can not find E:\TestSikuli\nav.png on the screen.
Line ?, in File ?
 at org.sikuli.script.Region.handleFindFailed(Region.java:420)
 at org.sikuli.script.Region.wait(Region.java:511)
 at org.sikuli.script.Region.find(Region.java:381)
 at com.SampleRead.main(SampleRead.java:31)

Please Help!

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

Ok, then this means:

your image E:\TestSikuli\nav.png is not visible (or cannot be matched caused by other reasons) on the screen in the moment, the find operation is processed.

Another possibility is to just try out the

find("E:\\TestSikuli\\nav.png")

in Sikuli IDE, only to be sure.

Revision history for this message
Naveen (naveennannapaneni1) said :
#4

Raiman !
I have tried the following snippet from the sikuli IDE

find("E:\\TestSikuli\\nav.png")

The following is the stack trace I have encountered with :

[error] nav.png looks like a file, but can't be found on the disk. Assume it's text.
[info] Text Recognizer inited.

[error] Stopped
[error] An error occurs at line 2
[error] Error message: Traceback (most recent call last):
 File "C:\Users\USER\AppData\Local\Temp\sikuli-tmp7981583417362119709.py", line 2, in
 find("nav.png")
Line 3, in file C:\Users\USER\AppData\Local\Temp\sikuli-tmp7981583417362119709.py

 at org.sikuli.script.Region.handleFindFailed(Region.java:420)
at org.sikuli.script.Region.wait(Region.java:511)
at org.python.proxies.sikuli.Region$Region$0.super__wait(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

org.sikuli.script.FindFailed: FindFailed: can not find nav.png on the screen.
 Line 3, in file C:\Users\USER\AppData\Local\Temp\sikuli-tmp7981583417362119709.py

Please suggest !

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

check that the image is really stored at:

E:\TestSikuli\nav.png

and that the access rights are sufficient.

Can you help with this problem?

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

To post a message you must log in.