Jump to content

Image Search Library


kangkeng
 Share

Recommended Posts

43 minutes ago, BetaLeaf said:

can I see your script please?

yeah sure :)

Below is the script file content : 

$x = 0
$y = 0

Send("#d")
Sleep(2000)
Local $search = _ImageSearch('recycleBin.bmp', 1, $x, $y, 0)
If $search = 1 Then
      MsgBox(0, "_ImageSearch Success", "Returned : " & $search)
      MouseMove($x,$y,3)
Else
     MsgBox(0, "_ImageSearch Failure", "Returned : " & $search)
EndIf

Link to comment
Share on other sites

I see the issue now. Here's an example script I have. It's what I used to learn how to use ImageSearch. Hope it helps.

#include "ImageSearch.au3";Required to get ImageSearch to function. Store in @scriptdir
#include "GDIPlus.au3";Required to get ImageSearch to function. Comes with AutoIT
Global $iX, $iY;Make these variables global so we can reuse them after finding an image, instead of creating new variables for that purpose.

;Example Image is the AutoIt Logo on the Offical Website. https://www.autoitscript.com/site/
Do
    Sleep(300)
Until _FindImage("Example.png")
MsgBox(0, "Example", "Found Image!" & @CRLF & @CRLF & "Coord X = " & $iX & "." & @CRLF & "Coord y = " & $iY & ".")
Func _FindImage($sImgPath);the function that searches

    ;Initialize and prepare ImageSearch.
    _GDIPlus_Startup();Initialize Microsoft Windows GDI+.
    Local $hImage = _GDIPlus_ImageLoadFromFile($sImgPath);Create an image object based on a file.
    Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage);Create a handle to a bitmap from a bitmap object.

    ;Search for Image.
    $iRet = _ImageSearch($hHBmp, 1, $iX, $iY, 5) ; Default=5: Tolerance, if it does not work for you rise it (up to 255)

    ;Begin Cleanup.
    _WinAPI_DeleteObject($hHBmp);Deletes a logical pen, brush, font, bitmap, region, or palette.
    _GDIPlus_ImageDispose($hImage);Release an image object.
    _GDIPlus_Shutdown();Clean up resources used by Microsoft Windows GDI+.

    ;Report Result.
    Return $iRet;Will return 1 if image was found. If no image was found, this will return 0.

EndFunc   ;==>_FindImage

I'm not sure who made the example above. Also, next time, please use the code button. Best of luck.

chrome_2017-02-09_02-38-06.png

Example.png

Example.png

Edited by BetaLeaf

 

 

Link to comment
Share on other sites

5 hours ago, BetaLeaf said:

I see the issue now. Here's an example script I have. It's what I used to learn how to use ImageSearch. Hope it helps.

#include "ImageSearch.au3";Required to get ImageSearch to function. Store in @scriptdir
#include "GDIPlus.au3";Required to get ImageSearch to function. Comes with AutoIT
Global $iX, $iY;Make these variables global so we can reuse them after finding an image, instead of creating new variables for that purpose.

;Example Image is the AutoIt Logo on the Offical Website. https://www.autoitscript.com/site/
Do
    Sleep(300)
Until _FindImage("Example.png")
MsgBox(0, "Example", "Found Image!" & @CRLF & @CRLF & "Coord X = " & $iX & "." & @CRLF & "Coord y = " & $iY & ".")
Func _FindImage($sImgPath);the function that searches

    ;Initialize and prepare ImageSearch.
    _GDIPlus_Startup();Initialize Microsoft Windows GDI+.
    Local $hImage = _GDIPlus_ImageLoadFromFile($sImgPath);Create an image object based on a file.
    Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage);Create a handle to a bitmap from a bitmap object.

    ;Search for Image.
    $iRet = _ImageSearch($hHBmp, 1, $iX, $iY, 5) ; Default=5: Tolerance, if it does not work for you rise it (up to 255)

    ;Begin Cleanup.
    _WinAPI_DeleteObject($hHBmp);Deletes a logical pen, brush, font, bitmap, region, or palette.
    _GDIPlus_ImageDispose($hImage);Release an image object.
    _GDIPlus_Shutdown();Clean up resources used by Microsoft Windows GDI+.

    ;Report Result.
    Return $iRet;Will return 1 if image was found. If no image was found, this will return 0.

