Jump to content

Image not found


Recommended Posts

Hey folks, it's been so much time since I still have this issue, I'm trynna make a script for a Identikit software that I made, we're talking about simple stuff.

I'm still new with Scripting in AutoIT and generally with Basic so please explain me how to solve the problem step by step.

Basically my script should recognise when I've choosed wrong or right with some images that pop up in my screen when I try to interact with my Identikit software.

this is the script:

https://pastebin.com/TjRs9FLu

and this is the Autocheck issue:

https://ibb.co/sJtTnZb

Thanks anyone for paying attention, I hope you guys can help me

Link to comment
Share on other sites

  • Developers

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Also:  Please post the script and other info simply in the post in a CodeBlock <> in stead of linking pastebin so people don't have to go to other sites to get all info. ;) 

Jos

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 comment
Share on other sites

Hey folks, it's been so much time since I still have this issue, I'm trynna make a script for a Identikit software that I made, we're talking about simple stuff.

I'm still new with Scripting in AutoIT and generally with Basic so please explain me how to solve the problem step by step.

Basically my script should recognise when I've choosed wrong or right with some images that pop up in my screen when I try to interact with my Identikit software.

this is the script:

#include <AutoItConstants.au3>
#include "ImageSearch_64_bit/Imagesearch.au3"
#include <Misc.au3>
HotKeySet("{f1}", "myExit")
#AutoIt3Wrapper_UseX64=y
$x=0
$y=0

Global $Counter = 1

init(); changed all that to a function to call one time(  readability)

while 1
    $timer = timerinit()
    Do
        MouseClick("Left", 779, 600, 1, 2) ; Red
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 607, 361, 1, 2) ;Blue
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 779, 600, 1, 2) ;Red
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 779, 600, 1, 2) ;Red
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 607, 361, 1, 2) ;Blue
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        sleep(2000)
        MouseClick("Left", 607, 361, 1, 2) ;Blue
        sleep(500)
        MouseClick("Left", 896, 685, 1, 2)
        Call ( "myResult", $Counter )
        Sleep(2000)
    until timerdiff($timer) > 960;
WEnd


func myResult($Counter)
    ;ConsoleWrite(" Function myresult is called " & @CRLF)
    $Variable = _ImageSearch("quinto.bmp", 0, $x,$y,0) Or _ImageSearch("quarto.bmp", 0, $x,$y,0)
    If IsArray($Variable) = True Then
        ConsoleWrite(" Win is found " & @CRLF)
        MouseClick("Left", 1110, 684, 1, 1)
        MouseClick($MOUSE_CLICK_LEFT,  $Variable[0], $Variable[1], $Counter)
    Else
        $Variable = _ImageSearch("primo.bmp", 0,$x,$y,0) Or _ImageSearch("secondo.bmp", 0, $x,$y,0) Or _ImageSearch("terzo.bmp", 0, $x,$y,0)
        If IsArray($Variable) = True Then
            ConsoleWrite(" no win is found " & @CRLF)
            For $vElement In $Variable
                $Counter = $Counter * 2
            Next
            MouseClick($MOUSE_CLICK_LEFT, $Variable[0], $Variable[1], $Counter)
        EndIf
    EndIf
EndFunc

Func init()
    WinActivate("Identikit")
    WinWaitActive("Identikit", "", 10); wait for 10 sec to appear
    MouseClick("Left", 746, 666, 1, 1)
    sleep(4000)
    MouseWheel($MOUSE_WHEEL_DOWN, 7)
    sleep(500)
    MouseClick("Left", 350, 798, 1, 1)
    sleep(2000)
    MouseClick("Left", 1010, 712, 1, 1)
    sleep(16000)
    MouseWheel($MOUSE_WHEEL_DOWN, 1)
    sleep(1000)
EndFunc

func myExit()
    Exit
EndFunc

and I'll leave a picture with the Autocheck screenshot so you guys can see the error

anew.PNG

Link to comment
Share on other sites

  • Developers

Sorry to be a pain, but just stick to the one topic I already moved for you.

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 comment
Share on other sites

  • Developers

Have you checked what statement is on line 44 of the Imagesearch.au3 include you use?

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 comment
Share on other sites

  • Developers

