Jump to content
Centrally

ImageSearch Usage Explanation

Recommended Posts

Hi,

I can't fix problem with autoit library. Its stop working in new versions of autoit.

I downloaded library from this page. When I try to compile script I get error

2hc7S3d.png

I fix it with changing declaration of functions like this:

Func _ImageSearch(ByRef $x, ByRef $y,$findImage,$resultPosition,$tolerance, $HBMP=0)

After that I get 2 different errors:

1) when I'm using 32bit version of DLL:

!>12:54:03 AutoIt3.exe ended.rc:-1073741819

2) when I'm using 64bit vertion of DLL:

$result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)

$result is always = 0;

And its not an array, just variable = 0.

I'm using 64bit Windows 8.1 (had similar problems at win 7 x64). I compile my scrips at 32 bit always.

Sorry for My English, I hope more experience programmers will help me.

Thank you.

Share this post


Link to post
Share on other sites

Are you sure you can simply change the parameters of the Func?

Show your total code which gave the initial error so we can have a look.

Jos

Share this post


Link to post
Share on other sites

#include-once
;#include <Array.au3>
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Image Search
;                 Require that the ImageSearchDLL.dll be loadable
;
; ------------------------------------------------------------------------------

;===============================================================================
;
; Description:      Find the position of an image on the desktop
; Syntax:           _ImageSearchArea, _ImageSearch
; Parameter(s):
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch(ByRef $x, ByRef $y,$findImage,$resultPosition,$tolerance, $HBMP=0)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP)
EndFunc

Func _ImageSearchArea(ByRef $x, ByRef $y,$findImage,$resultPosition,$x1,$y1,$right,$bottom, $tolerance,$HBMP=0)
    ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
If IsString($findImage) Then
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
Else
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP)
EndIf

    ; If error exit
    ConsoleWrite($result&@CRLF)
    ;_ArrayDisplay($result)
    if $result[0]="0" then return 0

    ; Otherwise get the x,y location of the match and the size of the image to
    ; compute the centre of search
    $array = StringSplit($result[0],"|")

   $x=Int(Number($array[2]))
   $y=Int(Number($array[3]))
   if $resultPosition=1 then
      $x=$x + Int(Number($array[4])/2)
      $y=$y + Int(Number($array[5])/2)
   endif
   return 1
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for an image to appear
;
; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImageSearch(ByRef $x, ByRef $y,$findImage,$waitSecs,$resultPosition,$tolerance,$HBMP=0)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        sleep(100)
        $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance,$HBMP)
        if $result > 0 Then
            return 1
        EndIf
    WEnd
    return 0
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for any of a set of
;                   images to appear
;
; Syntax:           _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the ARRAY of images to locate on the desktop
;                              - ARRAY[0] is set to the number of images to loop through
;                                ARRAY[1] is the first image
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns the index of the successful find
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch(ByRef $x, ByRef $y,$findImage,$waitSecs,$resultPosition,$tolerance,$HBMP=0)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        for $i = 1 to $findImage[0]
            sleep(100)
            $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance,$HBMP)
            if $result > 0 Then
                return $i
            EndIf
        Next
    WEnd
    return 0
EndFunc

Did you have similar errors like me? I mean with that ByRef part.

 

I use example code to call func

#include "ImageSearch.au3"

HotKeySet("p", "checkForImage")

global $y = 0, $x = 0

Func checkForImage()
Local $search = _ImageSearch($x, $y,"checkImage.png", 0, 100)
If $search = 1 Then
MouseMove($x, $y, 10)
EndIf
EndFunc

while 1
sleep(200)
WEnd

Share this post


Link to post
Share on other sites

I tried the code posted by tbodine88 () to help in debug, but it always return 1 - where it cant use the DLL.  Im using 64 bit.  I tried 32 bit but it is not working. can someone help pls? how can i have this work for me? thanks 

Share this post


Link to post
Share on other sites

Unfortunately, ImageSearch does not work for me neither.

#include <ImageSearch.au3>

global $y = 0, $x = 0

Func checkForImage()
   Local $search = _ImageSearch('./00-login.bmp', 0, $x, $y, 0)
   If $search = 1 Then
      MouseMove($x, $y, 10)
   EndIf
EndFunc

HotKeySet("p", "checkForImage")

while 1
   sleep(200)
WEnd

