Image Recognition Script Help Needed

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Sam71
Junior Coder
Posts: 23
Joined: Tue Mar 12, 2019 10:10 pm

Image Recognition Script Help Needed

Post by Sam71 » Sat Mar 30, 2019 1:03 am

Hi,
I have a script which is using both FindImage and Waitscreen to look for one of two images that will appear.
FindImagePos/image_2 & WaitScreenImage/image_1 work fine in the loop, however when FindImagePos/image_4 appears it skips to WaitScreenImage/image_1 and of course it wont find it because its already found image_4 so its stuck in limbo searching for image_1.

I found that its doing this because the script is reacting faster than screen updates. I can get around this by using the wait function at line 17-18 but I would much prefer to have the wait function only used for FindImagePos/image_4.

I hope this makes sense. If anyone has any suggestions I would appreciate your reply.

Code: Select all

1 // Test Script
2	SetFocus>Application01
3
4	Label>start
5
6	//Find image_2
7	FindImagePos>%BMP_DIR%\image_2.bmp,WINDOW:Application01,0.7,1,XArr,YArr,NumFound,CCOEFF
8	If>NumFound>0
9	  HoldKey>v,50,0
10	  Wait>0.900
11	  HoldKey>a,50,0
12	  Wait>0.900
13	  HoldKey>g,50,0
14	  Wait>0.900
15	  HoldKey>t,50,0 - // Search can take 1-6 seconds
16	Endif
17
18
19	//Find Image_4
20	FindImagePos>%BMP_DIR%\image_4.bmp,WINDOW:Application01,0.7,1,XArr,YArr,NumFound,CCOEFF
21	If>NumFound>0
22	  HoldKey>v,50,0
23	  Wait>0.500
24	  HoldKey>s,50,0
25	  Wait>0.500
26	Endif
27
28
29	//Wait for 
30	WaitScreenImage>%BMP_DIR%\image_1.bmp,0.7,CCOEFF
31	  HoldKey>v,50,0
32	  Wait>0.100
33
34	goto>start

User avatar
Sam71
Junior Coder
Posts: 23
Joined: Tue Mar 12, 2019 10:10 pm

Re: Image Recognition Script Help Needed

Post by Sam71 » Sat Mar 30, 2019 5:06 am

Maybe this might explain better as to what I'm trying to achieve:

Code: Select all

Label>start


FindImagePos>%BMP_DIR%\image_2.bmp,WINDOW:Application01,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  HoldKey>v,50,0
  Wait>0.200
  HoldKey>a,50,0
  Wait>0.200
  HoldKey>g,50,0
  Wait>0.200
  HoldKey>t,50,0 // Search can take 1-6 seconds
Endif

WaitScreenImage>%BMP_DIR%\image_4.bmp,WINDOW:Application01,0.7,1,XArr,YArr,NumFound,CCOEFF //Debugging Gets stuck here.
If>NumFound>0 
HoldKey>v,50,0 
Wait>0.200
HoldKey>s,50,0
Wait>0.200

Else

WaitScreenImage>%BMP_DIR%\image_1.bmp,WINDOW:Application01,0.7,1,XArr,YArr,NumFound,CCOEFF
  HoldKey>v,50,0
  Wait>0.100

goto>start

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Image Recognition Script Help Needed

Post by Grovkillen » Sat Mar 30, 2019 10:12 am

Is image recognition the only way you can do what you want to do? Since it's the most "analog" way of automation you sometimes are left with only the wait to not miss the images. The best is if you have the possibility to capture the frames with Windows API, as in object IDs etc .
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Sam71
Junior Coder
Posts: 23
Joined: Tue Mar 12, 2019 10:10 pm

Re: Image Recognition Script Help Needed

Post by Sam71 » Sat Mar 30, 2019 1:42 pm

Grovkillen wrote:
Sat Mar 30, 2019 10:12 am
Is image recognition the only way you can do what you want to do? Since it's the most "analog" way of automation you sometimes are left with only the wait to not miss the images. The best is if you have the possibility to capture the frames with Windows API, as in object IDs etc .
Hi Grovkillen, Thanks for the reply!. Image recognition is the only way of doing it as the images are coming from a playstation console.

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Image Recognition Script Help Needed

Post by Grovkillen » Sun Mar 31, 2019 6:40 am

Ok, then it makes sense. But like I said. Wait might be your only option here.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Sam71
Junior Coder
Posts: 23
Joined: Tue Mar 12, 2019 10:10 pm

Re: Image Recognition Script Help Needed

Post by Sam71 » Wed Apr 03, 2019 9:43 am

Grovkillen wrote:
Sun Mar 31, 2019 6:40 am
Ok, then it makes sense. But like I said. Wait might be your only option here.
Agreed, wait time is the key to a good working script in this case. Despite this I have still managed to put together a script that does exactly what I want and is very reliable!.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Image Recognition Script Help Needed

Post by Dorian (MJT support) » Wed Apr 03, 2019 12:14 pm

That's great to hear. Grovkillen really knows his stuff. :)
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts