Jump to content

HandleImgSearch (Image Search with ImageSearchDLL embedded)


Recommended Posts

  • lamnhan066 changed the title to HandleImgSearch (Image Search with ImageSearchDLL embedded)
  • 7 months later...

Sorry for bother

does any English ver. detail for function Description, Parameters and Return values (fully English ver.)

btw, _HandleImgSearch and _HandleImgWaitExist can search multiple img at same time (as A.png|B.png ... etc.)

thanks for au3 development, it's useful to me

thanks again !!

image.thumb.png.9278dabd9b730cae4a23f39cca14ff56.png

Edited by jimmy123j
Link to post
Share on other sites
  • 2 weeks later...
On 10/4/2020 at 9:45 AM, jimmy123j said:

does any English ver. detail for function Description, Parameters and Return values (fully English ver.)

I have no English version now. Sorry about that. I will add it later when I have free time and update on this thread.

Some default parameters (You can ask me here if you have another thing make you confused):

  • $hwnd: Handle of window you want to find in. If $Handle = "" then it will find images in your current screen.
  • $bmpLocal: Path of local image you want to find.
  • $x, $y, $iWidth, $iHeight: Area of $hwnd image you want to find in. Default values is full image.
  • $MaxImg: Max number of images you want to find (or return).
  • $Tolerance: (0 - 100) This is the variation of color you want to find. This parameter is helpfull when you want to share your app with your friend who use other devices.

Some default return values:

  • $aCords[0][0]: Total number of positions found.
  • $aCords[$i][0]: X coordinate of position $i.
  • $aCords[$i][1]: Y cooridinate of position $i.
  • $aCords[$i][2]: Bitmap width of position $i.
  • $aCords[$i][3]: Bitmap height of position $i.

The width and height of the bitmap are the same as your finding image.

On 10/4/2020 at 9:45 AM, jimmy123j said:

btw, _HandleImgSearch and _HandleImgWaitExist can search multiple img at same time (as A.png|B.png ... etc.)

No, it's now not support this. You can use this by add this a function like:

;~ I have not tested this code yet, but you can use something like this
Func _HandleMultiImgSearch($hwnd, $ImgsPath, $x = 0, $y = 0, $iWidth = -1, $iHeight = -1, $Tolerance = 15, $MaxImg = 1000)
    Local ImgsPathArray = StringSplit($ImgsPath, "|", 2) ;$ImgsPath = 'Path1|Path2|...|PathN'
    Local $Results
    For ImgPath in ImgsPathArray
        $Results = _ArrayAdd($Result, _HandleImgSearch($hwnd, $ImgPath, $x, $y, $iWidth, $iHeight, $Tolerance, $MaxImg))
    Next
    
    Return $Results
EndFunc

;~ Using this func
Local $ImgsPath = 'a.png|b.png|c.png'
Local $Results = _HandleMultiImgSearch($hwnd, $ImgsPath)
ConsoleWrite("> Total of finding images: " & Ubound($Results))
Local $count = 0
For $Coords in $Results
    ;~ An array of positions of each image
    $count += 1
    ConsoleWrite(">> Total of position found of image " & $count & " found: " & Ubound($Coords[0][0]))
Next

 

Edited by LTNhanSt94
Link to post
Share on other sites
  • 1 month later...

Sorry for bother, I found the _HandleCapture has some garbled word

that's why I try to use the _HandleCapture, but not working

I think the au3 file download from github had same issue

would you might to update the au3 file again

Thanks !!!

 

au3 download form Github

image.thumb.png.902de4ff62f5261fde9e300f4677760f.png

Github

image.thumb.png.f241a3a4c255eb8aaab5928a2deb403d.png

Edited by jimmy123j
Link to post
Share on other sites

Hello,

Thanks for this script, altho I have an Issue with it.
When I try to get HandleCapture working, it succesfully makes screenshot of control on given coordinates IF the window is on top. If I put any other window over it, the screenshot actually contains the overlapping window, blocking the window of interest, and inevitably failing finding the covered piece.

Setting "IsUser32" to True just produces black screenshots (of valid resolution tho) no matter if the window is infront or not.

Any idea where to point me? Feels to me like it might be problem with windows composition or something. Tried compiling and running as admin, same result. Win7 Pro, transparency of windows turned off

 

I dont really know what I did different now, but setting IsUser32 to True now works..
:D thanks for cool script!

Edited by MaximusCZ
Link to post
Share on other sites
  • 6 months later...

Yes you can.  You will need to use _GDIPlus_BitmapLockBits (see example) to transfer the bitmap into an 2D array.  You can also use _GDIPlus_BitmapGetPixel to read the color of a specific pixel.

