Jump to content

ImageSearch2015 on Windows 10 x64 - (Moved)


jmaruca
 Share

Recommended Posts

Hi folks,

I recently watched a YouTube video about Image Searching and I am very keen to get it to work on Windows 10 x64.  I downloaded all the files, etc, but it just doesn't work for me; it doesn't do anything …. can anyone assist?; please see my sample code below; many thanks in advance.

My Code:

; iSearch
#include <ImageSearch2015.au3>

$x1=0
$y1=0

$picture = "D:\AutoIT\1.png"
do
$result = _ImageSearch($picture,1,$x1,$y1,0)

ConsoleWrite($result)
until $result = 1
if $result=1 Then
    MouseMove($x1,$y1,10)
else
    MsgBox(0,"MSG","End")
EndIf

 

ImageSearch2015.au3

#AutoIt3Wrapper_UseX64=y ; Set to Y or N depending on your situation/preference!!
#include-once
#include <WinAPIFiles.au3> ; for _WinAPI_Wow64EnableWow64FsRedirection
#include <ScreenCapture.au3> ;_ScreenCapture_CaptureWnd etc. ;using this in the example to create a test image, otherwise not neccessary here
#RequireAdmin
#Region When running compiled script, Install needed DLLs if they don't exist yet
If Not FileExists("ImageSearchDLLx32.dll") Then FileInstall("ImageSearchDLLx32.dll", "ImageSearchDLLx32.dll", 1);FileInstall ( "source", "dest" [, flag = 0] )
If Not FileExists("ImageSearchDLLx64.dll") Then FileInstall("ImageSearchDLLx64.dll", "ImageSearchDLLx64.dll", 1)
If Not FileExists("msvcr110d.dll") Then FileInstall("msvcr110d.dll", "msvcr110d.dll", 1);Microsoft Visual C++ Redistributable dll x64
If Not FileExists("msvcr110.dll") Then FileInstall("msvcr110.dll", "msvcr110.dll", 1);Microsoft Visual C++ Redistributable dll x32
#EndRegion

Local $h_ImageSearchDLL = -1; Will become Handle returned by DllOpen() that will be referenced in the _ImageSearchRegion() function

#Region TESTING/Example
Local $bTesting = False; Change to TRUE to turn on testing/example

If $bTesting Then
 cr(">" & "_ImageSearchStartup()=" & _ImageSearchStartup(), 2)
 OnAutoItExitRegister(_ImageSearchShutdown)

 cr("!Testing...")
 ;using Notepad as a simple example
 #Region Notepad Snapshot Creation
 $hWin = WinGetHandle("[CLASS:Notepad]")
 If Not IsHWnd($hWin) Then
  If Run("notepad.exe") = 0 Then cr("Couldn't run notepad.exe")
  Local $hWin = WinWait("[CLASS:Notepad]", "", 10)
  If $hWin = 0 Then cr("Notepad WinWait Timeout!")
 EndIf
 WinSetState($hWin, "", @SW_RESTORE)
 WinSetState($hWin, "", @SW_SHOW)
 WinActivate($hWin)
 Local $testimage = "24bit.bmp"
 _ScreenCapture_CaptureWnd($testimage, $hWin, 0, 0, -1, -1, False);_ScreenCapture_CaptureWnd ( $sFileName, $hWnd [, $iLeft = 0 [, $iTop = 0 [, $iRight = -1 [, $iBottom = -1 [, $bCursor = True]]]]] )
 cr("made Notepad Window screenshot")
 #EndRegion Notepad Snapshot Creation

 #Region Test if application appeared
 Local $y = 0, $x = 0, $result
 $result = _ImageSearch($testimage, 1, $x, $y, 0, 0);_ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
 If $result = 1 Then
  cr("! $result=" & $result, 1)
  MouseMove($x, $y, 0)
  cr("+" & "recognised notepad! moved mouse to center of notepad!")
 Else
  cr("! $result=" & $result, 1)
  Exit
 EndIf
 #EndRegion Test if application appeared

 #Region Test if application vanished
 WinSetState($hWin, "", @SW_MINIMIZE)
 Local $y = 0, $x = 0, $result
 $result = _ImageSearch($testimage, 1, $x, $y, 0, 0);_ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
 If $result = 1 Then
  cr("! $result=" & $result, 1)
  Exit
 Else
  cr("! $result=" & $result, 1)
  cr("+" & "notepad dissapeared!")
 EndIf
 #EndRegion Test if application vanished
 cr()
 cr("!Test finished")
