Closed iseahound closed 9 months ago
Benchmarks (on a slow laptop):
Python's template matching (from OpenCV): 3.43 fps First Attempt at ImageSearch: 13.43 fps
This one does about 200 fps on the test images by preventing the subimage matching.
https://godbolt.org/z/vP679rhYP
The question is: is matching 2/3/4 best? For this script, matching 1,4 is good. But only 4 can be optimized. 2 and 3 may be too correlated.
#include *i ImagePut%A_TrayMenu%.ahk
#include *i ImagePut (for v%true%).ahk
#singleinstance force
; a := imageputwindow("g.png")
pic := ImagePutBuffer("h.png") ; Screen capture
hwnd := pic.show() ; or ImageShow(pic) ; Show image
if xy := pic.ImageSearch3("g.png") { ; Search image
x := xy[1], y := xy[2]
MouseMove x, y
WinGetPos &wx, &wy,,, hwnd
ImagePutWindow("g.png"
, x ", " y
, [wx + x, wy + y])
} else Tooltip "no"
or
pic := ImagePutBuffer("h.png") ; Screen capture
hwnd := pic.show() ; or ImageShow(pic) ; Show image
if xy := pic.ImageSearch("g.png") { ; Search image
x := xy[1], y := xy[2]
MouseMove x, y
ImagePutWindow("g.png"
, x ", " y
, [x,y,,, hwnd])
} else Tooltip "no"
with
try dpi := DllCall("SetThreadDpiAwarenessContext", "ptr", -3, "ptr")
if IsObject(pos) && pos.HasKey(5) {
pos[5] := (hwnd := WinExist(pos[5])) ? hwnd : pos[5]
VarSetCapacity(rect, 16, 0)
DllCall("GetClientRect", "ptr", pos[5], "ptr", &rect)
DllCall("ClientToScreen", "ptr", pos[5], "ptr", &rect)
x += NumGet(rect, 0, "int")
y += NumGet(rect, 4, "int")
}
try DllCall("SetThreadDpiAwarenessContext", "ptr", dpi, "ptr")
?
Yeah, the [x, y, w, h, r]
notation seems to be ideal, as it would allow screenshots relative to a window as well.
Another note to rank:
Because the first pixel kind of acts like another check!
; Search for the address of the first matching image.
address := DllCall(code, "ptr", this.ptr, "uint", this.width, "uint", this.height
, "ptr", image.ptr, "uint", image.width, "uint", image.height, "uint", image.width//2, "uint", image.height//2
, "cdecl ptr")
All of the above has been completed. Only useful data is:
Rank:
ImageSearch has two components:
Prioritize:
Here is some code to help you:
https://github.com/iseahound/ImagePut/assets/9779668/3c2587da-d6ed-449d-af78-89633e2a7442 https://github.com/iseahound/ImagePut/assets/9779668/25a63f1b-8fb2-4c2a-84c4-34867b1e5ece
Useful ideas: boyer moore (and string search algorithms in general) multi-dimensional string searcch Has ImageSearch been a priority in the public domain?
Some research papers would be immensely valuable.
Current performance is about 19 fps, compared to pixelsearch's 4000 fps. Aim for 800 fps or higher.