Question

My question is related to the following AutoHotkey function (you may find it here):

ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile

According to its purpose, this function searches a region of the screen for an image.

As of the ImageFile input, an optional parameter is allowed:

*n (variation): Specify for n a number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of each pixel's color. For example, *2 would allow two shades of variation. This parameter is helpful if the coloring of the image varies slightly or if ImageFile uses a format such as GIF or JPG that does not accurately represent an image on the screen. If you specify 255 shades of variation, all colors will match. The default is 0 shades.

So far, I've always been forced to "calibrate" that parameter making several trials until the chosen image was found: a too high value would return ErrorLevel = 0 all the time, while a too low one would always return ErrorLevel = 1, and of course both of them are not what you would expect from your script.

My question is: what's the most accurate and efficient way to find the "correct" value of *n, that is, the smallest value of *n that makes ImageSearch to not fail during the search with very high confidence (99% or greater)?

Let a possible attempt to find the following images on screen:

enter image description here enter image description here

Consider the following case: these are not images that appear or disappear: they simply amend their brightness (what attached above is the "dark" version); this means that a too high *n value would of course make the script to always find them, even if their brightness is high.

According to my trials, a value of *n spanning from 100 to 125 is quite good, but I cannot be sure about that if I don't know a way to accurately calibrate that value.

I've tried to make something such as this script

i = 1

Loop
{
    ImageSearch, OutputVarX, OutputVarY, 177, 645, 1150, 686, *%i% C:\...\MyImage.png
    i := i + 1
    ;MsgBox, %i%

    if (ErrorLevel = 0)
    {
        MsgBox, %i%
        break               
    }
}
Return

but this does not seem to work.

Was it helpful?

Solution

I made a function that does this about 2 years ago

I called it VariemClick

I made it to find multiple done buildings in a flash game.

Why? Because in the beginning, the image variation I used, found the image in the flash game, but it only worked one time or a few times and then the next time nothing, so I tried to just set up the used variation, only to have it not find the first image, so I needed some way to first, use a low variation and then a little more and so on, but if it got two high, it just found anything, so in with a max variation.

Now the function will start low and then keep setting the allowed variation up and down within the set min/max value given until a set number of tries and then give you a list with info about the images found and the used variation.

Find it here: http://www.autohotkey.com/board/topic/79607-variemclick-findnclick-images-multiple-times-in-flash-games/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top