How does AHK's ImageSearch work?

Discuss other programming languages besides AutoHotkey
Miguel7
Posts: 177
Joined: 08 Sep 2014, 07:06

How does AHK's ImageSearch work?

13 Jan 2017, 19:50

Hey guys,

I've been working on something similar to "IronAHK" (an old library where they tried to port AHK to .net); I'm not necessarily trying to do that per se, because .net has tons of AHK's functionality already (a GUI framework, a Sleep function, string handling, File I/O, it can call functions in DLLs etc.). So I'm really focusing on:
    Windows (WinExist, WinActivate, WinClose etc.)
    Controls (ControlClick, ControlSend, etc.)
    Hotkeys
    Sending keystrokes and mouse clicks (.net can do some of this though)

And so far it's working out pretty well; I've got a lot of the window functions working, and I just recently figured out how to do hotkeys. And for the few things .net doesn't do natively, there are NuGet packages or Win32 API functions that do.

Anyway I would LOVE to add ImageSearch to the list! But my C++ skills are not to the point (yet) where I can look at arbitrary code and figure out how it works. I've been looking at the AHK source lately, and can't seem to find the implementation details. There seems to be a class called "Line" that seems to handle a lot of stuff (I'm guessing it's the guts of the AHK interpreter, which decides what to do on a line-by-line basis), but I'm not seeing a Line::ImageSearch definition anywhere.

So my next step was to do like I did with the window functions - just get it done in C#. I tried Get/SetPixel (which I see is used for PixelGetColor) and soon found out how slow that was; frm there I tried using the .net Bitmap object and its LockBits method, and that came up with something that worked but was still way slower than AHK's version. I've also considered libraries like OpenCV and EmguCV (which I'd love to learn if I could follow the math :lol:) but in the end AHK still seems to have the simplest, fastest algorithm out there. Anyone here know how it works? :)

If not, another option I'm considering is writing an AHK script that I can compile to an EXE and call from C# passing the parameters through the command line. I actually got this working, but I'm thinking the overhead of running an external program might slow things down a bit (or would it?). Thanks guys. :)
Miguel7
Posts: 177
Joined: 08 Sep 2014, 07:06

Re: How does AHK's ImageSearch work?

17 Jan 2017, 18:46

Thanks HotKeyIt. I saw script2.cpp but never thought to look there (guess I was expecting a Line.cpp or ImageSearch.cpp or something, ID10T error on my part :lol:). Anyway, thanks for the info! I'm looking forward to diving into it.
User avatar
nnnik
Posts: 2309
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: How does AHK's ImageSearch work?

18 Jan 2017, 10:46

Code: [Select all] [Expand] [Download] (Untitled.cpp)GeSHi © Codebox Plus

Recommends AHK Studio
Miguel7
Posts: 177
Joined: 08 Sep 2014, 07:06

Re: How does AHK's ImageSearch work?

18 Jan 2017, 22:05

Thanks for that. That bit of code is exactly what I was looking for. What I've read since my last post has been making sense, but I wasn't there yet. I'm definitely gonna work on this again over the weekend. :)

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 1 guest