Jump to content

1 Screenshot

About This File

🚀 Quick API Overview of ImageSearch UDF for AutoIt

ImageSearchDLL is an ultra-fast image recognition library for AutoIt, leveraging advanced SIMD (AVX512/AVX2/SSE2) optimizations to deliver lightning-fast pixel-perfect and fuzzy image matching.

🌟 Key Capabilities

This library is designed for performance and flexibility, offering:

  •  Ultra-Fast Performance: Achieved through SIMD-accelerated algorithms.

  • 🔍 Fuzzy Matching: Allows tolerance-based color matching (0-255) to handle variations.

  • 🖼️ Multi-Scale Search: Enables searching for images scaled from 0.1x to 5.0x.

  • 💾 Smart Caching: Location and bitmap caching are used for fast repeated searches.

  • 🖥️ Multi-Monitor Support: Fully supports multi-monitor setups.


📚 Core Functions

These are the primary functions for image searching on the screen or within files:

  • _ImageSearch_Startup(): Initializes the ImageSearch library and loads the DLL.

  • _ImageSearch(): Searches for a target image on the screen, optionally within a specific region, with color tolerance, and can return multiple results. It also supports searching on a specific monitor index.

  • _ImageSearch_InImage(): Searches for a target image inside a source image file without performing a screen capture.


🛠️ Advanced & Utility Functions

For deeper control and performance optimization, the library provides several advanced utilities, particularly involving HBITMAP handles:

  • _ImageSearch_CaptureScreen(): Captures a specified screen region and returns an HBITMAP handle.

  • _ImageSearch_hBitmap(): Searches for a target HBITMAP inside a source HBITMAP (bypassing file I/O for speed).

  • _ImageSearch_hBitmapLoad(): Loads an image file into an HBITMAP handle, with optional background color specification.

  • _ImageSearch_Wait(): Waits for a specific image to appear on the screen, with customizable timeout and check intervals.

  • _ImageSearch_ClearCache(): Clears all cached bitmaps and location data.

  • _ImageSearch_GetVersion(): Returns the DLL version string.

  • _ImageSearch_GetSysInfo(): Provides detailed system information, including CPU features and cache status.

  • _ImageSearch_Shutdown(): Cleans up and unloads the library.


⚙️ Debugging and Error Handling

  • $g_bImageSearch_Debug: A global variable that, when set to True, enables debug information in search results.

  • $g_sLastDllReturn: A global variable that holds the debug information string, including timing, backend used, and cache details, from the last search operation.

  • Error Codes: All functions set the @error variable upon failure, with specific negative integer codes ranging from -1 (Invalid path) to -10 (Invalid monitor index) to help diagnose issues.

ImageSearch UDF is OpenSource, free for both personal and commercial use.

Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal

Edited by Trong


What's New in Version v3.1

Released

Source code inside!


User Feedback

Recommended Comments

OhItsThatGuy

Posted

Hi Trong, I love your work! Clean code, easy to read and use. I checked out your other projects as well!

Regarding your ImageSearch library, can I make a small request?

Having a scan function that can take a bitmap handle would be amazing. This would allow a finer control by eliminating the need to force a re-scan on each iteration of _ImageSearch(..)

_ImageSearch_ScanSnapshot($hImage = -1, $sImageFile, $iLeft = 0, $iTop = 0, $iRight = @DesktopWidth, $iBottom = @DesktopHeight, $iTolerance = 10, $iTransparent = -1, $iMultiResults = 1, $iCenterPos = 1, $iReturnDebug = 1, $fMinScale = 1.0, $fMaxScale = 1.0, $fScaleStep = 0.1, $iFindAllOccurrences = 0)

 

I realize we can use a delimiter | to search for multiple images but there are situations where a user would want to break images into categories and run different tolerance for each set, as well as focus on a particular area of the screen for each set.

We can take a snap shot using GDI+ through AutoIt as such:

Func _Img_TakeSnapshot($_iCanvasLeft=0,$_iCanvasTop=0,$_iCanvasWidth=@DesktopWidth,$_iCanvasHeight=@DesktopHeight)

    ; Clean up resources
    _GDIPlus_BitmapDispose($g_myImg_hImage)
    _WinAPI_DeleteObject($g_myImg_hMatWinCapture)

    ; Screen grab an area (should ideally be full screen)
    ; Use _Img_ScanSnapshotArea to scan

    ; Capture entire desktop or selected area
    $g_myImg_hMatWinCapture = _ScreenCapture_Capture("", $_iCanvasLeft, $_iCanvasTop, $_iCanvasWidth, $_iCanvasHeight, False)

    ; Create a Bitmap object from a bitmap handle (Using previously taken SnapShot)
    $g_myImg_hImage = _GDIPlus_BitmapCreateFromHBITMAP($g_myImg_hMatWinCapture)

    ; Save last scanned box dimensions
    $g_myImg_aAreaLastScan[0] = $_iCanvasLeft                           ; X Left Upper
    $g_myImg_aAreaLastScan[1] = $_iCanvasTop                            ; Y Left Upper
    $g_myImg_aAreaLastScan[2] = $_iCanvasLeft + $_iCanvasWidth          ; X Right Lower
    $g_myImg_aAreaLastScan[3] = $_iCanvasTop + $_iCanvasHeight          ; Y Right Lower
    $g_myImg_aAreaLastScan[4] = $_iCanvasWidth                          ; Box Width
    $g_myImg_aAreaLastScan[5] = $_iCanvasHeight                         ; Box Height

    ; Debug
    ;If $g_myImg_bDebugConsole = True Then ConsoleWrite("+ Snapshot:: (" & $_iCanvasLeft & ", " & $_iCanvasTop & ", " & $_iCanvasWidth & ", " & $_iCanvasHeight & ")" & @CRLF)

EndFunc

Or perhaps that can be handled by the dll. Those are just my thoughts, I'm not an expert a this.

Thank you for putting together this amazing UDF!

tubaba

Posted

First of all, thank you for providing a great user experience. However, I do have an issue to bring up. It seems that your DLL automatically corrects parts that exceed the screen, confining them within the frame of 0,0,@DesktopWidth,@DesktopHeight. But there are many application scenarios with multiple screens, which means that screen coordinates should not be limited to the range of the first screen. In earlier versions, I found that the coordinate correction was done in the UDF.

1.thumb.png.e0948e0023942a08c11910f8814928f1.png

tubaba

Posted

 

Get information of all screens

Global $__MonitorList[1][5], $__MonitorListBase[1][5]
$__MonitorListBase[0][0] = 0



_GetMonitors()



Func  _GetMonitors()
    $__MonitorList = $__MonitorListBase
    Local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnd;hwnd;ptr;lparam")
    DllCall("user32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0)
    DllCallbackFree($handle)
EndFunc   ;==>_GetMonitors

Func _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam)
    Local $Rect = DllStructCreate("int left;int top;int right;int bottom", $lRect)
    $__MonitorList[0][0] += 1
    ReDim $__MonitorList[$__MonitorList[0][0] + 1][5]
    $__MonitorList[$__MonitorList[0][0]][0] = $hMonitor
    $__MonitorList[$__MonitorList[0][0]][1] = DllStructGetData($Rect, "left")
    $__MonitorList[$__MonitorList[0][0]][2] = DllStructGetData($Rect, "top")
    $__MonitorList[$__MonitorList[0][0]][3] = DllStructGetData($Rect, "right")
    $__MonitorList[$__MonitorList[0][0]][4] = DllStructGetData($Rect, "bottom")
    Return 1 ; Return 1 to continue enumeration
EndFunc   ;==>_MonitorEnumProc

 

×
×
  • Create New...