EndIf

#EndRegion TESTING/Example

#Region ImageSearch Startup/Shutdown
Func _ImageSearchStartup()
 _WinAPI_Wow64EnableWow64FsRedirection(True)
 $sOSArch = @OSArch ;Check if running on x64 or x32 Windows ;@OSArch Returns one of the following: "X86", "IA64", "X64" - this is the architecture type of the currently running operating system.
 $sAutoItX64 = @AutoItX64 ;Check if using x64 AutoIt ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt.
 If $sOSArch = "X86" Or $sAutoItX64 = 0 Then
  cr("+>" & "@OSArch=" & $sOSArch & @TAB & "@AutoItX64=" & $sAutoItX64 & @TAB & "therefore using x32 ImageSearch DLL")
  $h_ImageSearchDLL = DllOpen("ImageSearchDLLx32.dll")
  If $h_ImageSearchDLL = -1 Then Return "DllOpen failure"
 ElseIf $sOSArch = "X64" And $sAutoItX64 = 1 Then
  cr("+>" & "@OSArch=" & $sOSArch & @TAB & "@AutoItX64=" & $sAutoItX64 & @TAB & "therefore using x64 ImageSearch DLL")
  $h_ImageSearchDLL = DllOpen("ImageSearchDLLx64.dll")
  If $h_ImageSearchDLL = -1 Then Return "DllOpen failure"
 Else
  Return "Inconsistent or incompatible Script/Windows/CPU Architecture"
 EndIf
 Return True
EndFunc   ;==>_ImageSearchStartup

Func _ImageSearchShutdown()
 DllClose($h_ImageSearchDLL)
 _WinAPI_Wow64EnableWow64FsRedirection(False)
 cr(">" & "_ImageSearchShutdown() completed")
 Return True
EndFunc   ;==>_ImageSearchShutdown
#EndRegion ImageSearch Startup/Shutdown

#Region ImageSearch UDF;slightly modified
; ------------------------------------------------------------------------------
;
; 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
;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparency; can be omitted if
;                                  not needed
;
; Return Value(s):  On Success - Returns True
;                   On Failure - Returns False
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
 Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance, $transparency)
