Autohotkey Picture Recognition

Autohotkey Picture Recognition Guide In The Next Normal

Autohotkey Picture Recognition presents a deeper look at image search. Check out this post to find out more. 

Autohotkey Picture Recognition Guide In The Next Normal

ImageSearch is one of the most mind-bogglingly wonderful yet incredibly irritating. It can be a game-changer if you’re attempting to automate a program that doesn’t utilize normal GUI controls; most games fall into this category since they generally draw the game onto a rule.

These include such as system. Drawing, #’s Java’s AWT, or HTML5’s Canvas object), but it’s not simply restricted to games

It’s a significant element of one of my projects at work, and some use it at home to set up Netflix hotkeys.

But, at times, it may not be easy to make it work! Don’t get me wrong: AHK’s devs are incredible just for developing it.

They are awesome just for creating AHK, my all-time favorite programming language. However, ImageSearch can be a huge PITA to work with. This is because, in most situations, every single nano-detail must be perfect; else, the system will fail with no explanation.

However, ImageSearch can be made to function in this lesson. And, of course, if you have any others to contribute, I’d love to hear them. So let’s get this party started.

Experiment with your numbers.

This one alone solves the vast majority of my ImageSearch issues. The ImageSearch manual explains it as follows:

Toggle Line Numbers – Code: Select all

ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile are all examples of output variables.

Autohotkey Picture Recognition: Here are a few things to keep in mind:

A: X2 and Y2 are “absolute” coordinates; that is, they are not width and height (unlike GUI functions). I’m prone to doing stupid stuff like this:

Toggle Line Numbers – Code: Select all

ImageSearch, OutputVarX, OutputVarY, 400, 200, 50, 50, ImageFile.png, 400, 200, 50, 50, ImageFile.png

Assuming it’s a GUI function, the other two coordinates are width and height. However, it is a distinct point with a different x and y, both of which should be bigger than the original x and y. So, to correct the above example:

Toggle Line Numbers – Code: Select all

400, 200, 450, 250, ImageFile.png, OutputVarX, OutputVarY, ImageSearch, OutputVarX, OutputVarY, 400, 200, 450, 250, ImageFile.png

Alternatively, if it’s easier, add x to width and y to height to get those coordinates.

Extending the search area may alter the results. In the preceding example, I made the error of having the search area the same size as the image you were looking for (50 by 50 pixels). Almost every time, this will ruin it. The search area should instead be larger than the picture.

Toggle Line Numbers – Code: Select all

Tip #2: Examine the zoom factor.

The term “zoom-factor” refers to any combination of the following:

– Configuration of the system (screen resolution, font sizes, magnification, transparency, etc.)

– Zooming based on the application (like IE, Word, etc. have zoom functionality)

You haven’t had to deal with this one too often, but I’ve read that it may have an impact on the search. Some of it is an obvious sense (you can’t search an area in the 1000s on an 800×600 screen resolution, for example), and some of it isn’t (unless you use a screen magnifier like some people do or share the script with folks running a different OS or with different settings).

Tip #3: Look for ways to double-check your coordinates.

When you’re unsure why ImageSearch keeps crashing for no apparent reason, you may utilize MsgBox, MouseMove, and other AHK methods to figure out exactly where your search area is. 

What this looks like depends on your code. But the objective is to ensure that your search area encompasses the picture being searched for. Again, you can be a fool at times, and questioning why my ImageSearch fails when the image isn’t even in that region in the first place is a classic Miguel move. 😆

Tip #4: Confirm that your image exists.

Again, users may be ID10T at times, which is another blunder you are equally responsible for. Check that the picture not only exists but that it is also at the place specified in your code.

Leave a Comment

Your email address will not be published. Required fields are marked *