After I run it - DLL library crashes. Did anyone manage to fix the problem?

Share this post


Link to post
Share on other sites

Don't want to hijack the threat but since I am having very similar problems thought I should just add it to this thread instead of creating a new one.

The script runs fine with the x64 dll and au3 file but the trouble is the result is always 0.

I have only tidied the imagesearch file and then complied the following code using autoit_x64 compiler.

 
#include <ImageSearch.au3>
#include <GDIPlus.au3>
$fileA = "full path to the file\meeting.bmp"
 
_GDIPlus_Startup()
 
$hImageA = _GDIPlus_ImageLoadFromFile($fileA) ;this is the firefox icon use something else if you don't have it.
$hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA)
 
$x = 0
$y = 0
 
$result = _ImageSearch($hBitmapA, 1, $x, $y, 20) ;Zero will search against your active screen
If $result > 0 Then
MouseMove($x, $y)
MsgBox (0, "Result", $Result)
EndIf
MsgBox (0, "Result", $Result)
_GDIPlus_ImageDispose($hImageA)
_GDIPlus_Shutdown()
 

any help would be much appreciated. it only worked once after I downloaded the demo file but since then it has stopped working completely.

edit: I added the debug lines to the imagesearch.au3 file as well and didnt get any errors (which I believe is good) but the result is always, as previously stated, 0.

Edited by rm65453

Share this post


Link to post
Share on other sites

Sorry about multiple posts but I am not able to edit my previous post.

So somehow using the standalone Aut2Exe v3 and compiling it under x86 works (using the 32 bit files). Still no luck with the 64 bit though which is fine except for the fact that the exe file crashes after most runs. 

here are the error details

 
Files that help describe the problem:
  C:\Users\username\AppData\Local\Temp\WERA988.tmp.WERInternalMetadata.xml
  C:\Users\username\AppData\Local\Temp\WERBF79.tmp.appcompat.txt
  C:\Users\username\AppData\Local\Temp\WERBFE7.tmp.mdmp
 
Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
 
If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt
 
 

Share this post


Link to post
Share on other sites

ok so I got this to work, somewhat successfully. Turns out it doesn't like mixing png and bmp formats. 

now the problem I am having is to make it search extended displays. currently it only searches the display with the toolbar underneath.

any ideas?

Am very close to getting it to work well enough to serve my purpose.

Share this post


Link to post
Share on other sites

After having lot of issues myself with getting ImageSearch to work I decided to make topic with explanation how to proper use this script.

Here is link of original topic at this topic: '?do=embed' frameborder='0' data-embedContent>>

Credits to kangkeng for creating such useful piece of code.

 

Description of parameters from ImageSearch.au3 itself:

; Description:   Find the position of an image on the desktop
; Syntax:        _ImageSearchArea, _ImageSearch
; Parameter(s):
;                $findImage - the image to locate on the desktop
EndIf
EndFunc

while 1
sleep(200)
WEnd

I would like to apologize if by writing this I offended any of member that thinks this script is too simple to even have it explained, it's just as me being new to autoIt it took me so much time getting around errors and making this script to work.

Thanks for reading, if you bump on any problems using it post it here, I will try to help you fixing it and update topic for further reference.

Download links:

32bit: ImageSearch 32bit.rar

64bit: ImageSearch 64 bit.rar

 

 

i have a question iam trying to get the image search to work and it says error line 1 #include <ImageSearch.au3> i think because i dont have that downloaded to my library but i tried to download theses and it didnt really do anything how could i get this ? 

Share this post


Link to post
Share on other sites

The links are in the post you quoted.

Did you extract it?

Did you put it in your script folder?

Did you change  #include <ImageSearch.au3> to  #include "ImageSearch.au3"?

Share this post


Link to post
Share on other sites

Unfortunately, ImageSearch does not work for me neither.

#include <ImageSearch.au3>

global $y = 0, $x = 0

Func checkForImage(main.bmp)
   Local $search = _ImageSearch('main.bmp', 0, $x, $y, 0)
   If $search = 1 Then
      MouseMove($x, $y, 10)
   EndIf
EndFunc

HotKeySet("p", "checkForImage")

while 1
   sleep(200)
WEnd

After I run it - DLL library crashes. Did anyone manage to fix the problem?