Don't know what the reason is but guess some error checking is missing in that UDF.
I don't know that include as it isn't a standard include so do you have a link to the sourcecode so it can be checked why you get the error.

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 comment
Share on other sites

please help me, this is the library

#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, $HBMP=0)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP)
EndFunc

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

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

 

Link to comment
Share on other sites

If you look at help file for DllCall you would have notice that :

Return Value
Success: an array. See remarks. 
Failure: sets the @error flag to non-zero. 
@error: 1 = unable to use the DLL file,
2 = unknown "return type",
3 = "function" not found in the DLL file,
4 = bad number of parameters,
5 = bad parameter. 

$Result is not an array in case of failure.  It can be any of the errors mentioned. But my guess is you are not using the right (x86 vs x64) dll or the dll is missing (wrongly placed).

Edited by Nine
Link to comment
Share on other sites

14 hours ago, pixelsearch said:

I maybe mistaken, but how could ever the following test be True in Func myResult() when _ImageSearch() and _ImageSearchArea() Returns are only 0 or 1 ?

You are right.

Local $Variable

; Func _ImageSearch() : Return Value(s): Success=1 , Failure=0
; --> simulates the possible results of : _ImageSearch(...) Or _ImageSearch(...)
$Variable = (0 Or 0)
ConsoleWrite(' 0 Or 0 : $Variable = ' & $Variable & @CRLF)
$Variable = (1 Or 0)
ConsoleWrite(' 1 Or 0 : $Variable = ' & $Variable & @CRLF)
$Variable = (0 Or 1)
ConsoleWrite(' 0 Or 1 : $Variable = ' & $Variable & @CRLF)
$Variable = (1 Or 1)
ConsoleWrite(' 1 Or 1 : $Variable = ' & $Variable & @CRLF)

; ==> $Variable is either True or False
$Variable = True
ConsoleWrite('! IsArray = ' & IsArray($Variable) & @CRLF)
$Variable = False
ConsoleWrite('! IsArray = ' & IsArray($Variable) & @CRLF)

Summary : If IsArray($Variable) = True will never come true !

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

@Musashi: thanks for the confirmation.

@Polistotele: after googling on the sentence "If IsArray($Variable) = True", I wonder where you found this erroneous syntax in your script because you apply it to _ImageSearch() which will never return an Array. I didn't find your syntax in any post related to _ImageSearch()

$Variable = _ImageSearch(...) Or _ImageSearch(...)
If IsArray($Variable) = True Then ; this will never happen
    ...
Else
    $Variable = _ImageSearch(...) Or _ImageSearch(...)
    If IsArray($Variable) = True Then ; impossible too
        ...
    EndIf
EndIf

When BrewmanNH used this kind of nesting in Dec 2011, he applied it to $Variable = PixelSearch(...) as we can see here and it was correct because PixelSearch(...) returns an Array when successful. This is BrewmanNH's code :

$Variable = PixelSearch(...)
If IsArray($Variable) = True Then ; correct
    ...
Else
    $Variable = PixelSearch(...)
    If IsArray($Variable) = True Then ; correct
        ...
    EndIf
EndIf

Maybe one did copy his script, thinking he could apply it to _ImageSearch() without any other change... wrong try !
To solve this 1st issue, you should do what all other posters did in their scripts, testing only one image per line, then testing if the Return is 1 (success) :

$Variable = _ImageSearch(...)
If $Variable = 1 Then

Here are a few interesting links I found in AutoIt concerning _ImageSearch()

LINK1 : 8 pages of comments, OP is Centrally (thread created in 2013) . The whole pages should be read when you got an issue to see how other posters solved it (or at least tried to) . You would have immediately noticed how Centrally scripted, in his 1st post :

global $y = 0, $x = 0 ; always good to write Global (especially on $x & $y)

Func checkForImage()
Local $search = _ImageSearch(...)
If $search = 1 Then

LINK2 : tbodine88's code shows exactly what Nine asked you to do in his upper post (testing all DllCall possible error values) as it may help solve your #2 issue

LINK3 : JohnOne's about  #include <ImageSearch.au3> vs #include "ImageSearch.au3"

