WaitForImage not working on multiple monitors

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
kevinkalexander67
Newbie
Posts: 8
Joined: Tue Jul 11, 2017 2:36 pm

WaitForImage not working on multiple monitors

Post by kevinkalexander67 » Wed Sep 27, 2017 1:49 pm

I have a situation where I'm issuing a WaitForImage and the script is only recognizing the image when it is displayed on the primary monitor. It doesn't pick it up if it's on the secondary monitor. Is there a way to make this work with multiple monitors and recognize the image regardless of which monitor it shows up on?

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: WaitForImage not working on multiple monitors

Post by Marcus Tettmar » Wed Sep 27, 2017 2:22 pm

Do you mean WaitScreenImage? Image recognition has worked in multi-monitor setups, across all monitors since v12. See release notes: https://www.mjtnet.com/mswhatsnew.htm - could you be using an old version?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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

Re: WaitForImage not working on multiple monitors

Post by Grovkillen » Wed Sep 27, 2017 8:20 pm

Marcus Tettmar wrote:Do you mean WaitScreenImage? Image recognition has worked in multi-monitor setups, across all monitors since v12. See release notes: https://www.mjtnet.com/mswhatsnew.htm - could you be using an old version?
Just for convenience: https://www.mjtnet.com/mswhatsnew.htm
Let>ME=%Script%

Running: 15.0.24
version history

kevinkalexander67
Newbie
Posts: 8
Joined: Tue Jul 11, 2017 2:36 pm

Re: WaitForImage not working on multiple monitors

Post by kevinkalexander67 » Thu Sep 28, 2017 3:11 pm

Yes, sorry - I mean WaitScreenImage. I'm using version 14.3.12, the very latest I believe. I'm waiting on an image that's in a tab of Chrome, could this make a difference? I doubt it. I expected it to work across all monitors, but sure enough, I ran it with the Chrome browser in the secondary monitor and my application wouldn't "pop" (because I do a WaitScreenImage then pop up my application).

kevinkalexander67
Newbie
Posts: 8
Joined: Tue Jul 11, 2017 2:36 pm

Re: WaitForImage not working on multiple monitors

Post by kevinkalexander67 » Thu Sep 28, 2017 3:19 pm

I just tested it again to be sure. And it is definitely not seeing the image in the secondary monitor. As soon as I brought the browser to the main monitor, the application popped - meaning the image was recognized. So something isn't working as expected about this.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: WaitForImage not working on multiple monitors

Post by Marcus Tettmar » Thu Sep 28, 2017 3:31 pm

It *definitely* works on a multi-monitor setup. We use image recognition on multi-monitor setups regularly. But just to make sure I'm not going completely mad I just tested it.

However, your setup may mean that the resolution is different on each monitor. If so, and if you captured the image on your main monitor, it would appear different on the second monitor. So when the window is on the second monitor it may fail to match. This is most notable if you have a HD monitor as your main monitor and a low res monitor as your second. With the latest versions of Windows with a setup like that you will even see a sudden change of appearance as you drag the window from one to the other. With Windows 10 even the scale factor changes, it being specific to each monitor. So Chrome looks quite different on one monitor compared to the other and if a portion of Chrome was captured on one it may not be found when placed on the other.

Another possibility is if your second monitor is large, and to the right, it will take longer to find the image if it's there, than if it's on the main monitor which is the left-most (because of the way the pixels are scanned left to right, top to bottom). So even if the resolutions are identical, moving the window to the left could cause WaitScreenImage to "pop" sooner. Of course if it is waiting forever rather than just longer, then that's probably not the issue and I would suspect it's a difference in resolution.

The answer of course is to capture the image when it's on the monitor that the window is most likely to be on. And/Or have your script MOVE the window to the monitor you captured from, so you can be sure you are comparing like with like. If you can't do that, you could capture BOTH versions and have your script detect where the window is (GetWindowPos) and then decide which to look for, or have it look for both and stop waiting when it finds one or other. And finally I'd suggest you always set a timeout and check the outcome.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

kevinkalexander67
Newbie
Posts: 8
Joined: Tue Jul 11, 2017 2:36 pm

Re: WaitForImage not working on multiple monitors

Post by kevinkalexander67 » Thu Sep 28, 2017 4:00 pm

Ok, snapping the image from the secondary monitor made it work. So, although the monitors seemed to be identical and the resolution was the same, there must have been some microscopic difference between the two monitors. But isn't the CCOEF matching algorithm supposed to account for small differences and match anyway? What exactly does the CCOEF matching do in a case like this? I thought it would account for screen resolution differences and things like that.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: WaitForImage not working on multiple monitors

Post by Marcus Tettmar » Thu Sep 28, 2017 4:08 pm

CCOEFF stands for Correlation Coefficient - it's a statistical matching algorithm. It all depends on what the differences are and what the tolerance is set to. There must have been enough of a difference to make it think it wasn't a statistical match.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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