FindText - Capture screen image into text and then find it

Post your working scripts, libraries and tools for AHK v1.1 and older
paulpma
Posts: 65
Joined: 08 Sep 2018, 22:05

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

21 Apr 2020, 22:35

Example how to use OCR function in the FindText version 7.5. I didn't find any info from posts. Hopefully it will help someone.

Code: Select all

FText:=FindText_OcrOK(FindText(0, 0, 600, 600, 0.01, 0, TxtLetters))
Txt:=FText.ocr
MsgBox, % Txt
endgame94
Posts: 2
Joined: 27 Apr 2020, 20:47

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

27 Apr 2020, 20:57

Is there a way to find text on images instead of on pages? Please help me!
endgame94
Posts: 2
Joined: 27 Apr 2020, 20:47

Re: FindText - Catch screen image into text and then find it

27 Apr 2020, 23:08

ed1chandler wrote:
20 May 2016, 09:34
Want to make sure I'm understanding use case and usage:

1) Download script and run it. This pops up the "Catch Image To Text And Find Text Tool" box with "Catch", "Test", and "Copy" buttons.

2) Click the "Catch" button and the cursor is accompanied by a transparent red box.

3) Move the red box over the text you want to search for and click, then move the box more than 100 px in any direction to trigger capture.

4) This brings up the "Catch Image To Text" box with a magnified view of the captured text.

5) The lower left portion of that GUI has a series of "trimming" buttons, used to trim the edges of the captured region. I'm not sure what the abbreviations are supposed to stand for, but it appears that "LD" trims one pixel from the left edge, "LD3" trims three pixels, and the other buttons do the same for "up", "down", and "right." Use those buttons to trim the region down to what you really want to search for.

6) Click somewhere on the magnified capture to select a pixel with the color you want to use for matching. When you do, the text box next to the "Color2Two" button will populate with the hex value of the color corresponding with the pixel you chose.

It appears there are two modes: color and greyscale. If you want to use color, it appears to go something like this:
7a) After selecting a pixel (step 6), if you click the "Color2Two" button, it appears to convert the magnified image into a two-tone version where all pixels of the selected color are converted to black and all other pixels are converted to white.

And if you want to use greyscale, it goes something like this:
7b) After selecting a pixel (step 6), if you click the "Gray2Two" button, it appears to make a "best guess" at a threshold, then convert the magnified image into a two-tone black/white version where all pixels on one side of the threshold are black and all others are white. It also appears that you can change the threshold and click the button again if you want to adjust the program's guess.

8) Once you've got the two-tone image you want, click the "Ok" button. This returns a GUI with a "Text=..." block of text and a related function call. You can click the "Test" button to test that the search will actually find what you're looking for, then click the "Copy" button to copy the text block and the related function call to the clipboard. The "Exchange" button will negate the image and the "Load" button will reload the original capture.

9) Copy that block of text and the function call into the script from which the search will be run ... and be sure the script can "see" the FindText() function.

10) Modify and enjoy.

