Jump to content

Imagesearch function not work on some computers


Recommended Posts

Hello im using Imagesearc function and almost always it works great but i have seen on 2 computers this function not works. I dont know why and cant figure out whats going on.

 

So there are windows 8 64bit and 10 64bit.

I use script like below so in program folder I got there 4 files

  • ImageSearchDLLx32
  • ImageSearchDLLx64
  • msvcr110
  • msvcr110d

And it should work I think, it would chose proper file to windows and use it.

Should I copy Imagesearch to windows directory or system32 directory too or if it is on program folder it is enough?

I have tried other imagesearch dll and with no success.

Tried change resolution, colors, some graphic settings etc and no effect

 

Maybe someone know what can causing problem with functionality imagesearch function?

And where I should finally put imagesearch dll file to be sure it would be loaded correctly?

 

There are these 4 files

https://mega.nz/#!GkMUFSoC!ND0HlpWGZYywxMEF7Nan5YOUdBUPPBE7VAd0TM1Lhm8

 

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=x64.Exe
#AutoIt3Wrapper_Outfile_x64=x32.Exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#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
#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>

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

#include <ImageSearchUDF.au3>

#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


HotKeySet("h", "search")


Global $x = 0, $y = 0


Func search()
    Local $img = _ImageSearch('img.bmp', 0, $x, $y, 0)
        If $img = 1 Then
            MsgBox("", "", "FOUND IMAGE")
        Else
            MsgBox("", "", "NOT FOUND IMAGE")
        EndIf
EndFunc


While 1
    sleep(200)
WEnd







#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
Exit
#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 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

 

 

 

 

Link to comment
Share on other sites

I ask this each time I see image search as a problem - what is the name of the application you are trying to automate? I ask for Imagesearch is the WORST way to interact with an application 99% of the time. It is normally best practice to hook into the control in question. Saying that, if we know the application, then we most likely have the code you need to solve your problem. 

Link to comment
Share on other sites

I know its not best way to do app. it would be better to move the bits and reading from memory . 

But

i have ready extensive program in autoit which use a lot of imagesearch functions.

that was the assumption it would be based on images, pixels, colors .  It works great except 2 computers.

I will not now rewrite the whole program now cause it its written using not the best practices.

So u not help me

Link to comment
Share on other sites

then be prepared for a world of hurt. it will probably take you longer to figure this out and get it working than to do it talking to controls.

Why do colors look different on different screens?

look for the differences in the configuration of the good ones vs the bad 2. maybe you can change a color setting or something.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

8 hours ago, Miliardsto said:

I know its not best way to do app. it would be better to move the bits and reading from memory . 

But

i have ready extensive program in autoit which use a lot of imagesearch functions.

that was the assumption it would be based on images, pixels, colors .  It works great except 2 computers.

I will not now rewrite the whole program now cause it its written using not the best practices.

So u not help me

I will help you WHEN you name the application you are automating. So far you refuse to answer the question

Link to comment
Share on other sites

  • 1 year later...

Sorry to resurrect this old post, but I found Miliardsto's reply to his own issue unhelpful for figuring out what could cause imagesearch to not work on some  PC's.  As I was running into the same issue trying to automate some Citrix windows that do not contain controls, but only images.  Hopefully this helps someone with the same problem.

Check the monitor's Display settings and make sure the size of text, apps, and other items is set to the same percentage as when you took the screen shot of the image file you are searching.  I ended up creating 2 files for every image being searched.  One at 100% and the other at 125%, as our company laptops default to that percentage.  Now imagesearch works on all our PCs.

Link to comment
Share on other sites

  • Moderators

Not sure why this thread was reported 2 years after the fact, but it is a good example of when (during the time of the original post) a thread should have just been reported, rather than badgering the OP while playing detective. As has been stated many times before:

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...