Page 7 of 55

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

Posted: 18 May 2018, 07:27
by DRocks
thats very impressive!

thank you so much :)

Posted: 23 May 2018, 09:42
by HBasalim
how to show critical msgbox when more than 1 text is found within the screen?

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

Posted: 31 May 2018, 13:13
by guest26789
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.

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

Posted: 01 Jun 2018, 16:46
by guest26789
I got it to work by going back one AHK release

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

Posted: 02 Jun 2018, 19:59
by Saiftey
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.

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

Posted: 03 Jun 2018, 00:35
by feiyue
err1、err0 set 0.1 is 10%, 1 is 100%.

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

Posted: 04 Jun 2018, 09:01
by guest26789
Is there a way to make it only search a certain window? (or coordinates in a window?)

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

Posted: 04 Jun 2018, 20:00
by Saiftey
feiyue wrote:err1、err0 set 0.1 is 10%, 1 is 100%.
Ah, now that works better. Thanks lad. :bravo:

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

Posted: 05 Jun 2018, 05:18
by feiyue
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)

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

Posted: 08 Jun 2018, 13:45
by feiyue
I try to use GetDCEx and BitBlt to get background windows.
Unfortunately, it failed on Win7. :headwall:

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

Posted: 10 Jun 2018, 17:52
by jt_kirk
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?

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

Posted: 17 Jun 2018, 15:30
by feiyue
@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. :)

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

Posted: 07 Jul 2018, 09:59
by Guest
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.

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

Posted: 08 Jul 2018, 01:23
by Irrelephant
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!

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

Posted: 19 Jul 2018, 11:26
by frd
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!!! :( :( :(

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

Posted: 19 Jul 2018, 19:46
by feiyue
@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

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

Posted: 20 Jul 2018, 13:45
by feiyue
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.

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

Posted: 20 Jul 2018, 22:04
by pedroabs
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.

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

Posted: 21 Jul 2018, 11:50
by feiyue
@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
}


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

Posted: 26 Jul 2018, 13:04
by Rafaeloneil
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?