FindText - Capture screen image into text and then find it

Post your working scripts, libraries and tools for AHK v1.1 and older
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

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

18 May 2018, 07:27

thats very impressive!

thank you so much :)
HBasalim
Posts: 1
Joined: 23 May 2018, 09:33

23 May 2018, 09:42

how to show critical msgbox when more than 1 text is found within the screen?
guest26789

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

31 May 2018, 13:13

I cannot get this to run, I copied the code in the first post to a new AHK file and ran it. I get a little magnifying glass in the toolbar, but it vanishes. Help me plz :)
I am using the latest AHK 32 bit version.
guest26789

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

01 Jun 2018, 16:46

I got it to work by going back one AHK release
Saiftey
Posts: 18
Joined: 08 May 2018, 18:30

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

02 Jun 2018, 19:59

FindText(X,Y,W,H,err0,err1,Text)

err1 is the character "0" fault-tolerant in percentage (0-1) Default 0.
err0 is the character "_" fault-tolerant in percentage.(0-1) Default 0.
Please explain. I have attempted to set the err0 and err1 values to 1, 2, 3, 4, 5 and many others assuming it meant "percentage" and even just 1% makes my picture go crazy when 1% shouldn't be doing that.

How do I increase the fault tolerant? Please provide an example - I have tried replacing err1 and err0 with actual small numbers 1-9 and it just makes my script match everything black and white.
feiyue
Posts: 348
Joined: 08 Aug 2014, 04:08

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

03 Jun 2018, 00:35

err1、err0 set 0.1 is 10%, 1 is 100%.
guest26789

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

04 Jun 2018, 09:01

Is there a way to make it only search a certain window? (or coordinates in a window?)
Saiftey
Posts: 18
Joined: 08 May 2018, 18:30

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

04 Jun 2018, 20:00

feiyue wrote:err1、err0 set 0.1 is 10%, 1 is 100%.
Ah, now that works better. Thanks lad. :bravo:
feiyue
Posts: 348
Joined: 08 Aug 2014, 04:08

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

05 Jun 2018, 05:18

guest26789 wrote:Is there a way to make it only search a certain window? (or coordinates in a window?)
WinGetPos, x, y, w, h, A
FindText(x+w//2,y+h//2,w//2,h//2,0,0,Text)
feiyue
Posts: 348
Joined: 08 Aug 2014, 04:08

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

08 Jun 2018, 13:45

I try to use GetDCEx and BitBlt to get background windows.
Unfortunately, it failed on Win7. :headwall:
jt_kirk

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

10 Jun 2018, 17:52

feiyue wrote:@jt_kirk, I think this is a relatively easy solution: :)

Code: Select all

;----------------------------
;  Load Pictures to GUI
;----------------------------

Gui, +AlwaysOnTop +ToolWindow
Gui, Color, DDEEFF
Gui, Font, cRed s28
Gui, Add, Text,, Drag Pictures here to Load
  . `n`nPress Enter or Space to Clear.
Gui, Show,, Load Pictures
OnMessage(0x201, "LButton_Down")
return

LButton_Down() {
  ListLines, Off
  if (A_Gui=1 or A_Gui=2) and (A_GuiControl="")
    SendMessage, 0xA1, 2
}

GuiClose:
ExitApp

