It looks like a hungry algorytm. Think about it again and identify points where you can safely leave this function. e.g. add refund after
Console.Add("Ok button found."); Console.Add(""); ConsoleUpdate(); return;
I believe that you can find more points that you can leave because you can be sure that you have nothing more to find, or why you end your cycles even if you have already found what you are looking for?
Or maybe you can configure it differently. You can start scanning the image for the first pixel, and after searching for it, you can check the second, third, etc., And, if, for example, the third pixel is incorrect, you will need to go back and continue.
So, even if one pixel is correct, you will view the image only once.
In other words, do not try to compare the two x * y regions, first try to compare the pixels, and then the regions. You should be able to significantly reduce the time.
source share