What I'm *not* quite following is how to modify the function parameters. The "w" and "h" parameters say that they're "offsets" but what does that *mean*? (i.e. What's the effect of changing them?) The default is 150, but the capture tool seeds these to 150000. What is this changing?
I downloaded and compile it into an exe file. But when running the exe file, nothing happens! The program does not appear! Please everyone help@@
OMGmarc
Posts: 4
Joined: 05 Feb 2020, 23:46

Re: FindText - Catch screen image into text and then find it

28 Apr 2020, 09:18

endgame94 wrote:
27 Apr 2020, 23:08
I downloaded and compile it into an exe file. But when running the exe file, nothing happens! The program does not appear! Please everyone help@@
You don't need to compile the FindText.ahk Just run the script itself.

Steps:
1. Copy the code from the OP.
2. Paste it into a blank text file.
3. Save the text file as FindText.ahk.
4. Double click on FindText.ahk to launch FindText.

et voila, start capturing and saving text strings.
skido
Posts: 8
Joined: 05 Mar 2020, 12:46

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

28 Apr 2020, 10:54

@endgame94 Hello , try to update your version of ahk

I discover this fantastic script today and doesn't works with version 1.1.26.01 , after updating it works perfectly! :)
reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

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

03 May 2020, 19:31

Hi!

This looks very useful! Can anyone post their sample use-case script to see how it is implemented for automation purposes?

What do you use it for?
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

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

03 May 2020, 20:53

Finding is not successful when the font size changes. Is it just me failing?
leosouza85
Posts: 90
Joined: 22 Jul 2016, 16:28

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

03 May 2020, 21:26

hasantr wrote:
03 May 2020, 20:53
Finding is not successful when the font size changes. Is it just me failing?
No, font size should remain the same for it to find.
chaoscreater
Posts: 59
Joined: 12 Sep 2019, 21:15

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

05 May 2020, 04:17

Hi there,

I came across your script and tested it and it works great! It's awesome, I love it!

One small problem I have is that the execution of the script is a bit slow. I'm using your script to automate clicking between 2 images on my screen. The images are not always in the same location, hence why I'm using your script. The problem is that there's a delay between each click. So 1st image is clicked and then there's a small wait delay before the 2nd image is clicked.

I found that the delay seems to mostly come from this bit:

Code: Select all

    Gui, _MouseTip_: Color, % A_Index & 1 ? "Red" : "Blue"
    Sleep, 500
So I adjusted it to Sleep, 100 and that made it run a lot faster. However, there's still a small delay. I would like the click to be near instant. I couldn't find anything else to adjust to make it click faster. Any ideas?
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

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

05 May 2020, 04:33

chaoscreater wrote:
05 May 2020, 04:17
Hi there,

I came across your script and tested it and it works great! It's awesome, I love it!

One small problem I have is that the execution of the script is a bit slow. I'm using your script to automate clicking between 2 images on my screen. The images are not always in the same location, hence why I'm using your script. The problem is that there's a delay between each click. So 1st image is clicked and then there's a small wait delay before the 2nd image is clicked.

I found that the delay seems to mostly come from this bit:

Code: Select all

    Gui, _MouseTip_: Color, % A_Index & 1 ? "Red" : "Blue"
    Sleep, 500
So I adjusted it to Sleep, 100 and that made it run a lot faster. However, there's still a small delay. I would like the click to be near instant. I couldn't find anything else to adjust to make it click faster. Any ideas?
I don't know the content of your code, but maybe you forgot to add the necessary things for speed.
Especially:

Code: Select all

SetBatchLines, -1
https://www.autohotkey.com/boards/viewtopic.php?t=6413
blue83
Posts: 157
Joined: 11 Apr 2018, 06:38

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

05 May 2020, 13:33

Hi,

can this be used with v2?

thanks,
blue
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

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

05 May 2020, 15:46

@chaoscreater: For max speed don't use FindText_MouseTip(...) at all e.g.:

Code: Select all

 for i,v in ok
   ;if (i<=2) ; limit number of clicks to two
     ;FindText_MouseTip(ok[i].x, ok[i].y) ; don't use this line
     ;MouseMove, ok[i].x, ok[i].y ; move the mouse to found position(s)
     MouseClick,, ok[i].x, ok[i].y ; click to found positon(s)
     ;Click, % ok[i].x "," ok[i].y ; click to found positon(s) (alternative)
SetBatchLines, -1 would not noticeably speed up the clicks.

@hasantr: For different font and its size try OCR with UWP API.
kairushinjuu
Posts: 46
Joined: 07 May 2020, 07:02

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

07 May 2020, 17:15

Hey all. Sorry to be posting this. I have followed all the steps captured the image, copied the code that comes out, but I am just having problems understanding how to then incorporate this into my script? I've tried reading all the explanations I can find, but I am still too new to this all I guess... If anyone could simplify the process I would be most appreciative. All I want is the found text to be clicked on.
chaoscreater
Posts: 59
Joined: 12 Sep 2019, 21:15

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

09 May 2020, 04:55

Is it possible to edit an existing image found by FindText? Like, can we paste the code back into the software to make a quick edit?
paulpma
Posts: 65
Joined: 08 Sep 2018, 22:05

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

09 May 2020, 21:28

chaoscreater wrote:
09 May 2020, 04:55
Is it possible to edit an existing image found by FindText? Like, can we paste the code back into the software to make a quick edit?
Not possible.
rinjp727
Posts: 1
Joined: 10 May 2020, 06:12

Re: FindText - Catch screen image into text and then find it

10 May 2020, 06:17

OMGmarc wrote:
28 Apr 2020, 09:18
endgame94 wrote:
27 Apr 2020, 23:08
I downloaded and compile it into an exe file. But when running the exe file, nothing happens! The program does not appear! Please everyone help@@
You don't need to compile the FindText.ahk Just run the script itself.

Steps:
1. Copy the code from the OP.
2. Paste it into a blank text file.
3. Save the text file as FindText.ahk.
4. Double click on FindText.ahk to launch FindText.

et voila, start capturing and saving text strings.
>"C:\Program Files\AutoHotkey\SciTE\..\AutoHotkey.exe" /ErrorStdOut "C:\Users\admin\Desktop\FindText.ahk"
C:\Users\admin\Desktop\FindText.ahk (71) : ==> This line does not contain a recognized action.
Specifically: local
>Exit code: 2 Time: 0.1478
Please help me.!!!
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: FindText - Catch screen image into text and then find it

10 May 2020, 09:46

rinjp727 wrote:
10 May 2020, 06:17
>"C:\Program Files\AutoHotkey\SciTE\..\AutoHotkey.exe" /ErrorStdOut "C:\Users\admin\Desktop\FindText.ahk"
C:\Users\admin\Desktop\FindText.ahk (71) : ==> This line does not contain a recognized action.
Specifically: local
>Exit code: 2 Time: 0.1478
Please help me.!!!
Could hint to an AHK version that is too old.
andy5566888
Posts: 10
Joined: 07 May 2020, 02:20

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

10 May 2020, 22:11

i am a rookie in autohotkey i want to ask

Code: Select all

Text:="|<0>*147$6.SnVVVVVnSU"
Text.="|<1>*147$5.9kV248Hw"
Text.="|<2>*148$6.yX11248EzU"
Text.="|<3>*149$6.yX13C11XyU"
Text.="|<4>*149$6.66+GmWz22U"
Text.="|<5>*149$6.TEES311XyU"
Text.="|<6>*148$6.CEUyXVVnSU"
Text.="|<7>*149$6.z1224A8MEU"
Text.="|<8>*148$6.SnVnSVVnSU"
Text.="|<9>*148$6.SnVVlT12QU"
how to get the above the data i want to know the data is use Calculation to get or use something method to convert ?
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

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

11 May 2020, 13:02

@kairushinjuu: If you manage to perform test successfully then this might help you:

Code: Select all

; #Include <FindText>

 ;t1:=A_TickCount, X:=Y:=""

Text:="|<>*196$20.0zk0zz0w1wC0777stVz6kzlw6wT0DDk7rw3tz0w7kD1y3URUw6QD3XXVkzVw3zw0Dw2" ; use your own snippet code!

F11::
     if (ok:=FindText(855-150000, 89-150000, 855+150000, 89+150000, 0, 0, Text))
     {
       CoordMode, Mouse
       X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
        Click, %X%, %Y%
     }
Return
 ;MsgBox, 4096, Tip, % "Found :`t" Round(ok.MaxIndex())
   ;. "`n`nTime  :`t" (A_TickCount-t1) " ms"
   ;. "`n`nPos   :`t" X ", " Y
   ;. "`n`nResult:`t" (ok ? "Success !" : "Failed !")

 ;for i,v in ok
   ;if (i<=2)
     ;FindText_MouseTip(ok[i].x, ok[i].y)

;===== Copy The Following Functions To Your Own Code Just once =====
...
@chaoscreater:
chaoscreater wrote:Is it possible to edit an existing image found by FindText? Like, can we paste the code back into the software to make a quick edit?
Yes, it's possible, but currently not user friendly! Try to change e.g. the last letter/number in Text.="|<2>*148$6.yX11248EzU" to the one which precedes/follows the existing and you will get the idea how to do it.

@andy5566888: It's not very clear to me what do you want to convert (probably image numbers?, where did you get stuck?)!
wrekk
Posts: 4
Joined: 11 May 2020, 15:20

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

11 May 2020, 15:24

Has anyone converted this script to ahk v2?

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: JoeWinograd, return, TheNaviator and 73 guests