Jump to content

Imagesearch problem


Bou
 Share

Recommended Posts

Helllo guys

I have tried to search the forums before posting but nothing solved my problem :(

I included the "imagesearch.au3" and its DLL today and i tried to run it, but i have faced couple of problems, i have tried to install 32x version 64x ... i have tried the old searchimage dll and au3, and the new ones, but nothing solves the problem, not even running it as an admin, installing SciTE4 all over again... :(

 

Could you guys please help me ? 

Thanks in advance.

 

Untitled.png

Link to comment
Share on other sites

  • Moderators

Bou,

Welcome to the AutoIt forums.

Posting images of your code is not a great help, much better to use Code tags - see here how to do it.

M23

 

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

Okay, sorry didnt know... here's my code:

#include <imagesearch.au3>

HotKeySet('=', 'start')
$x = 0
$y = 0

Func Start()
    $search = _ImageSearch('capture.bmp', 0, $x, $y, 0)
    If $search = 1 Then
        MouseMove($x, $y, 10)
    EndIf
EndFunc   ;==>Start

While 1
    Sleep(100)
WEnd

and here's the ImageSearch.au3's code:

#include-once
; ------------------------------------------------------------------------------
;
; 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
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0 
;
; 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)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
    ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)

    ; If error exit
    if $result[0]="0" then return 0
    
    ; Otherwise get the x,y location of the match and the size of the image to
    ; compute the centre of search
    $array = StringSplit($result[0],"|")
   
   $x=Int(Number($array[2]))
   $y=Int(Number($array[3]))
   if $resultPosition=1 then
      $x=$x + Int(Number($array[4])/2)
      $y=$y + Int(Number($array[5])/2)
   endif
   return 1
EndFunc

;===============================================================================
;
; 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
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0 
;
;
;===============================================================================
Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        sleep(100)
        $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance)
        if $result > 0 Then
            return 1
        EndIf
    WEnd
    return 0
EndFunc

;===============================================================================
;
; 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
;
; 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)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        for $i = 1 to $findImage[0]
            sleep(100)
            $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
            if $result > 0 Then
                return $i
            EndIf
        Next    
    WEnd
    return 0
EndFunc

 

Link to comment
Share on other sites

Do you work with a 64bit windows?

Maybe you have to add "#AutoIt3Wrapper_UseX64 = Y" on the top of your script.

#AutoIt3Wrapper_UseX64 = Y

#include <imagesearch.au3>

HotKeySet('=', 'start')
$x = 0
$y = 0

Func Start()
    $search = _ImageSearch('capture.bmp', 0, $x, $y, 0)
    If $search = 1 Then
        MouseMove($x, $y, 10)
    EndIf
EndFunc   ;==>Start

While 1
    Sleep(100)
WEnd

 

Edited by nobbitry
Link to comment
Share on other sites

8 minutes ago, InunoTaishou said:

This has been asked a lot, a lot of posts in the imagesearch thread, and hundreds of posts on other forums.

If (IsArray($result) = False) Then Return 0

Just check to see if it is an array

 

 

Thank you so much. its working now. but only when i "right click" Run script (86x), anyway to make it work with 64x :D?

Link to comment
Share on other sites

Also there seems to be a problem in the SearchImage code, if my code doesnt find the picture looking for

The error:

"C:\Program Files (x86)\AutoIt3\Include\ImageSearch.au3" (46) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$x = IsArray(Int(Number($array[2])))
$x = IsArray(Int(Number(^ ERROR

The original part of the code that has the problem:

; Otherwise get the x,y location of the match and the size of the image to
    ; compute the centre of search
    $array = StringSplit($result[0], "|")

    $x = Int(Number($array[2]))
    $y = Int(Number($array[3]))
    If $resultPosition = 1 Then
        $x = $x + Int(Number($array[4]) / 2)
        $y = $y + Int(Number($array[5]) / 2)
    EndIf
    Return 1
EndFunc   ;==>_ImageSearchArea

 

Link to comment
Share on other sites

  • Moderators

You're right, it doesn't help - sounds like you've already seen the forum rules and know this is a topic that is not open for discussion.

If you haven't, you need to read them before you post again - especially the part about game automation.

Edited by JLogan3o13

"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

  • Recently Browsing   0 members

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