Sign in to follow this  
Followers 0
Snyper

ImageSearch not working

19 posts in this topic

Hi there, I've had a bunch of trouble with ImageSearch but currently my script isn't doing anything when I run it but exits a few seconds later with an exit code.

This is in the SciTE output.

>Exit code: -1073741819 Time: 8.149

This is my script:

#AutoIt3Wrapper_UseX64=n
#Include

HotKeySet("{NUMPAD2}", "Start")
HotKeySet("{NUMPAD3}", "Stop")

$X = 0
$Y = 0

While 1
Sleep(1)
WEnd

Func Start()
$image_location = @ScriptDir & "\TestA.BMP"
While 1
; $Found = _ImageSearchArea($image_location,1,0,0,@DesktopWidth,@DesktopHeight,$X,$Y,100)
$Found = _ImageSearch($image_location, 1, $X, $Y, 20)

If $Found = 1 Then
MsgBox(0, "Found it!", "The image was found.")
MouseClick("left", $X, $Y, 2, 10)
Else
MsgBox(0, "Not Found", "The image was not found.")
EndIf
WEnd
EndFunc

Func Stop()
exit 0
EndFunc

Any help would be appreciated.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

not enough information provided. What is _ImageSearch? That is not a command in the helpfile.

Also, what is the name of the application you are working with? Does it have controls you can interact with? If so then why not work with the controls?

Edited by scullion

Share this post


Link to post
Share on other sites

not enough information provided. What is _ImageSearch?

Also, what is the name of the application you are working with? Does it have controls you can interact with? If so then why not work with the controls?

ImageSearch is a library for finding things on screen.

I am attempting to find the Mozilla Thunderbird logo icon on my desktop and double click.

Share this post


Link to post
Share on other sites

I know it can be found that way, I am just using it as a test for the capability of the ImageSearch library.

I posted this topic on the forum in the hope that somebody could help me out in getting the library to work.

Share this post


Link to post
Share on other sites

Looks like you are using a DLL posted right?

The OP hasn't been active here for a while and it looks like this uses a DLL.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

No, I am not the author of the library. I am just attempting to use it.

Here is a link:

Share this post


Link to post
Share on other sites

Looks like you are using a DLL posted right?

The OP hasn't been active here for a while and it looks like this uses a DLL.

Correct. I have the DLL and the .au3 files in the correct places. It took a lot of effort to get to this point due to the library + DLL not being compatible with 64 Bit OS.

It appears I will not be able to reply after this message as I seem to be limited to five messages a day...

Share this post


Link to post
Share on other sites

Correct. I have the DLL and the .au3 files in the correct places. It took a lot of effort to get to this point due to the library + DLL not being compatible with 64 Bit OS.

Don't know enough about that library to help.

It appears I will not be able to reply after this message as I seem to be limited to five messages a day...

Fixed.

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thank you for allowing me to post again.

Could I somehow suggest building an ImageSearch type function in to AutoIt itself?

I think many people would appreciate it.

Share this post


Link to post
Share on other sites

This should work tested on Windows 8 64bit.

#include <ImageSearch.au3>
HotKeySet("{F1}", "Imgtest")
HotKeySet("{Esc}", "_End")

Global $x = 0
Global $y = 0

While 1
sleep(100)
Wend


Func Imgtest()
$testimg = "images\test.png"
$img = _ImageSearchArea($testimg, 1, 0, 0, @DesktopHeight, @DesktopWidth, $x, $y, 100)
if $img = 1 Then
MsgBox(0, "Image Found!", "Image has been found", 5)
MouseMove($x, $y)
Else
MsgBox(0,"Error:","Image not found.")
EndIf

EndFunc

Func _end()
Exit
EndFunc

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Thank you for allowing me to post again.

Could I somehow suggest building an ImageSearch type function in to AutoIt itself?

I think many people would appreciate it.

That is really good, I've used it in the past, and does not rely on

any 3rd party files.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

This should work tested on Windows 8 64bit.

Didn't work, log shows the same thing:

>Exit code: -1073741819 Time: 6.626

:-/

Share this post


Link to post
Share on other sites

Didn't work, log shows the same thing:

>Exit code: -1073741819 Time: 6.626

:-/

Code works i tested it on my system, if its not working then your doing something wrong have you got these files in the right places?

I can always make a Youtube video to show it works but it be Windows 8 64bit though im sure it works on 64bit 7 too.

Imagesearch.au3 needs to be in C:Program Files (x86)AutoIt3Include

ImageSearchDLL needs to be in C:WindowsSystem32

#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 file location or HBitmap to locate on the
; desktop or in the Specified HBitmap
;                   $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
;
; $HBMP - optional hbitmap to search in. sending 0 will search the desktop.
;
; 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 IsString($findImage) Then
if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
If $HBMP = 0 Then
$result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
Else
$result = DllCall("ImageSearchDLL.dll","str","ImageSearchEx","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
EndIf
Else
$result = DllCall("ImageSearchDLL.dll","str","ImageSearchExt","int",$x1,"int",$y1,"int",$right,"int",$bottom, "int",$tolerance, "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

Share this post


Link to post
Share on other sites

The two files are in the correct place. I replaced the ImageSearch.au3 file with the code you just provided.

Now, when I run the script you gave me or the one I wrote in the first place, I receive this error again:

http://puu.sh/1ta9h

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

The script was not wrote by me and i only make basic functions while im learning. Its working on my end and i have had no issues other than now and again it can not find the image result i crop a new image/make a loop function though i need to work on a better way.

You can see here:

http://youtu.be/_pFOMG2NaZM

Will need 720p to view the video i used a a basic video recorder

I believe this is where the project started but im not sure:

Edited by Gotemp

Share this post


Link to post
Share on other sites

Odd, i started to get the same issue as the OP last night for no reason, infact it was that strange that while my old script was working the new one would just give the error message which is posted below, to make sure i did not type anything wrong i deleted everything i had wrote and copied and pasted a section of my old script which was an image test function and nope still an error!

Anyway i searched for a fix and found an imagesearch64.au3 and a 64.dll but all they did was jump to my message box saying "Error" so i did some more digging and read that i should try placing my imagesearch.dll into SysWOW64 when its normally System32 i copied it over and... The script worked. I dont know if this is an Autoit error or soemthing to do with the au3 file or what but thought i would share. Maybe the OP is subscribed to this thread i'll message just incase anyhow but its something they can try.

if $result[0]="0" then return 0
if $result^ ERROR

Share this post


Link to post
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
Sign in to follow this  
Followers 0