Jump to content

HandleImgSearch (Image Search with ImageSearchDLL embedded)


lamnhan066
 Share

Recommended Posts

_BmpImgSearch also works great with *.png files :)

But i still did not understand the parameters in this function (apart from the pictures)
In the following code, i am searching recycle-bin on my desktop:

#include <Array.au3>
#include "HandleImgSearch.au3"

Local $Find_this_image = @ScriptDir & '\recycle.PNG'
Local $In_this_image = @ScriptDir & '\desktop.PNG'

Local $aResult = _BmpImgSearch($In_this_image, $Find_this_image, 0, 0, -1, -1, 30, 1)
_ArrayDisplay($aResult)

Result is as follwos and i understand all values:
image.png.484a5cd38ea3e6b1cef1f3c31d276ef0.png

Is it also possible to search in a specific area (like with  _imagesearcharea)? I thought that the parameters $x, $y, $iWidth, iHeight can be used for this, but it seems this is not the case. I get the same result, if i use these parameters with 0,0,1,1 or 100,100,100,100  or any other combination (instead of 0,0,-1,-1). What are theses parameters for, please?

Can you please tell me the min/max values for $Tolerance? 

And is it correct, that $MaxImg defines the max number of (best) results?
When i use the code above but change _BmpImgSearch like this:

Local $aResult = _BmpImgSearch($In_this_image, $Find_this_image, 0, 0, -1, -1, 200,300)

Then i get 34 results with different locations:
image.png.d102c231f796309e4bda2b5d568b42cd.png

But if i change it slightly to:

Local $aResult = _BmpImgSearch($In_this_image, $Find_this_image, 0, 0, -1, -1, 230,300)

Then all results have same location:

image.png.26009f68440d2b0c8f98bada73bc8083.png


Or one example with extreme values:

Local $aResult = _BmpImgSearch($In_this_image, $Find_this_image, 0, 0, -1, -1, 500,1000)


image.png.dcada96d09858c13dbfcb9d68f4ba301.png

Sorry for this long post, this function is really great, just would like  to understand the parameters in order to use it in a senseful way.
Many thanks

 

Link to comment
Share on other sites

  • 2 months later...

Hi @tobius,

On 10/10/2022 at 4:10 AM, tobius said:

Is it also possible to search in a specific area (like with  _imagesearcharea)? I thought that the parameters $x, $y, $iWidth, iHeight can be used for this, but it seems this is not the case.

Those are the right parameters in your case, but I think that function has issues because its body doesn't use those parameters (I'm not sure about this because it is quite a long time but I still have a quick rewrite of the function at the end of this post).

On 10/10/2022 at 4:10 AM, tobius said:

Can you please tell me the min/max values for $Tolerance? 

This parameter is also known as color in bounds or color variation of each pixel, it has a value between 0 and 255 (usually between 15 and 30 is used). When the value is 0, it means that all pixel colors must be the same between the finding image and the result image.

On 10/10/2022 at 4:10 AM, tobius said:

And is it correct, that $MaxImg defines the max number of (best) results?

This is the max number of results. It will increase the performance if you know the max number of results that you need.

Here is a quick rewrite of that function (without testing). Please try it and let me know the result:

Func _BmpImgSearch($SourceBmp, $FindBmp, $x = 0, $y = 0, $iWidth = -1, $iHeight = -1, $Tolerance = 15, $Transparency = "", $MaxImg = 1000)
    Local $SourceBitmap = _GDIPlus_BitmapCreateFromFile($SourceBmp)
    If @error Then Return SetError(1, 0, 0)

    Local $Right = $iWidth + $x
    If $iWidth = -1 Or $iWidth = Default Then $Right = _GDIPlus_ImageGetWidth($SourceBitmap) + $x
    Local $Bottom = $iHeight + $y
    If $iHeight = -1 Or $iHeight = Default Then $Bottom = _GDIPlus_ImageGetHeight($SourceBitmap) + $y

    Local $pos = __ImgSearch($x, $y, $Right, $Bottom, $FindBmp, $SourceBitmap, $Tolerance, $Transparency, $MaxImg)

    Return SetError(@error, 0, $pos)
EndFunc   ;==>_BmpImgSearch

 

Link to comment
Share on other sites

  • 1 month later...
On 2/17/2020 at 1:18 AM, lamnhan066 said:

Today, I will share my work with image search in inactive windows (windows that run in the background) with tolerances (variations).

After a long time of searching and using image search UDF on the internet. I combined all of that with my experienced and created a UDF name HandleImgSearch.

I have embedded the .dll file in this script so it doesn't need any external files, just include it and run. However, this UDF uses a pure AutoIT loop to make the multiple positions returned work so it may be slower if you set the $MaxImg to a high number.

Some highlights:

  • Very fast with imagesearchdll embedded, no external files required.
  • Tolerances and Max Images are supported.
  • Optimized.
  • Use with a handle or full screen easily.
  • Included global functions, so you can run multiple functions in one capture.
  • Examples used for testing included.

Notes:

  • Only used to compile to 32-bit AutoIt version (It can completely run on Windows 64-bit)
  • The image used for searching should be in a "24-bit Bitmap" format.
  • I included the $IsUser32 variable in some places like _GlobalImgInit, _HandleCapture. This variable allowed you to use DllCall with the "PrintWindow" parameter instead of _WinAPI_BitBlt with $SRCCOPY. $IsUser32 = True is useful for the window explorer handle, $IsUser32 = False is useful for the emulator handle (NoxPlayer handle example included).
  • If hwnd parameter equals "", it will use the whole screen instead.

Functions:

  • Global Functions: Run multiple functions with one capture.
    • _GlobalImgInit: Initialization variables.
    • _GlobalImgCapture: Capture the handle.
    • _GlobalGetBitmap: Get captured bitmap handle.
    • _GlobalImgSearch: This is the main function of this UDF.
    • _GlobalGetPixel: Get pixel color in the captured image.
    • _GlobalPixelCompare: Compare pixel color with captured image pixel color.
  • Handle Functions: Capture every time.
    • _HandleImgSearch: This is the main function of this UDF. Search for images in the handle of the window with the tolerance and maximum image options.
    • _BmpImgSearch: Search the picture in the picture instead of the handle.
    • _HandleGetPixel: Get pixel in the handle image.
    • _HandlePixelCompare: Compare color with pixel color of handle image.
    • _HandleCapture: Capture handle screen.

Source code: 

Thanks to:

  • ImageSearchDLL (Author: kangkeng 2008)
  • MemoryCall (Author: Joachim Bauch)
  • BinaryCall (Author: Ward)

GAMERS - Asking for help with ANY kind of game automation is against the forum rules. DON'T DO IT.

 

 

it works for 3 monitors?

cause im using to scan image on left monitor assuming the middle one is the main, and its not working... 

Link to comment
Share on other sites

  • 3 months later...

the HandleCapture does not save images to the provided path. here is what i tried, it only returns a handle.
 

;~ #RequireAdmin
#include <Array.au3>
#include ".\HandleImgSearch.au3"

Local $handle = WinGetHandle(0x001A0AEA)
  
Local $x = 0
Local $y = 0
Local $width = 800
Local $height = 600
Local $isBMP = False
Local $savePath = @ScriptDir & "\captured_image.bmp"
  
Local $result = _HandleCapture($handle, $x, $y, $width, $height, $isBMP, $savePath, False)
  
If @error Then
    MsgBox(16, "Error", "Capture failed. Error code: " & @error)
Else
    MsgBox(64, "Success", "Capture successful. " & $result)
EndIf
Edited by ScorpX
Link to comment
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
 Share

×
×
  • Create New...