EndFunc   ;==>_FindImage

I'm not sure who made the example above. Also, next time, please use the code button. Best of luck.

chrome_2017-02-09_02-38-06.png

Example.png

Example.png

 

Hi,

In the above script file, you are passing bitmap handle in ImageSearch method  shown below: 

 ;Search for Image.
    $iRet = _ImageSearch($hHBmp, 1, $iX, $iY, 5) ; Default=5: Tolerance, if it does not work for you rise it (up to 255)

------------------------------------------------------------------------------------------------------------------------------------------

But in the ImageSearch.au3 file you have mentioned passing an ImageFile Name (path of the image file) which is a string, i.e. 

If IsString($findImage) Then
      MsgBox(0, "Inside If", "IsString Method", 2)
      ;If $tolerance>0 Then $findImage = "*" & $tolerance & " " & $findImage
      If $HBMP = 0 Then
         MsgBox(0, "Inside If", "$HBMP = 0", 2)
         $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
      Else
         MsgBox(0, "Inside Else", "$HBMP = 0", 2)
         $result = DllCall("ImageSearchDLL.dll","str","ImageSearchEx","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
      EndIf
   Else
      MsgBox(0, "Inside Else", "IsString Method", 2)
      $result = DllCall("ImageSearchDLL.dll","str","ImageSearchExt","int",$x1,"int",$y1,"int",$right,"int",$bottom, "int",$tolerance, "ptr",$findImage,"ptr",$HBMP)
   EndIf

------------------------------------------------------------------------------------------------------------------------------------------

So while passing string , this code works fine. but if I am sending bitmap handle, its returning 0.

Also , plss help how can I check what is written in the methods "ImageSearchExt", "ImageSearchEx", "ImageSearch" of ImageSearchDLL.dll file.

Please help.

Thanks in advance.

Link to comment
Share on other sites

20 hours ago, BetaLeaf said:

I see the issue now. Here's an example script I have. It's what I used to learn how to use ImageSearch. Hope it helps.

#include "ImageSearch.au3";Required to get ImageSearch to function. Store in @scriptdir
#include "GDIPlus.au3";Required to get ImageSearch to function. Comes with AutoIT
Global $iX, $iY;Make these variables global so we can reuse them after finding an image, instead of creating new variables for that purpose.

;Example Image is the AutoIt Logo on the Offical Website. https://www.autoitscript.com/site/
Do
    Sleep(300)
Until _FindImage("Example.png")
MsgBox(0, "Example", "Found Image!" & @CRLF & @CRLF & "Coord X = " & $iX & "." & @CRLF & "Coord y = " & $iY & ".")
Func _FindImage($sImgPath);the function that searches

    ;Initialize and prepare ImageSearch.
    _GDIPlus_Startup();Initialize Microsoft Windows GDI+.
    Local $hImage = _GDIPlus_ImageLoadFromFile($sImgPath);Create an image object based on a file.
    Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage);Create a handle to a bitmap from a bitmap object.

    ;Search for Image.
    $iRet = _ImageSearch($hHBmp, 1, $iX, $iY, 5) ; Default=5: Tolerance, if it does not work for you rise it (up to 255)

    ;Begin Cleanup.
    _WinAPI_DeleteObject($hHBmp);Deletes a logical pen, brush, font, bitmap, region, or palette.
    _GDIPlus_ImageDispose($hImage);Release an image object.
    _GDIPlus_Shutdown();Clean up resources used by Microsoft Windows GDI+.

    ;Report Result.
    Return $iRet;Will return 1 if image was found. If no image was found, this will return 0.