LINK4 : guestscripter's (2015) whole package "ImageSearch2015.zip" which seems to solve a lot of issues.
And for all other posters whining later in the same thread that his additional link "ImageSearch15.au3" wasn't working anymore (a version of ImageSearch Library without the built-in Example and Debugging) ... he pasted that additional script "ImageSearch15.au3" at the very end of his post, the same day he wrote it !

LINK5 : guestscripter's again (2018) showing he didn't modify his precedent download package (good news !) : 10.659 downloads.

LINK6 : BrewmanNH's "That's probably one of the worst reasons for using ImageSearch I've seen yet."
Impossible not to smile (at least) when reading this sentence :D
I guess many posters who created an account to ask for help used the function for game automation, invoking disguised reasons... which will make JLogan3o13 react :

LINK7 : JLogan3o13's "I was curious how long this thread would go after being resurrected before someone ruined it for everyone."

LINK8 : kangkeng's original thread (2008) : 13 pages of comments

You may also google on "Miguel7" "AutoHotKey" "ImageSearch" which links to 10 ImageSearch Tips & Tricks (2014) that could help you.

Good luck with all these various dll's from 2008 / 2010 / 2012, let's hope they can be trusted  without any danger.

Edited by pixelsearch
Link to comment
Share on other sites

  • 1 month later...

In my tests ImageSearch() works fine

#include <ImageSearch.au3>

$x1 = 0
$y1 = 0

If FileExists("image2.bmp") = 0 Then
    MsgBox(0, "Error", "The sample image was not found!", 4)
    Exit
EndIf

AdlibRegister("image", 2000)

While 1
    $res = _ImageSearch("image2.bmp", 1, $x1, $y1, 0)
    If $res = 1 Then
        MouseMove($x1, $y1, 30)
        ExitLoop
    EndIf
    Sleep(200)
WEnd

MsgBox(0, "Sucess", "Image is found!", 4)

Func image()
    ShellExecute(@ScriptDir & "\image.bmp")
EndFunc   ;==>image

Test:  https://mega.nz/#!YFcinSiQ!hovb6nC4WZCaD7muC9bJKid6n4Wi3dc44ywZA5keh8c

Edited by Belini
Link to comment
Share on other sites

Just downloaded the imagesearch stuff and all works for me out of the box. Have that _ImageSearch_Example.au3 first working before you try on your own app

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\xxx\Downloads\AutoIT_ImageSearch_2018\AutoIT_ImageSearch\_ImageSearch_Example.au3" /UserParams    
+>21:54:35 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00020409  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0413)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\xxx\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\xxx\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\xxx\Downloads\AutoIT_ImageSearch_2018\AutoIT_ImageSearch\_ImageSearch_Example.au3
+>21:54:36 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\xxx\Downloads\AutoIT_ImageSearch_2018\AutoIT_ImageSearch\_ImageSearch_Example.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
--\\ ImageSearch //: DEBUG  --  OSArch : X64 // AutoIT ver: 3.3.14.5 X64
-- WorkingDir      : C:\Users\xxx\Downloads\AutoIT_ImageSearch_2018\AutoIT_ImageSearch
-- ScriptFullPath  : C:\Users\xxx\Downloads\AutoIT_ImageSearch_2018\AutoIT_ImageSearch\_ImageSearch_Example.au3
-- ImageSearchDLL  : C:\Users\xxx\AppData\Local\Temp\_ImageSearch_x64.dll (16kb)
-- ScreenCapture   : X1=132 Y1=317 X2=211 Y2=403
-- ScreenCapture   : X1=1449 Y1=944 X2=1576 Y2=1005
+ Dll Return: 1|132|317|80|87
- CP: 172 361
+ Dll Return: 1|132|317|80|87
-   : 132 317
+ Dll Return: 1|132|317|80|87
- CP: 172 361
! Search not found !
+ Dll Return: 1|1449|944|128|62
- CP: 1513 975
+ Dll Return: 1|132|317|80|87
- CP: 172 361
+>21:56:02 AutoIt3.exe ended.rc:0
+>21:56:02 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 87.01

 

And the imagesearch library tells you it returns 0 or 1 

; 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

So you could try

$variable=imagesearch(...)
$variable+=imagesearch(...)
if $variable > 0 then ....

 

Edited by junkew
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...