where do i put the image and i put the imagesearch file in the include folder or do i put it the script folder because the script complies but when i click go to run it it wont move the mouse or hit the p hot key still to run but it gives me 

>"E:DownloadAutoIt3SciTE..autoit3.exe" /ErrorStdOut "E:DownloadFindIMG.au3"    
"E:DownloadFindIMG.au3" (5) : ==> Expected a variable in user function call.:
Func checkForImage(main.bmp)
Func checkForImage(^ ERROR
>Exit code: 1    Time: 0.3234

Share this post


Link to post
Share on other sites

It would be nice to have the functionality to search for images in another image, I'm thinking this could lead to some basic facial recognition, if anyone wanted to take ti there, among other uses.

Share this post


Link to post
Share on other sites

I wanted to start looking at this, no luck so far.

Just the most basic example I can think of.

Took a screenshot of an icon on my deskto and named it VMWare.bmp and put it in the script dir.

Used the same code as the first page example with a bit of added tollerance and I get an error.

**

Line 44 

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

Error: Subscrit used on non-accessible varible.

**

Code:

#include <ImageSearch.au3>

HotKeySet("p", "checkForImage")

global $y=0, $x=0

Func checkForImage()
Local $search = _ImageSearch("VMWare.bmp", 1, $x, $y, 10)
If $search = 1 Then
    MouseMove($x, $y, 10)
EndIf
EndFunc


While 1
    Sleep(200)
WEnd

I have tried the 32bit and 64bit dll + udf and put them in the autoit Include folder and the scripts directory both will recreate the issue unless I use the 32bit dll in the script folder it crashes autoit outright. 

Edited by ViciousXUSMC

Share this post


Link to post
Share on other sites

This UDF has no error checking in it, you'd need to add some so that you won't get those errors. For example test $result to see if it is an array before acting on it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yeah I was doing some error checking.

I got the script working without error, just not functioning properly/well.

I had to use the x64 udf and dll and then right click and explicitly tell the script to run as x64 then no errors occured but the image was not being found.

I bumped up the tolerance higher and higher until around 150 it found something but not the image it should have found.

I'll experiment with different image captures and see if I can get it working better.  I use a 3 monitor setup and I am searching for an icon on the main monitor, when it finally found something it was nothing close to the image I took a picture of :/

Edit: Larger image works with a 175 tolerance.  Took a capture of the entire icon.  About a 3 second lag from when I fire the function till when it finds it. 

Edit2: Working Great now used irfanview to do the screen capture, crop, save instead of the other stuff before that was probably degrading the image quality and resampling it. 

Edited by ViciousXUSMC

Share this post


Link to post
Share on other sites

FljnhqC.pngwhy this it >.< can anyone help me :)

Im having the same issue, any resolution to it??

 

local $x1
Local $y1
local $search = _ImageSearch($ImgDir&"image.PNG",1,$x1,$y1,0)
 
 
if $search=1 Then
    MouseMove($x1,$y1,3)
    MsgBox(0,"Found","Found a recycle bin with stuff here...")
EndIf
 
