Preformer
Preformer

Reputation: 37

Finding images on screen

I'm a rookie java learner. I'm trying to develop a bot (or trainer, whatever) for a simple mini-game, I need to analyze the screen for images and press the corresponding action. Therefore: -

I first tried to use sikuli ScreenRegion for this, but it didn't quite go as expected. What I tried was something like this: -

if(arrowSet.find(oneDown)!=null)
{
    r.keyPress(KeyEvent.VK_DOWN);
    r.keyRelease(KeyEvent.VK_DOWN);
    r.delay(20);
} 

But it just jumped to the action, even if the condition was false. Is my application of ScreenRegion wrong in this situation? Or should I use something different than sikuli?

Upvotes: 1

Views: 3144

Answers (2)

Preformer
Preformer

Reputation: 37

Figured it out, guys! Seems like the image recognition of sikuli is fuzzy. It wont work with targetImage.setMinRank(1.00) wont work, but when I tried running the program with targetImage.setMinRank(0.99), it all worked fluidly. Thank you for you help.

Upvotes: 2

Tytus
Tytus

Reputation: 648

If using Java is not required and you work under Windows, you might consider using Automa - Python tool/library for UI automation. It allows operations on images.

For example, to find out whether an image exists on screen:

Image("arrow_screenshot1.png").exists() # returns True or False

To click on an image:

click(Image("arrow_screenshot1.png"))

To find out image coordinates/center:

Image("arrow_screenshot1.png").x # returns x-coordinate
Image("arrow_screenshot1.png").y # returns y-coordinate
Image("arrow_screenshot1.png").center # returns Point object

To wait until an image appears on the screen:

wait_until(Image("arrow_screenshot1.png").exists)

etc.

I think that using Automa you can quite easily achieve what you need!

Disclaimer: I'm one of Automa's developers

Upvotes: 4

Related Questions