EndFunc   ;==>_ImageSearch

Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance = 0, $transparency = 0);Credits to Sven for the Transparency addition
 If Not FileExists($findImage) Then Return "Image File not found"
 If $tolerance < 0 Or $tolerance > 255 Then $tolerance = 0
 If $h_ImageSearchDLL = -1 Then _ImageSearchStartup()

 If $transparency <> 0 Then $findImage = "*" & $transparency & " " & $findImage
 If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage
 $result = DllCall($h_ImageSearchDLL, "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
 If @error Then Return "DllCall Error=" & @error
 If $result = "0" Or Not IsArray($result) Or $result[0] = "0" Then Return False

 $array = StringSplit($result[0], "|")
 If (UBound($array) >= 4) Then
  $x = Int(Number($array[2])); Get the x,y location of the match
  $y = Int(Number($array[3]))
  If $resultPosition = 1 Then
   $x = $x + Int(Number($array[4]) / 2); Account for the size of the image to compute the centre of search
   $y = $y + Int(Number($array[5]) / 2)
  EndIf
  Return True
 EndIf
EndFunc   ;==>_ImageSearchArea

;===============================================================================
;
; 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
;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparency can be omitted if
;                                  not needed
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImageSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
 $waitSecs = $waitSecs * 1000
 $startTime = TimerInit()
 While TimerDiff($startTime) < $waitSecs
  Sleep(100)
  If _ImageSearch($findImage, $resultPosition, $x, $y, $tolerance, $transparency) Then
   Return True
  EndIf
 WEnd
 Return False
EndFunc   ;==>_WaitForImageSearch

;===============================================================================
;
; 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
;                   $transparent - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparent; can be omitted if
;                                  not needed
;
; Return Value(s):  On Success - Returns the index of the successful find
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
 $waitSecs = $waitSecs * 1000
 $startTime = TimerInit()
 While TimerDiff($startTime) < $waitSecs
  For $i = 1 To $findImage[0]
   Sleep(100)
   If _ImageSearch($findImage[$i], $resultPosition, $x, $y, $tolerance, $transparency) Then
    Return $i
   EndIf
  Next
 WEnd
 Return False
EndFunc   ;==>_WaitForImagesSearch
#EndRegion ImageSearch UDF;slightly modified

#Region My Custom ConsoleWrite/debug Function
Func cr($text = "", $addCR = 1, $printTime = False) ;Print to console
 Static $sToolTip
 If Not @Compiled Then
  If $printTime Then ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ")
  ConsoleWrite($text)
  If $addCR >= 1 Then ConsoleWrite(@CR)
  If $addCR = 2 Then ConsoleWrite(@CR)
 Else
  If $printTime Then $sToolTip &= @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " "
  $sToolTip &= $text
  If $addCR >= 1 Then $sToolTip &= @CR
  If $addCR = 2 Then $sToolTip &= @CR
  ToolTip($sToolTip)
 EndIf
 Return $text
EndFunc   ;==>cr
#EndRegion My Custom ConsoleWrite/debug Function

 

Edited by JLogan3o13
Removed Word Wall
Link to comment
Share on other sites

Hi Skeletor,

Yes, it was the YouTube video with Heath; it appeared to have worked well during the demo.  When I run it and empty Notepad appears.  Also, the code I used was as follows; are you able to shed any light on this?, thank you.

; iSearch
#include <ImageSearch2015.au3>
$x1=0
$y1=0

$picture = "D:\AutoIT\1.png"
do
$result = _ImageSearch($picture,1,$x1,$y1,0)
ConsoleWrite($result)
until $result = 1
if $result=1 Then
    MouseMove($x1,$y1,10)
else
    MsgBox(0,"MSG","End")
EndIf

Link to comment
Share on other sites

Interesting, is the dll in script dir?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

This code works if you have a sample picture included... so let's say your 1.png is a picture of a folder. You would need to have a sample of the folder.
Windows 98 to Windows 10 have different icons, so make sure you have:

$result = _ImageSearch("1.png",0,$x1,$y1,0)
    $result2 = _ImageSearch("2.png",0,$x1,$y1,0)
    $result3 = _ImageSearch("3.png",0,$x1,$y1,0)

and do a If..ElseIf... condition.

Kind Regards
Skeletor

"Coffee: my defense against going postal."

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi Folks,

The Search Image code is providing interesting results which does not make sense, when running the code below, it presents Notepad for a few seconds, then closes when using - setting variable: Local $bTesting = False  (ImageSearch2015.au3); I am not sure where this is going wrong here???; if someone can shed some light on this would be sensational, thank you.

Debug Pane output

+>17:26:59 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\joe\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\joe\AppData\Local\AutoIt v3\SciTE
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:D:\AutoIT\image1.au3
+>17:26:59 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "D:\AutoIT\image1.au3"   
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
+>@OSArch=X64 @AutoItX64=0 therefore using x32 ImageSearch DLL
>_ImageSearchStartup()=True

!Testing...
made Notepad Window screenshot
! $result=True
+recognised notepad! moved mouse to center of notepad!
! $result=False
+notepad dissapeared!

!Test finished
>_ImageSearchShutdown() completed
+>17:27:00 AutoIt3.exe ended.rc:0
+>17:27:00 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 2.349

 

AutoIT Code:

; image Search
#include <ImageSearch2015.au3>

$x1=0
$y1=0

do
$result = _ImageSearch("1.png",0,$x1,$y1,0)
ConsoleWrite($result)
until $result = 1
if $result=1 Then
    MouseMove($x1,$y1,10)
else
    MsgBox(0,"MSG","End")
EndIf

Link to comment
Share on other sites

  • 1 year later...

Slight bug in ImageSearch2015:

Hi Folks,

the great tool ImagSearch2015 contains some slight bugs in documentation and code. Here's what I found:

1. Most of the files involved need a complete path to 'em in order to operate reliably. Please consider providing the file path like here for the DLL to be used:

$h_ImageSearchDLL = DllOpen(@ScriptDir & "\" & "ImageSearchDLLx32.dll")

2. The function does search only on the current or primary screen:

Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
 Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance, $transparency)

@DesktopWidth & @DesktopHeight return the parameters of the currently active screen only. This might be intended, but should be documented.

 

Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance = 0, $transparency = 0)
    local $iwidth = _WinAPI_GetSystemMetrics(78), $iheight = _WinAPI_GetSystemMetrics(79)                           
    Return _ImageSearchArea($findImage, $resultPosition, 0, 0, $iwidth, $iheight, $x, $y, $iTolerance, $transparency)

  as a replacement.

Otherwise the call could be quite unreliable depending where your intersting image is placed on the screen.

 

Thanx to the original authors!

-- LuI

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

  • Recently Browsing   0 members

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