EndFunc   ;==>_FindImage

I'm not sure who made the example above. Also, next time, please use the code button. Best of luck.

chrome_2017-02-09_02-38-06.png

Example.png

Example.png

Hi,

In the above script file, you are passing bitmap handle in ImageSearch method  shown below: 

 ;Search for Image.
    $iRet = _ImageSearch($hHBmp, 1, $iX, $iY, 5) ; Default=5: Tolerance, if it does not work for you rise it (up to 255)

------------------------------------------------------------------------------------------------------------------------------------------

But in the ImageSearch.au3 file you have mentioned passing an ImageFile Name (path of the image file) which is a string, i.e. 

If IsString($findImage) Then
      MsgBox(0, "Inside If", "IsString Method", 2)
      ;If $tolerance>0 Then $findImage = "*" & $tolerance & " " & $findImage
      If $HBMP = 0 Then
         MsgBox(0, "Inside If", "$HBMP = 0", 2)
         $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
      Else
         MsgBox(0, "Inside Else", "$HBMP = 0", 2)
         $result = DllCall("ImageSearchDLL.dll","str","ImageSearchEx","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
      EndIf
   Else
      MsgBox(0, "Inside Else", "IsString Method", 2)
      $result = DllCall("ImageSearchDLL.dll","str","ImageSearchExt","int",$x1,"int",$y1,"int",$right,"int",$bottom, "int",$tolerance, "ptr",$findImage,"ptr",$HBMP)
   EndIf

------------------------------------------------------------------------------------------------------------------------------------------

So while passing string , this code works fine. but if I am sending bitmap handle, its returning 0.

Also , plss help how can I check what is written in the methods "ImageSearchExt", "ImageSearchEx", "ImageSearch" of ImageSearchDLL.dll file.

Please help.

Thanks in advance.

Link to comment
Share on other sites

24 minutes ago, VandanaS said:

Hi,

In the above script file, you are passing bitmap handle in ImageSearch method  shown below: 

 ;Search for Image.
    $iRet = _ImageSearch($hHBmp, 1, $iX, $iY, 5) ; Default=5: Tolerance, if it does not work for you rise it (up to 255)

------------------------------------------------------------------------------------------------------------------------------------------

But in the ImageSearch.au3 file you have mentioned passing an ImageFile Name (path of the image file) which is a string, i.e. 

If IsString($findImage) Then
      MsgBox(0, "Inside If", "IsString Method", 2)
      ;If $tolerance>0 Then $findImage = "*" & $tolerance & " " & $findImage
      If $HBMP = 0 Then
         MsgBox(0, "Inside If", "$HBMP = 0", 2)
         $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
      Else
         MsgBox(0, "Inside Else", "$HBMP = 0", 2)
         $result = DllCall("ImageSearchDLL.dll","str","ImageSearchEx","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
      EndIf
   Else
      MsgBox(0, "Inside Else", "IsString Method", 2)
      $result = DllCall("ImageSearchDLL.dll","str","ImageSearchExt","int",$x1,"int",$y1,"int",$right,"int",$bottom, "int",$tolerance, "ptr",$findImage,"ptr",$HBMP)
   EndIf

------------------------------------------------------------------------------------------------------------------------------------------

So while passing string , this code works fine. but if I am sending bitmap handle, its returning 0.

Also , plss help how can I check what is written in the methods "ImageSearchExt", "ImageSearchEx", "ImageSearch" of ImageSearchDLL.dll file.

Please help.

Thanks in advance.

Good Evening. Unfortunately I do not have an answer to that question. Sorry. It seems like you were able to get it working though.

 

 

Link to comment
Share on other sites

1 minute ago, BetaLeaf said:

Good Evening. Unfortunately I do not have an answer to that question. Sorry. It seems like you were able to get it working though.

hey, DLLCall method is returning an array with some value in it. but i m not getting how it is manipulating the array value to get the x-y coordinates because the same line of working for one image but not working for second image.

Link to comment
Share on other sites

Just now, VandanaS said:

hey, DLLCall method is returning an array with some value in it. but i m not getting how it is manipulating the array value to get the x-y coordinates because the same line of working for one image but not working for second image.

You can use _ArrayDisplay($aArray) to view the array. Have you tried plugging your files in using the example script above?

 

 

Link to comment
Share on other sites

4 minutes ago, BetaLeaf said:

Also, what are you trying to automate? I believe we could better help you if we better understood what you are trying to do.

I m simply searching an image on desktop. say, recyclebin icon on screen.

Aim : search that icon on screen and click on it to open it. thats it.

I m sharing the Imagesearch.au3 file and MyScriptFile.au3  here, please have a look, and correct me where i am doing wrong

ImageSearch.au3.au3

MyScript.au3

Link to comment
Share on other sites

Immediately I noticed this 3 things

 

1.

Do
   Sleep(300)
Until _FindImage($sImgPath)

You aren't checking if _FindImage() = 1 so your script exits the loop immediately after running _FindImage once. Change it to 

Do
   Sleep(300)
Until _FindImage($sImgPath) = 1

2.

MouseMove and MouseClick can be combined into one command. You want to use primary, not left click. Some users switch their left and right clicks and can be unreliable if you specify left or right. Use Primary or Secondary instead. Also, I assume you want to double click. In your script, you are telling it to left click once at x coordinate 2 and y at current mouse position. Try this instead:

MouseClick($MOUSE_CLICK_PRIMARY, $x, $y, 2, 5)

3. 

You uploaded ImageSearch.au3.au3 but you script is trying to include ImageSearch.au3 (you have an extra .au3)

 

 

Link to comment
Share on other sites

53 minutes ago, BetaLeaf said:

Also, if you are just trying to launch a program on the desktop, why not use ShellExecute() or Run()? They are much more reliable if you are just trying to find an icon the desktop to open it. 

yeah I agree that Run() or Execute() can also work. But i am trying to search an image on the screen , so that the same logic can be used for image search at a Browser or in any opened application also.

Link to comment
Share on other sites

34 minutes ago, BetaLeaf said:

There are much better ways to interact with browsers and opened applications. ImageSearch should be a last resort when all other methods have failed to work.

I will ask again. What are you trying to automate?

I want to hit a url by opening a browser and wait till it loads completely. then there will be 4 images on the webpage and i have to click one of the image.

that is what i am trying to do.

Link to comment
Share on other sites

47 minutes ago, BetaLeaf said:

Yea I'm certain that there are better ways to do this besides ImageSearch. What website?

currently , i am trying with www.autoitscript.com. but thats only for testing purpose.

If the logic works, we are gonna implement the same to access various servers ( e.g. Webmon) 

Link to comment
Share on other sites

On 8. únor 2017 at 2:37 AM, VandanaS said:

HI I downloaded the above zip file bt i m still getting error, even after placing imagesearchDLL.dll file in my c drive System32 location.

could u plss help. I am using 64 bit version of OS. Attaching the screenshot of the error msg. 

 

error.png

Try to compile your script as 32bit because this DLL is 32bit too.

 

Just add this line at top of your script and compile script from FULL Scite4AutoIt3 by F7.

#AutoIt3Wrapper_UseX64=n

 

Edited by Zedna
Link to comment
Share on other sites

  • 3 weeks later...

Hi, I am new to Autoit, may I ask who is developing this feature Image Search?

Is it a built-in function or it a UDF (User Defined Function)? If it a UDF then who/where I should follow to update the latest version of Image Search?

Thank you.

Link to comment
Share on other sites

its not an inbuilt feature. I have one UDF for image search , which i got from Forum only, and i edited as per my requirement.

But this code is working perfectly only for chrome browser.

You can find out on forum. Check on page 4 on forum in the topic image search. you will find ImageSaerch2015 example . Download it and use it.

 

 

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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