FindText; Highlight Multiple Found Images

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
saph
Posts: 68
Joined: 25 May 2020, 12:09

FindText; Highlight Multiple Found Images

16 Apr 2021, 20:01

I'm using this to draw a square around a single image if result1 is true. I want to expand this to use multiple images, if any return true I want to draw a box around any and all of them. How do I expand this to work with multiple images? I can't find anything in the documentation.

Code: Select all

{
Search1 := "a"
;Search2 := "b"
;Search3 := "c"

Loop {
		Result1 := FindText(0, 0, 0, 0, 0, 0, Search1)
		;Result2 := FindText(0, 0, 0, 0, 0, 0, Search2)
		;Result3 := FindText(0, 0, 0, 0, 0, 0, Search3)
		
		if (Result1) {
	    x:=Result1.1.x, y:=Result1.1.y
            for i,v in Result1
            if (i<=2)
            FindText_MouseTip(Result1[i].x, Result1[i].y)
	    } 
  } 
}
Usually the code uses the code

Code: Select all

(Result1 || Result2 || Result3 || Result4)
rather than

Code: Select all

(Result1)
and my if statement executes and clicks where I want it if any of the results return true.
User avatar
Chunjee
Posts: 1420
Joined: 18 Apr 2014, 19:05
Contact:

Re: FindText; Highlight Multiple Found Images

16 Apr 2021, 20:49

You want to draw a large box that covers all of them right?

Find
  • The topleft corner (min of all x, max of all y)
  • bottomright corner (max of x, min of all y)
https://www.autohotkey.com/docs/commands/Math.htm#Max
https://www.autohotkey.com/docs/commands/Math.htm#Min

Then use those in a function that draws a box. Not immediately familiar with FindText_MouseTip but doesn't sound like it draws a box.
saph
Posts: 68
Joined: 25 May 2020, 12:09

Re: FindText; Highlight Multiple Found Images

16 Apr 2021, 21:00

Hello,

It's a screen that cycles every 6 seconds with thousands of different images that might be presented. There are range of objects I am (mostly) successfully detecting on the images.

Only one image will ever be present at a time.

For debugging purposes, I'm trying to highlight successfully found images.

I've adapted the default that comes with the FindText Capture Tool for my purposes (code below). But I can't figure out how to make it work for multiple images.

Code: Select all

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

Text:="|<test>*99$7.429YmNAaPc"

 if (ok:=FindText(-533, 131, -487, 169, 0, 0, Text))
 {
   CoordMode, Mouse
   X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
   ; Click, %X%, %Y%
 }

 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)
saph
Posts: 68
Joined: 25 May 2020, 12:09

Re: FindText; Highlight Multiple Found Images

16 Apr 2021, 21:05

This is the exact code and the output. Beneath that square could be a few thousand different images. I only want to highlight certain images, rather than all of them. The detection is working for the most part but because there are so many it's difficult to tune FindText without knowing for sure what the issue might be.

Code: Select all

{
RandomWindow:="|<test>*93$24.Tzy8Dzy8DiTADaTADaTADaTA0krA1triU"

Loop {
		if (FoundRandomWindow:=FindText(-695, 219, -375, 403, 0, 0, RandomWindow))
        {	
            x:=FoundRandomWindow.1.x+, Y:=FoundRandomWindow.1.y
            Sleep 500
            Click, %X% , %Y%
		}

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

	}
}
Attachments
Capture.JPG
Capture.JPG (2.96 KiB) Viewed 412 times
User avatar
Chunjee
Posts: 1420
Joined: 18 Apr 2014, 19:05
Contact:

Re: FindText; Highlight Multiple Found Images

19 Apr 2021, 12:18

What we did once was setup a worst case test image; where we know there should be 8 found images. But some are harder than others.

Then the script tries different Err0, Err1 values till all 8 are found. Probably a smarter way to do it but it only took a few mins to setup the test.

Code: Select all

RandomWindow:="|<test>*93$24.Tzy8Dzy8DiTADaTADaTADaTA0krA1triU"
foundGate := false
while (foundGate == false) {
	random, rand0, 0, 0.9
	random, rand1, 0, 0.9
	result := FindText(-695, 219, -375, 403, rand0, rand1, RandomWindow)
	if (result.count() == 8) {
		foundGate := true
		msgbox, % "found 8 with " rand0 " and " rand1
	}
}
or something like that.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 329 guests