Jump to content

Recommended Posts

Posted

Hello.

I made a simple function which looks for a specific image on the screen. The image has 7px width, 1px height, so its nothing special nor big. After it finds it on the screen, it returns the coordinates and then I can do with them whatever I want.

My approach is to store the image I'm looking for into an array as hex values. I then scan the opened window, pixel by pixel, store the last 7 scanned pixels into an array. Every time a pixel gets scanned, I do a quick comparison with the array of pixels of the image I'm looking for. If the two arrays match, I then found the image on the screen. That's like the most basic and easiest to understand solution for this problem.

And it seems to work flawlessly, except one problem. The issue is that it takes a really long time to scan the screen. I read somewhere that PixelGetColor() method has some CPU limiters which doesn't allow it to hog the CPU. So that's an issue for me. I need to scan the screen every so often and waiting more that 5 minutes to do the scan is not really an option.

Is there some other way to approach this problem, perhaps by using some different faster method?

 

Here's my working script.

#Region HOTKEYS
HotKeySet("{ESC}", _Close)
#EndRegion HOTKEYS

Global $sWindowTitle = "Firefox"
Global $aWindowPosition = GetBrowserWindowCoordinates($sWindowTitle)
Global $iWindowXPosition = $aWindowPosition[0]
Global $iWindowYPosition = $aWindowPosition[1]
Global $iWindowWidth = $aWindowPosition[2]
Global $iWindowHeight = $aWindowPosition[3]
Local $aImageCoords[2] = GetImageCoordinates()
ConsoleWrite("X: " & $aImageCoords[0] & " Y: " & $aImageCoords[1] & @CRLF)


#Region GET IMAGE COORDINATES
Func GetImageCoordinates()
   Local $aImageCoordinates[2]
   Local $aImagePicture[7] = ['00111014', '0068696B', '00817E83', '0078787A', '006B6D6F', '008F9092', '00363236']
   Local $aScreenPicture[7]

   Local $iScanningXStartCoord = $iWindowXPosition
   Local $iScanningXStopCoord = $iWindowXPosition + $iWindowWidth
   Local $iScanningYStartCoord = $iWindowYPosition
   Local $iScanningYStopCoord = $iWindowYPosition + $iWindowHeight

   For $y = $iScanningYStartCoord To $iScanningYStopCoord Step 1
      For $x = $iScanningXStartCoord To $iScanningXStopCoord Step 1
         $aScreenPicture[0] = $aScreenPicture[1]
         $aScreenPicture[1] = $aScreenPicture[2]
         $aScreenPicture[2] = $aScreenPicture[3]
         $aScreenPicture[3] = $aScreenPicture[4]
         $aScreenPicture[4] = $aScreenPicture[5]
         $aScreenPicture[5] = $aScreenPicture[6]
         $aScreenPicture[6] = Hex(PixelGetColor($x, $y, 6))

         For $j = 0 To 6
            If StringCompare($aScreenPicture[$j], $aImagePicture[$j]) <> 0 Then
               ExitLoop
            EndIf
            If $j = 6 Then
               $aImageCoordinates[0] = $x
               $aImageCoordinates[1] = $y
               ExitLoop 3
            EndIf
         Next
      Next
   Next

   Return $aImageCoordinates
EndFunc
#EndRegion GET IMAGE COORDINATES

#Region GET BROWSER WINDOW COORDINATES
Func GetBrowserWindowCoordinates($sWindowTitle)
   Local $aWindowPosition = WinGetPos($sWindowTitle)

   Return $aWindowPosition
EndFunc
#EndRegion GET BROWSER WINDOW COORDINATES

#Region CLOSE SCRIPT
Func _Close()
  GUIDelete()
  Exit
EndFunc
#Region CLOSE SCRIPT

 

Posted

Wouldn't automating Firefox be a faster alternative?

5 hours ago, Papak said:

After it finds it on the screen, it returns the coordinates and then I can do with them whatever I want. 

If you could provide more information what you need to do with the result we might provide a faster solution ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

I'm building an interactive map. So I'm using AutoIt for testing purposes. I'm basically searching for icons on the map and then clicking them in rapid succession. I'm trying to emulate a super fast user so I can see how my map script behaves under those conditions.

So basically all I need is a method, to which I can pass an image, or an array of pixels and it returns me the $x and $y coordinates of where  they are located on the screen. Then I can pass them to MouseClick($x,$y,0).

Since I couldn't find one, I wrote my own using PixelGetColor(), but as I said, its extremely slow. The function I wrote takes like 5 minutes+ to scan 1920x1080 screen.

 

I found ImageSearch.au3. Looked promising, but regardless if I use the 32bit or 64bit version, I can't get it to work, I'm always getting an error.

Line 44 

if $result[0]="0" then return 0

Error: Subscrit used on non-accessible varible.

I did every suggestion in that thread and nothing worked for me.

 

So I'm not sure what else to do. Suggestions are much appreciated, thanks!

Posted

Seems _ImageSearch just returns 0 (error ) or 1 (success) according to the link you provided above.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

That's not a problem because there's a _ImageSearchArea() method. I can pass small areas of the screen to the function and I can keep testing if the method returns 0 or 1. If it returns 1, I know it found the image, so I know I've sent it the right coordinates. I can use those coordinates to click on the location. So I can make it work.

The issue is that no matter which area I send, I always get the error above, even when the image is on the screen. Image path I'm loading is correct when I print it to the console, so I know it loads it.

Posted (edited)

What you're saying is confusing. You latest issue was that you get an error saying: 'Error: Subscrit used on non-accessible varible.' That's because of what water suggested. Currently you're checking for the array variable called 'result', but it is not an array at all, hence the error. (provided the error is related to the what _ImageSearchArea returns) You should be doing this:

$result = _ImageSearchArea("image.bmp", 1, xPos, yPos, xPos, yPos, xpos_return_var, ypos_return_var, tolerance)
If $result = 1 Then
    do stuff
EndIf

If that solves the error but you're still not getting any results. Try increasing the tolerance.

_ImageSearch(Area) works wonders for me...

Edited by Seminko
cleanup
Posted

Without seeing your code it is hard to tell whether the error on line 44 is in the _ImageSearch UDF or your code.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...