Can't get Image Recognition to work

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Can't get Image Recognition to work

Post by RNIB » Tue Mar 31, 2020 2:55 pm

I know I'm doing something dumb but I can't work out what.

I'm using Adobe Audition and there is a panel within the program which, if the panel is enabled, displays the word "Markers" on it.

I'm trying to work on part of a macro that looks to see if the Markers panel is open and if it isn't, it then send the command to open it which is Alt+8

Code: Select all

SetFocus>Adobe Audition
Let>WSI_TIMEOUT=10
//Wait for 
FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
Message>I See Markers
Else
Press Alt
send>8
Release Alt
Endif

The bitmap is a screen grab of the word Markers as displayed in the panel. So I'm asking it to find this image on screen and if it does it displays the message "I See Markers". If it doesn't then it sends Alt+8.

I'm finding though that most times it always sends Alt+8 regardless of whether NumFound is greater than 0.

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

Re: Can't get Image Recognition to work

Post by Grovkillen » Tue Mar 31, 2020 4:11 pm

Must you use image recognition? Can't you get it some other way? Perhaps a registry key? I usually do a scan of the registry prior and post change of settings of a program.
Let>ME=%Script%

Running: 15.0.24
version history

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

Re: Can't get Image Recognition to work

Post by Dorian (MJT support) » Wed Apr 01, 2020 8:39 am

Two questions :

1. Are you entirely sure Numfound is 1? If you run this through in the debugger (try >debug >trace), what does Numfound show you in the Watch List?
2. Are you using an external monitor?

If there is an error, NumFound will be -1. This will of course result in the Else part of the code running, even if the image you're looking for is present.
Yes, we have a Custom Scripting Service. Message me or go here

RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Can't get Image Recognition to work

Post by RNIB » Wed Apr 01, 2020 11:11 am

Yes NumFound is definitely registering 1. I'm not using an external monitor, this is all on my laptop and it's built in screen.

I've tried changing to exact mode, restricting the search to within the Audition window and to a rectangle I drew over the specific area but each time it says it's finding the image even when it's definitely not on screen.

I've attached a screengrab of the whole Audition window and of the images I've tried to search for. Could it be because Audition uses a low contrast interface?

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

Re: Can't get Image Recognition to work

Post by Dorian (MJT support) » Wed Apr 01, 2020 12:50 pm

Isn't finding it when it's not there different to the original question, which was not finding it when it was there? Hence Alt-8 being pressed when it shouldn't have been?

Either not finding it (0), or a -1 error would cause ALT-8 to be pressed. The only way "I see markers" should appear is if NumFound>0.

I noticed your tolerance in the first post was 0, which I thought you may have set in order to make a match more likely. More "I See Markers" but very few Alt-8 presses. That could explain it finding it when it wasn't there.

Now I understand the issue with more clarity :

If I try your original code with your screenshot, it finds a match, even if I cover up "Markers". This is because of the tolerance being zero. Anything less than 0.8 seems to give false positives, for example finding a match with "History". Try 0.8. This worked as expected every time. "Found" when Markers was visible. "Not found" when I obscured it.

Code: Select all

//Find and Move Mouse Center of 
FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.8,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  MDL>Found
  Else
  MDL>Not Found
Endif 
Yes, we have a Custom Scripting Service. Message me or go here

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