[v2] FindText - Capture screen image into text and then find it

Post your working scripts, libraries and tools.
feiyue
Posts: 362
Joined: 08 Aug 2014, 04:08

Re: [v2] FindText - Capture screen image into text and then find it

Post by feiyue » 24 May 2024, 18:55

Updated to 9.6 version - 2024/05/25 :beer: :dance:
1. Modify: X:="wait/wait1/wait0" After running once, X will be cleared without affecting subsequent calls.
2. Modify: The color similarity and color difference binarization mode can mix multiple colors for binarization.
Text:="|<>RRGGBB1@0.8/RRGGBB2-DRDGDB2/... $ ..."
3. Add: ColorBlock() function, which can generate color blocks with specified area and color, and limit the number of matching colors.
4. Add: Add the GuiCreate Class in V1 to make Gui related code compatible with V2 and reduce the difficulty of code maintenance.

feiyue
Posts: 362
Joined: 08 Aug 2014, 04:08

Re: [v2] FindText - Capture screen image into text and then find it

Post by feiyue » 17 Jun 2024, 22:57

Updated to 9.7 version - 2024/06/18 :beer: :dance:
1. Modify: The use of the left and right dilation algorithm greatly improves the success rate of searching for slightly deformed images.
You need to set at least one fault tolerance to be less than 0 in order to enable the left and right dilation algorithm.
In this case, please set the fault tolerance to be very small, otherwise it may lead to incorrect matching.
2. Add: Use FindText().GetTextFromScreen() quickly generates Text to the clipboard.
3. Modify: Skip searching for overlapping areas around the image (FindMultiColor).
Last edited by feiyue on 22 Jun 2024, 08:11, edited 2 times in total.

redrum
Posts: 101
Joined: 25 Jan 2015, 22:57

Re: [v2] FindText - Capture screen image into text and then find it

Post by redrum » 18 Jun 2024, 09:48

Nevermind, I think I figured it out. I'm new to FindText and didn't realize that the version I was using was Descolada's port of FindText to AHK v2, and that feiyue's port of FindText to AHK v2 was different, so it wasn't a simple change of libraries, as I had to make some minor script modifications since the two libraries have slightly different returns and default search behavior.
Last edited by redrum on 22 Jun 2024, 14:33, edited 1 time in total.

qomph
Posts: 5
Joined: 11 Aug 2023, 22:48
Contact:

Re: [v2] FindText - Capture screen image into text and then find it

Post by qomph » 18 Jun 2024, 14:24

In Fortnite, Lumberjack Heroes, I was searching for x1 Charged using v9.6, and that worked fine.

Now using same Text code, it finds x3 Charged when searching for x1 Charged.

I can try recapture (or just continue using v9.6), but what changed?

https://github.com/tallpeak/AHK/tree/main/fortnite/lumberjack
(using 9.6 from latest checkin)

feiyue
Posts: 362
Joined: 08 Aug 2014, 04:08

Re: [v2] FindText - Capture screen image into text and then find it

Post by feiyue » 18 Jun 2024, 21:41

@qomph :D :headwall:
Compared to the old 9.6 version, the new 9.7 version does have both advantages and disadvantages. The advantage is that it uses left and right fault-tolerant matching internally, greatly improving the success rate of matching. The disadvantage is that it cannot accurately distinguish subtle image differences.
Because after binarization of the screen image, the left and right dilation algorithm expands each black and white point to the left and right, and after overlapping with each other, blurs the details of the image, which is equivalent to a large internal fault tolerance. Therefore, the external fault tolerance should not be too large (it is recommended not to exceed 0.1), otherwise it is easy to make incorrect matches.

For previous scripts, the new version may result in incorrect search results because the previous script may have set a larger fault tolerance value, and the new version needs to reduce the fault tolerance value.

qomph
Posts: 5
Joined: 11 Aug 2023, 22:48
Contact:

Re: [v2] FindText - Capture screen image into text and then find it

Post by qomph » 20 Jun 2024, 22:16

This found inaccurate results using v9.7 ("x4 Charged" instead of "x2 Charged")

Code: Select all

ok:=FindText(&X, &Y, 1344-xtrax, 242-xtray, 1344+xtrax, 242+xtray, 0, 0, Text)
This one works correctly:

Code: Select all

ok:=FindText(&X, &Y, 1344-xtrax, 242-xtray, 1344+xtrax, 242+xtray, 0.01, 0.01, Text)
So it seems err tolerance arguments (7th and 8th args) default to a nonzero value when 0 is passed?
==
FYI:

This is the pattern decoded from below Text by FindText, which is clearly "x2 Charge":

Code: Select all

Text:="|<x2Charge>*240$52.zPynTzzjxhjvxSRFtzyzjqynPPbryzPvRhxwzvBhhzrqkzlymrTbU"
000000_00_0000000_00__00_000000000000000000_00000000
_00_00_00_0000000_000000_0_0000__000_0_0___0000__000
000000000_0000000_000000_00_00000_00__00_00_00_00_00
0__00000_00000000_000000_00_00000_00_000_00_00_00000
_00000__000000000_00__00_00_00_00_00_000000000_00000
_00_00____00000000___000000_00__0_00_000_000000__000

This shows 9.7 finding the wrong match using the 0 arguments:
Screenshot 2024-06-20 201048.png
Screenshot 2024-06-20 201048.png (7.94 KiB) Viewed 221 times
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]

feiyue
Posts: 362
Joined: 08 Aug 2014, 04:08

Re: [v2] FindText - Capture screen image into text and then find it

Post by feiyue » 21 Jun 2024, 07:40

@qomph :D
I have updated version 9.7 to no longer default to using the left and right dilation algorithm.
Now you need to set a fault tolerance to less than 0 to enable the left and right dilation algorithm, which will not affect the previous code.

Post Reply

Return to “Scripts and Functions (v2)”