Link to post
Share on other sites
On 7/19/2021 at 10:03 PM, Nine said:

Yes you can.  You will need to use _GDIPlus_BitmapLockBits (see example) to transfer the bitmap into an 2D array.  You can also use _GDIPlus_BitmapGetPixel to read the color of a specific pixel.

can i use any of the function here 

 
  ; _HandleImgSearch($hwnd, $bmpLocal, $x = 0, $y = 0, $iWidth = -1, $iHeight = -1, $Tolerance = 15, $MaxImg = 1000)
  ; _HandleImgWaitExist($hwnd, $bmpLocal, $timeOutSecs = 5, $x = 0, $y = 0, $iWidth = -1, $iHeight = -1, $Tolerance = 15, $MaxImg = 1000)
  ; _BmpImgSearch($SourceBmp, $FindBmp, $x = 0, $y = 0, $iWidth = -1, $iHeight = -1, $Tolerance = 15, $MaxImg = 1000)
  ; _HandleGetPixel($hwnd, $getX, $getY, $x = 0, $y = 0, $Width = -1, $Height = -1)
  ; _HandlePixelCompare($hwnd, $getX, $getY, $pixelColor, $tolerance = 15, $x = 0, $y = 0, $Width = -1, $Height = -1)
  ; _HandleCapture($hwnd, $x = 0, $y = 0, $Width = -1, $Height = -1, $IsBMP = False, $SavePath = "", $IsUser32 = False)
   
Link to post
Share on other sites
  • 1 month later...
On 2/17/2020 at 11:18 AM, LTNhanSt94 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 have a feature that will make it run slower is $MaxImg variable, this variable will allow you to return multiple positions of a finding image.

Some highlights:

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

Notes:

  • Only use to compile to 32 bit AutoIt version (It can completely run on Windows 64 bit)
  • Image use for searching should be a "24-bit Bitmap" format.
  • I included $IsUser32 variable in some places like _GlobalImgInit, _HandleCapture. This variable allowed you to use DllCall with "PrintWindow" parameter instead of _WinAPI_BitBlt with $SRCCOPY. $IsUser32 = True is useful for window explorer handle, $IsUser32 = False is useful for the emulator handle (NoxPlayer handle example included).
  • If hwnd parameter equal "", it will use 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 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 picture in picture instead of handle.
    • _HandleGetPixel: Get pixel in handle image.
    • _HandlePixelCompare: Compare color with pixel color of handle image.
    • _HandleCapture: Capture handle screen.

Source code: https://github.com/ltnhanst94/HandleImgSearch

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.

 

 

This isn't game automation ask but i got trouble with your UDF... GlobalImageSearch or HandleImageSearch can't scan my game window with title ""

Link to post
Share on other sites
  • Developers
24 minutes ago, Ranastic said:

can't scan my game window

Care go explain how this is not game related?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
  • 1 month later...

Friends, tell me, if I reduce the search area, the coordinates are returned no longer correct, if the default search area is ok.

You can somehow change the search area, get coordinates relative to the size of the control, and not the search area.


I'm sorry for the mistakes in communication, I'm writing through a translator.

Link to post
Share on other sites
9 hours ago, Ivantu said:

Friends, tell me, if I reduce the search area, the coordinates are returned no longer correct, if the default search area is ok.

You can somehow change the search area, get coordinates relative to the size of the control, and not the search area.


I'm sorry for the mistakes in communication, I'm writing through a translator.

In the current version, the result will relate to the search area, you just need to add (x, y) of the result to your search area coordinates to get the results you need.
 
For instance, you need to search in (30, 40, 300, 300) coordinates and get a result (10, 15) then the result you need is (30 + 10, 40 + 15).
Link to post
Share on other sites
2 hours ago, Ivantu said:

how can i know these coordinates before starting the search?

How can you do a specific area searching when you don't know these coordinates? Let's look at this function:

_HandleImgSearch($hwnd, $bmpLocal, $x = 0, $y = 0, $iWidth = -1, $iHeight = -1, $Tolerance = 15, $MaxImg = 1000)

You have to know at least one parameter in $x, $y, $iWidth, $iHeight to search for an area. Let's say you want to search in area [50, 60, 800, 600], so the function will look like:

_HandleImgSearch($hwnd, $bmpLocal, 50, 60, 800, 600)

and the result is `[1, [10, 20, 50, 50]]` which means it has 1 matched possition at [$x, $y, $width, $height] = [10, 20, 50, 50]. If you want to get the relative to your $hwnd coordinates then you need to add [10 + 50, 20 + 60] = [60, 80].

