Image reconition not working after using screen.setRect() --- screen needs to be reset to whole screen

Asked by Mohammed Saquib

Installed using 2 & 3 option checked

Settings.OcrTextRead = true;
   Settings.OcrTextSearch = true;

   for(int i = 0; i < 4; i++) {
    Thread.sleep(3000);
    Rectangle rectangle = new Rectangle(500, 550+(i*25), 75, 20);
    screen.setRect(rectangle);
    String xx= screen.text();
    xx= xx.substring(1);
    System.out.println("$"+xx);
   }

   Settings.OcrTextRead = false;
   Settings.OcrTextSearch = false;
   Pattern scrollDown = new Pattern(iconPath + "scrolldown.png");
   screen.mouseMove(scrollDown);
   screen.click();

FindFailed: D:/Users/xxxx/xxxxxx/images/scrolldown.png: (74x21) in S(0)[0,0 1366x768] E:Y, T:3.0
  Line 2759, in file Region.java

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 problem is this:
screen.setRect(rectangle);

which means that on the screen it is searched only in the given rectangle.

after the loop, you have to reset the screen object:
screen = new Screen()

to restore to the whole screen.

generally it is not recommended to use screen.setRect(), since this may lead to such quirks if not reset and may be hard to debug.

--- better:
for(int i = 0; i < 4; i++) {
    Thread.sleep(3000);
    //Rectangle rectangle = new Rectangle(500, 550+(i*25), 75, 20);
    Region reg = new Region(500, 550+(i*25), 75, 20);
    //screen.setRect(rectangle);
    //String xx= screen.text();
    String xx= reg.text();
    xx= xx.substring(1);
    System.out.println("$"+xx);
   }

Can you help with this problem?

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

To post a message you must log in.