GuiDropFiles:
Gui, +OwnDialogs
Loop, parse, A_GuiEvent, `n
{
  file:=A_LoopField
  Gosub, LoadPic
}
return

LoadPic:
Gui, 2:Default
Gui, +LastFound +AlwaysOnTop +Owner1 -Caption
Gui, Margin, 0, 0
Gui, Color, White
Gui, Add, Button, w50 Default, OK
Gui, Add, Picture, vPic, %file%
GuiControlGet, p, Pos, Pic
if pW>50
  GuiControl, Move, Button1, w%pW%
Gui, Show
WinWaitClose
return

2ButtonOK:
2GuiEscape:
Gui, Destroy
return

;----------- Script End -----------

;

Hi, feiyue! thank you very much! Unfortunately i do not understand how this will work :( how this code will convert loaded pictures to strings?
feiyue
Posts: 348
Joined: 08 Aug 2014, 04:08

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

17 Jun 2018, 15:30

@jt_kirk, It is more troublesome to generate a function to read a picture file and then convert it to two valued text.
I see you say there are not many pictures that need to be converted.
So a simple solution is to open these pictures directly,
and then use my tool to capture screen images to generate two valued text. :)
Guest

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

07 Jul 2018, 09:59

The red box which is used to capture the image into text, can you not make it any bigger? It's a little too small for what I want to capture.
Irrelephant
Posts: 5
Joined: 13 Jun 2018, 07:13

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

08 Jul 2018, 01:23

Isn´t it enough to caputre just a part of the image - you don´t have to have the whole picture!

Increasing the the capture window shouldn´t be the problem - you just need to find the right code snippet in the script but on top you´d probably have to adjust the GUI for the fine tuning!
frd
Posts: 42
Joined: 19 Jul 2018, 10:01

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

19 Jul 2018, 11:26

Hi people! I've been a long time lurker. AHK has made my work life so much easier, I have no words to express my gratitude towards this great community! :D :D :D

I also would like to thank Feiyue for this INCREDIBLE script! :clap: :clap: :clap: It works so well, it's pretty reliable, it's really fast.

I'm in need of a little help. Another user has asked if there's a way to retrieve a value TRUE or FALSE for this script. I need this to figure this out to solve two problems I have. I need two scripts that will do the following:

a) One that will wait one of three images to appear, if any of them appear, it will click on it and then will keep looking again, three times. If it doesnt find any of them, it will wait 2 seconds (the proprietary software I work with is extremely unstable). Then, after three loops, it will follow a routine (goto).

b) Another one that will wait for one image, if doesnt appear, wait 1 second, look for it again, wait 1 second etc endless untill it finds it, after it finds it, it will follow a routine (goto)

If someone just help me how can I get a value true or false from FINDTEXT, I believe I can slowly work my way to reach those objectives. Any help will be greatly appreciated!

Again, congratulations Feiyue for this incredible work. Hopefully it will part of the official version, since it is so much better than the built in imagesearch. Oh, I tried the code Feiyue has written in response to Cantus (23 Apr 2018, 01:47), but I couldn't manage to change it to fit my needs (I'm sorry, I'm still a newbie). Sorry!!! :( :( :(
feiyue
Posts: 348
Joined: 08 Aug 2014, 04:08

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

19 Jul 2018, 19:46

@frd, Hello! :beer:
ok:=FindText(……) If an image is found, an array will be returned. If it is not found, it will return to 0.
So you just need to compare the ok with 0. if (ok!=0) ;--> is True or False
feiyue
Posts: 348
Joined: 08 Aug 2014, 04:08

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

20 Jul 2018, 13:45

Updated to the v5.9 version. The PicX() function is added. It is used for FindText2(). :beer:

In webpage automation tasks, I find that sometimes the text is slightly changed
(the spacing between words becomes larger), causing the FindText() function to fail.
So I added the PicX() function to divide the Text and then use the FindText2() function to find it.
pedroabs
Posts: 9
Joined: 04 Oct 2017, 23:09

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

20 Jul 2018, 22:04

Hi feiyue,

Is this possible with your function?

1st Step: convert a 4x4 area in a screen into a text screen and stores it in a variable
2nd Step: checks that area for the captured picture and returns yes or no

My intention is to check in a regular interval if an area (an image in a game) has changed. If it changes, it returns yes and a few steps are done by my script and then recaptures the 4x4 area amd stores it in the variable for checking in the next interval.

Thank you very much in advance.
feiyue
Posts: 348
Joined: 08 Aug 2014, 04:08

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

21 Jul 2018, 11:50

@pedroabs, I hope the following two functions can help you. :wave:

Code: Select all

/*

Use examples:

Loop {
  pic1:=GetPicArr(100, 100, 20, 10)
  Sleep, 1000
  pic2:=GetPicArr(100, 100, 20, 10)
  if ComparePicArr(pic1, pic2, n:=0.3)
  {
    MsgBox, The screen image changed !
    Send z
  }
}

*/

; Get the RGB value of all the points of the picture to the array

GetPicArr(x, y, w, h)
{
  xywh2xywh(x,y,w,h, x,y,w,h)
  if (w<1 or h<1)
    return, 0
  ListLines, % "Off" (lls:=A_ListLines=0?"Off":"On")/0
  SetBatchLines, % "-1" (bch:=A_BatchLines)/0
  GetBitsFromScreen(x,y,w,h,Scan0,Stride,bits)
  arr:=[], i:=-4
  Loop, % w*h
    arr.Push(NumGet(bits,i+=4,"uint")&0xFFFFFF)
  SetBatchLines, %bch%
  ListLines, %lls%
  return, arr
}

; Check whether all change points in the picture exceed the percentage

ComparePicArr(arr1, arr2, n:=0.3)
{
  diff:=0, diffMax:=Round(arr1.MaxIndex()*n)
  For k,v in arr1
    diff+=(arr2[k]!=v)
  if (diff>diffMax)
    return, 1
  return, 0
}

Rafaeloneil
Posts: 2
Joined: 26 Jul 2018, 12:38

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

26 Jul 2018, 13:04

Personally, taking advantage of the subject of this topic, I ask your help in this matter:

https://stackoverflow.com/questions/515 ... ying-color

Can you help me?

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 68 guests