In addition, if you want to get the relative to your current whole screen coordinates, you need to use WinGetPos to get your current $hwnd coordinates and add the [x, y] coordinates to it like the above.

Link to post
Share on other sites
On 11/19/2021 at 12:54 PM, Ivantu said:

Please tell me where I can change the _Handle Img Search function so that it returns the coordinates I need?

I don 't want to just prescribe it manually every time )

I'm only bring the best way to get the results because the UDF can return multiple positions, so you can modify the UDF yourself to get the result that you want to or just write a function to parse the results, the second way may be easier to do because it won't break the core function of the UDF.

Edited by lamnhan066
Link to post
Share on other sites
  • Jos locked and unlocked this topic

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.

  • Similar Content

    • By SolemnStrike
      Hey, 
      I know the title sounds weird, but i couldn't find better words for it...
      I finally managed to have a working image search (yes yes i know image search is evil :p).
      I noticed that even if the script is compiled, the images have to be in my script folder.
      But i don't want that the images i'm searching for on the screen can be viewed, edited etc by every user.
      Is there a way to... uhm... put them in a file like .rar, but one that can't be easily opened? 🤔
       
      Edit: Now that i think of .rar, maybe using a .rar which is protected by a password... Can autoit search, open, extract, use and delete that? (I guess so, I didn't search for this yet, going to google that asap)
    • By lenclstr746
      Hi guys,
      Some functions of my script are running slowly. Very slow. What is the reason?
      My Code:
      <snip>
    • By Atoxis
      Howdy, I've gone through a lot of au3 forums, and I once had a working Imagesearch script that I got from here.  However, and i'm just totally not sure how but my imagesearch scripts aren't working anymore.
      I'm not new to au3 but i'm not the most experienced with it's syntax/commands.

      Anyways, I've looked over the big threads involving imagesearch.

      Does anyone have a working Imagesearch x64 for win10 that is currently working as of the date with the post.

      Dll's and what not is fine, just when I tell the script to run, I want to be able to find the image on the screen!
      Can't find a working copy so if anyone has one please send it my way lol.

      I've taken all the imagesearch downloads and what not and have played with them but I can't get any of them working on my end, despite others saying they're working.
      Thanks.
    • By Ian_Mac
      Func dg_get_images() $x1=0 $y1=0 ;MsgBox(0,"start","start") do $result = _ImageSearch("C:\Users\Server\Desktop\my project\image.png",1,$x1,$y1,0) until $result = 1; if $result=1 Then MouseMove($x1,$y1,3) MouseClick("left", $x1,$y1, 1) WinWait("[Title:TightVNC File Transfer]", "", 10) EndIf  this code works when i search the image, but when i change the location of the desktop icon it can't find the desktop icon anymore.   i wanna try image search area. but i don't know how to use it because i cant understand the parameter for the image search area.  please help me how to solve it thank you in advance.
    • By knuxfighter
      Hello. I've been working with Imagesearch library lately and it did a good work, although I moved to a new PC and didn't copy the old files with me so I downloaded the Imagesearch from the following post
       hoping that it will work. It doesn't though. First time I when I use (run as subscript to my code) the Imagesearch.au3, Scite finds errors (missing spaces). Ctrl+T (scite tidy) fixes these missing spaces but the script returns the following error on every run after:
      _ImageSearch('search.bmp', 0, $x, $y, 0) outputs
       
      "C:\Users\Knuckles\Desktop\AutoIt\include\ImageSearch.au3" (44) : ==> Subscript used on non-accessible variable.: If $result[0] = "0" Then Return 0 If $result^ ERROR no matter if I put the searched bmp in the script folder or folder img in the script directory. Also, it doesn't matter if the searched image on screen or not, it returns the same.

      Can you provide me any help please? I remember having these problems 2 years ago when I first met the imagesearch library also (I fixed it somehow though in that time). Seems nothing changed.

      Using this version posted in the following post gives the same error:
      Also I run windows 10 64bit and I have no shell options for script editing, running as x86 or whatever as I used to have on windows xp/7. I went through some steps like deleting a key in registry and I even reinstalled autoit and scite but that only resulted to au3 as unrecognized file format and not in getting back the menus and the icon on au3 files. Any thoughts on this?

      Edit: Installing 64-bit AutoIt and using 64bit ImageSearch is no change.
      code.au3

      FOUND WORKING: http://www.codebot.de/index.php/Thread/12713-Imagesearch-au3-funktioniert-nicht/
       but why is this one working and the original aren't? :(
×
×
  • Create New...