running it gives me the error above....

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • By kylejustknows
      The code is solid and simple, it can almost explain itself.
      This is the native autoit way to do the "imagesearch", no 3rd party .dll needed.
       
      It gets "your.bmp", and "screenshot.bmp" ----> Convert the  .bmp files into 2D-Arrays (Malkey's function)  ----> Compare the 2D-arrays, return the matched position.
       
      Tested on: Windows 7; Windows server 2008R2; Windows 10 1809.
       
      Pros:
      It is native. No extra .dll needed
      It is super robust. (I used to have lots of funny results using other imagesearch libs).
      It gets screenshot the same you get your screenshot crop, so it always gets a solid result, and 100% accurate.
      The code is very simple and friendly, all level users can understand and use it.
       
      Cons:
      It is slow to convert your.big.screen.bmp into a 2D-array, and may consume 200+MB of memory and may take 5 - 20 seconds to return the result. (the actual search in an array is fast, but the conversion from .bmp to array is slow. The speed depends on your CPU speed and your screen size).
      Correct: now optimized,  it's ~5 seconds and ~ 70MB ram usage.
      It is a pixel-by-pixel color-code strict comparison in the "array-in-array" search, so you have to use the 24-bit BMP file, no "Tolerance" allowed.
       
      2019-Jun-11: script update:
      Same day updated: Update example;  Optimize the algorithm for performance, now most computers can get the result in ~5 seconds, using ~70MB temporary memory, for the 1920x1080 resolution screen.
       
      2019-Jun-12 script update:
      It now uses "PrintScreen" hotkey to save the screenshot.bmp (restores the user's old clipboard content after it is done) ~This is the only way to make sure the screenshot matches exactly what the user is seeing, after doing dozens of harsh tests.
      The reason: The UDF "ScreenCapture" and "ImageSearch.dll"  are not reliable for an unknown reason. Some window/dialogue special drawings are "invisible" in their screenshots.
      But the "PrintScreen" key -> Clipboard -> screenshot.bmp, this method always catches exact things showing on the screen.
       
      #include <GDIPlus.au3> #include <ClipBoard.au3> ;Sinple Example.================== the 1.bmp is what you want to find on your screen $result = _ScreenSearchBmp("1.bmp") if $result[0] = 0 Then MsgBox(0,"","not found") Else MouseMove($result[0],$result[1],20) ;move mouse to the result EndIf ;Example End.================== You can "include" this file after you remove this "Example" part here. ;=============================================================================== ; ; Description: Main Function. Find the position of an image on the desktop ; Parameter(s): ; $center = 1 - Set where the returned x,y location of the image is. ; default 1 means center, 0 means top-left ; ; Return Value(s): On Success - Returns the array of matched position [x,y] on your screen. ; On Failure - Returns array [0,0] (BTW, there is no position 0,0 on a screen, so it means error) ; ; Note: Warning: The BMP file must be a 24-bit BMP (windows default) ; ;=============================================================================== Func _ScreenSearchBmp($file,$center=1) local $pixelarray,$screenarray ;get both your image.bmp and screenshot.bmp into pixel-by-pixel 2D arrays _FileImageToArray($file, $pixelarray) _Clip_screenshot(@TempDir & "\screenshot.bmp") _FileImageToArray(@TempDir & "\screenshot.bmp",$screenarray) FileDelete(@TempDir & "\screenshot.bmp") ;compare the 2 2D-arrays local $result = _2darray_in_2darray($screenarray,$pixelarray) ;result tidy up, for if $center=1, and for if not found. Local $aresult[2] $aresult[0] = $result[0] $aresult[1] = $result[1] if $aresult[0] = 0 then Return $aresult ;if not found , return 0 0 here if $center = 1 then $aresult[0] = $result[0]+ Round(UBound($pixelarray,1)/2) if $center = 1 then $aresult[1] = $result[1]+ Round(UBound($pixelarray,2)/2) Return $aresult ;if ALL GOOD, and $center=1 then return the center of the image here. EndFunc ;=============================================================================== ; Code by Malkey, converts .bmp into 2D array pixal by pixal. : thanks man! ;=============================================================================== Func _FileImageToArray($filename, ByRef $aArray) Local $Reslt, $stride, $format, $Scan0, $iW, $iH, $hImage Local $v_Buffer, $width, $height Local $i, $j _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($filename) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) $Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW, $iH, $GDIP_ILMREAD, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") Dim $aArray[$width][$height] For $i = 0 To $iW - 1 For $j = 0 To $iH - 1 $aArray[$i][$j] = DllStructGetData(DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)), 1) Next Next _GDIPlus_BitmapUnlockBits($hImage, $Reslt) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Return EndFunc ;==>_FileImageToArray ;=============================================================================== ; ; Description: ; My code, search a 2D array inside another 2d array ; If found, return the positon of first element ; If error or not found, return array [0,0]. Because the very first match would be [1,1], "0" means something wrong. ; eg. search a 2d array ; [1,2,3,4] ; [5,6,7,8] ; [9,0,1,2] ; for: ; [7,8] ; [1,2] ; You will get result [2,3] (means, matched, first element position is row 2, colunm 3) ; ; Parameter(s): ; ; Return Value(s): On Success - Returns the array of matched [x,y], the top-left element position in the source. ; On Failure - Returns [0,0] ; ; ;=============================================================================== Func _2darray_in_2darray($source,$search) ;get the size of the both arrays local $sourcerow = UBound($source,1) Local $sourcecol = UBound($source,2) local $searchrow = UBound($search,1) Local $searchcol = UBound($search,2) ;error input cheching, if error return position 0,0 if $sourcerow = 0 or $sourcecol = 0 or $searchrow = 0 or $searchcol = 0 then Local $aPeople[2] $aPeople[0] = 0 $aPeople[1] = 0 Return $aPeople EndIf ; A crazy 4-for-loops, compare every x,y of search array in every x,y in source array for $ssr = 1 to $sourcerow - $searchrow +1 for $ssc = 1 to $sourcecol - $searchcol +1 for $sr = 1 to $searchrow for $sc = 1 to $searchcol ;if an element not match, go back, search for next if $search[$sr-1][$sc-1] <> $source[$ssr+$sr-2][$ssc+$sc-2] then ContinueLoop 3 Next Next ;if the loop passed all elements test, made it here, means the result is found! congress! lets return the result: Local $aPeople[2] $aPeople[0] = $ssr $aPeople[1] = $ssc Return $aPeople Next Next ;all the loops finished, no result found. return [0,0] Local $aPeople[2] $aPeople[0] = 0 $aPeople[1] = 0 Return $aPeople EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Clip_screenshot ; Description ...: This get a screenshot.bmp using "Print Screen" key, so the image is EXACT same image you use "Print Screen" key, to avoid funny results. ; Syntax ........: _Clip_screenshot($file) ; Parameters ....: $file - The location of the screen shot .bmp file you want it to save ; Return values .: None ; Author ........: Kyle ; =============================================================================================================================== Func _Clip_screenshot($file) local $tempdata = _ClipBoard_GetData() ;save current user's clipboard Send("{PRINTSCREEN}") sleep(200) If _ClipBoard_IsFormatAvailable($CF_BITMAP) Then _ClipBoard_Open(0) $hClipboardImage = _ClipBoard_GetDataEx($CF_BITMAP) _ClipBoard_Close() _GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hClipboardImage) Local $iX = _GDIPlus_ImageGetWidth($hBitmap) Local $iY = _GDIPlus_ImageGetHeight($hBitmap) Local $hClone = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $iX, $iY, $GDIP_PXF24RGB) ;make sure its 24bit bmp _GDIPlus_ImageDispose($hBitmap) $hBitmap = $hClone $sCLSID = _GDIPlus_EncodersGetCLSID("BMP") _GDIPlus_ImageSaveToFileEx($hBitmap, $file, $sCLSID, 0) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndIf _ClipBoard_SetData($tempdata) ; restore user clipboard EndFunc Remove the "example" part then you can include this code as a file.
    • By kuhicop
      Hello, I need to find an image on screen and return it's position left, top, right, botton.
      I'm using the ImageSearch function but it only returns 1 or 0.
      Any ideas? Thanks!
    • By Errious
      Hello,
      maybe i am just tired or i did not understand exactly how to use ImageSearch for different pictures, but i tried now a few things with my example script and only the first part is working.
      Explaining what i try to do, at work we have a programm running which has three different states, they are visible but sometimes the statuses of the process is not running and to avoid a long time without progress of the programm i searched to get a way to have a better visible notification as existing, so there is grey as work in progress, orange for not running and red for aborted, now when the states are changing i would like to receive a little window that is just telling the actual status.
      #include <ImageSearch2015.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> $x1=0 $y1=0 While 1 sleep(100) $image1 = _ImageSearch("red.png", 1,$x1,$y1,0) If $image1 = 1 then SplashTextOn ( "", "RED !" , 100 , 50 , 1800 , 220 , $DLG_TEXTLEFT, "Arial" , 12 , 500 ) Sleep(1000) SplashOff() sleep(100) EndIf $image2 = _ImageSearch("orange.png", 1,$x1,$y1,0) If $image2 = 1 Then SplashTextOn ( "", "Orange !" , 100 , 50 , 1800 , 220 , $DLG_TEXTLEFT, "Arial" , 12 , 500 ) Sleep(1000) SplashOff() sleep(100) EndIf $image3 = _ImageSearch("grey.png", 1,$x1,$y1,0) If $image3 = 1 Then SplashTextOn ( "", "Grey !" , 100 , 50 , 1800 , 220 , $DLG_TEXTLEFT, "Arial" , 12 , 500 ) Sleep(1000) SplashOff() EndIf WEnd As i said before, part one to receive the state for aborted is working, so i get the splash window for this, but what do i miss for the other two?
      I put the While statement in for continuously running as long it is needed when the program is in use, but i believe i missed something.
    • By VIP
      Use MouseClick()  mybe must/need:
      #RequireAdmin  
      DLL incuded on script!
      ; #INDEX# ================================================================================================= ; Title .........: ImageSearch ; AutoIt Version : 3.x ; Language ......: English ; Description ...: Check image Appears or Not and Return the position of an image on the desktop ; Author(s) .....: Dao Van Trong - TRONG.LIVE ; ================================================================================================= ; #CURRENT# ================================================================================================= ; _ImageSearch ; _ImageSearch_Area ; _ImageSearch_Wait ; _ImageSearch_WaitArea ; ================================================================================================= ;=============================================================================== ; ; Author:...........: AutoIT VietNam : Dao Van Trong - TRONG.LIVE ; Description:......: Check image Appears or Not ; Find and return the position of an image on the desktop ; Syntax:........... _ImageSearch_Area, _ImageSearch ; Parameter(s):..... $_ImagePath: The image to locate on the desktop ; May be a list of image by delimited by "|" ; i.e: $_ImagePath = "image1.bmp|image2.bmp|image3.bmp" ; $P_x1 $P_y1: Position of 1st point ; $P_x2 $P_y2: Position of 2nd point - Default is last botton right of desktop ; $_Tolerance: 0 for no tolerance (0-255). Needed when colors of image differ from desktop. e.g GIF ; $_CenterPos: boolen. True will return $array[1] x $array[2] is center of image found. ; False will return top-left position ; Return Value(s):.. Return an array has 3 item ; On Success: $array[0] 1 ; On Failure: $array[0] 0 ; DLL not found or other error: $array[0] -1 ; $array[1] x $array[2]: position of image what found on desktop ; ; Note:............. Use _ImageSearch to search the entire desktop ; _ImageSearch_Area to specify a desktop region to search ; $_ImagePath with more item need more time appear on screen before function can detect. ; Decrease sleep time in the loop to detect faster. But less performance. I.e CPULoad increased ; ;=============================================================================== EG:
      #include "_ImageSearch.au3" #include "_ImageSearch_Debug.au3" #RequireAdmin HotKeySet("{Esc}", "_Exit") ; Press ESC for exit Func _Exit() Exit 0 EndFunc ;==>_Exit Global Const $Ask_On_Found = 1 Global Const $Mouse_Move_On_Found = 1 Global Const $Mouse_Click_On_Found = 0 Global $_Image_1 = @ScriptDir & "\example.bmp" ; First, use this function to create a file bmp, maybe a desktop icon for example') MsgBox(64 + 262144, 'ImageSearch', 'At first, create a file bmp,' & @CRLF & 'photos that will search on the screen!') _ImageSearch_Create_BMP($_Image_1) ConsoleWrite("! Search for images: " & $_Image_1 & @CRLF & '! Searching on the screen ...' & @CRLF) While 1 ToolTip('(Press ESC for EXIT) Searching ...', 1, 1) Local $return = _ImageSearch($_Image_1) If $return[0] = 1 Then ConsoleWrite('- Image found:' & " X=" & $return[1] & " Y=" & $return[2] & @CRLF) If $Mouse_Move_On_Found Then MouseMove($return[1], $return[2]) If $Mouse_Click_On_Found Then MouseClick("left", $return[1], $return[2]) ToolTip('(Press ESC for EXIT) Image found:' & " X=" & $return[1] & " Y=" & $return[2], 1, 1) If $Ask_On_Found Then Local $ask = MsgBox(6 + 262144, 'Success', 'Image found:' & " X=" & $return[1] & " Y=" & $return[2]) If $ask = 2 Or $ask = 3 Or $ask = 5 Or $ask = 7 Then Exit ;No, Abort, Cancel, and Ignore If $ask = 10 Then _ImageSearch_Create_BMP($_Image_1) ; Continue ;Try Again EndIf EndIf Sleep(200) WEnd  
       
      Video demo:
       
    • By Nick3399
      I have loaded FastFind into my code and it takes a snapshot and creates a BMP file from it. 
      My issue is now I want to imagesearch from that BMP file (or snapshot memory) and look for a specific image from that image and get the coordinates from that. 
      I have looked at all the documentation but I cannot find anything to assist me.
       
      Does anyone have any idea?
×
×
  • Create New...