Checking for a picture faster

Asked by layanor

https://gyazo.com/3946c51e2e658c1fb5b38eeda6c4a100

I have two pictures that need to be watched for every second "Player1 Player2". The way I have them set up now almost works but sometimes is too late to recognize the pictures. How do I shave off more time?

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#1

Nobody know which line of code you want to make faster.
You should confirm response time each line of codes, and decide which line of code you want to do faster.

Revision history for this message
Manfred Hampl (m-hampl) said :
#2

A general hint:
The smaller the region where you search for the image, the faster the search.

E.g. If you know that the green or red bar for the winner is always shown on a specific position, then define a region around this position endregion=Region(x,y,w,h) and do a endregion.exists(...) instead of searching the whole screen with exists(...).

Revision history for this message
layanor (layanor) said :
#3

Where do I get the location numbers?

Revision history for this message
layanor (layanor) said :
#4

Okay I got the numbers. Now I need to know how to put in the code the correct way.

https://gyazo.com/9fa5117497acd769ccc54593a7ac2c27

This does not work.

Revision history for this message
Manfred Hampl (m-hampl) said :
#5

1. A statement like "This does not work." does not stimulate anybody to help further. Can't you tell what happens if you try?

2. It seems that my wording was not clear enough, and you misunderstood my intentions.
Whenever you search for an image (including a click action which also does an search) , make the region where the search is executed as small as possible, and also make the image to search for as small as possible, but big enough that it is not inadvertently found elsewhere inside the search region.
This is relevant not only for the "endregion", but also for all other click (Set winner option...) actions.

The way that you did your region definition is counterproductive, because you do it with another search inside the loop, and this will probably even slow down the script.

My suggestion:
define the region where the green or red bar appears outside the while loop, and not by searching for an image but by giving coordinates - and as small as possible.
If possible do the same for the region where "set winner option" will appear, and if possible also for the "yes" boxes.

I understood that the winner is announced by either a green or a red bar on a certain location on the screen.
I do not see the need to search for the complete red/green bar across the whole screen, maybe it is sufficient to check a small part of the area where that bar appears for red respectively green color.

Revision history for this message
layanor (layanor) said :
#6

https://gyazo.com/399c349648eee103c1ff7b53a2f2c6e1

Is this more of what you were saying?

Revision history for this message
layanor (layanor) said :
#7

Why is there no way to edit comments here past the first question?

Anyway...

In the region palyer1 and player2 i took a small sample of the green and red bars. It aborts at line 4 so I am not sure why it stops.

Revision history for this message
Manfred Hampl (m-hampl) said :
#8

I do not see the definition of endregion in your latest script.

I assume the following might work:

Settings.MoveMouseDelay(0.0)
endregion = Region (400, 30, 100, 50) # adapt the numbers to have a rectangle where the green or red bar will appear (the smallest reasonable one)
winnerregion=Region (500, 100, 100, 50) # adapt the numbers to have a rectangle where the "Set winner option" button will appear
yesregion=Region (600, 100, 100, 50) # adapt the numbers to have a rectangle where the "yes" button will appear

while True:
 setAutoWaitTimeout(0.1)
 player1 = endregion.exists("greenbar.jpg")
 player2 = endregion.exists("redbar.jpg")

 if player2:
  setAutoWaitTimeout(0.0)
  winnerregion.click(set winner option image 1)
  winnerregion.click(set winner option image 2)
  wait (6.0)
  if yesregion.exists(yes image)
    click()
    wait (5.0)
  continue
...

Revision history for this message
layanor (layanor) said :
#9

https://gyazo.com/2069c5350ce885ed80fd80f089159a38

We have made great progress!

I did not set up the rest of the code yet as you suggested. I just set up the green and red bars so I could contact you quickly.

The code is now working almost instantly when looking for these bars and that is great! However, both bars trigger Player2 actions and never Player1 actions.

Are we missing something?

Revision history for this message
Manfred Hampl (m-hampl) said :
#10

I do not have the program that you want to control, so I cannot really tell why your script is not doing what you expect.
You have to do some debugging yourself, and eventually do some further fine tuning.

Some ideas:
Check whether only player1 image is found or only player2 image or both

Maybe you have to increase the minimum similarity before the "playerX = endregion.exists(...)" statements by insering a
Settings.MinSimilarity = 0.8 #(or any other suitable value)
line.

Revision history for this message
layanor (layanor) said :
#11

https://gyazo.com/6b7574aacfbf7db7c54c7d8efd78cf5a

I have been working on this over the last few days.

The fighting game is something I have made myself. I am able to change the green and red trigger images. So I changed them to blue and red. Then made them much smaller.

I set up the region again and the code can see these images.

Still, for some weird reason, Player 1 and Player 2 still get switched at times.

The code is slow again even when adding in MinSimilarity

Even with the progress I had, it seems I have made it worse while adjusting it.

Revision history for this message
Manfred Hampl (m-hampl) said :
#12

Changing MinSimilarity will not help making processing of the script faster.
Key for speeding up the script is making the endregion and selectregion as small as possible.

Revision history for this message
layanor (layanor) said :
#13

https://www.youtube.com/watch?v=s5P8N0ZMBVo

I split up the code into different projects so I can work on them one at a time. This is a video to show you how it looks. I have everything very small and looking good.

I realize now that I put this all into the same project "FightBot" that this script will slow down. Do you have any suggestions on any of it as I rebuild this into one script?

Revision history for this message
layanor (layanor) said :
#14

https://gyazo.com/deb1c6d766678df409c04c1a6527521d

Each of the 4 sections of code now works and are fast. But the issue I thought I would have has happened. It is slow again with all four in one code.

All region pics are now super small and the larger buttons can be smaller but I didn't see reason to do that with them as those were always fast and only get triggered when the code needs to call on them

Also, there is an issue now where I believe parts of the code is looping. I have tried to continue and break commands but it seems these do not work and just either crash the code or the code ends with no errors.

Revision history for this message
Launchpad Janitor (janitor) said :
#15

This question was expired because it remained in the 'Open' state without activity for the last 15 days.