Jump to content

Image Search help


Stuvven
 Share

Recommended Posts

I was trying to get image searching to work and I have ImageSearch.au3 in the folder that my script is in, and I put a picture that I snipped, I put it on my desktop. For some reason when I run the script, instead of looking for the image on my destop, it opens up notepad for some reason. This is the simple script I wrote. 

 

#include <ImageSearch.au3>
WindowActivate ("desktop")
$x=0
$y=0

Func Start()
   $Search = _ImageSearch("Raccoon.JPG", 0, $x, $y, 0)
   If $Search = 1 Then
      MouseMove($x, $y, 10)
   EndIf
EndFunc

while 1
   sleep (500)
WEnd
 

Link to comment
Share on other sites

This is what my log says when the script is ran

 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\steph\Desktop\Scripts\AutoIt\Source\Image Search\image.au3"    
+>@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 >Exit code: 0    Time: 1.405

Link to comment
Share on other sites

Is that the Whole code? There must be some code somewhere, that opens and takes a screenshot as mentioned in the log.

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

That's everything. I was sent a different imageSearch.au3 file from a friend and it no longer brings up the notepad. I took a look inside the ImageSearch.au3 that I was originally using and it had the notepad part in it which was weird. So now that I'm using the other Imagesearch that I was sent, I run my script and literally nothing happens lol. I'll attach the ImageSearch.au3 that I'm currently using. If possible, could you send over the ImageSearch.au3 that you're using? I run my script and this is all it says in the log: >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\steph\Desktop\Scripts\AutoIt\Source\Image Search\image.au3".

 

Nothing happens once it's ran. Same code as what I previously posted.

ImageSearch.au3

Link to comment
Share on other sites

Sorry for the double post but I'm not sure how to edit my other replies. I added #includeadmin on the top of the script and once it's ran, it now comes up in the log with: >Exit code: 0    Time: 0.1926. 

 

But it's not even searching for the image it seems like. I run the script and that pops up instantly without the mouse moving at all.

Link to comment
Share on other sites

I actually helped someone get there image search working some time ago.. I'll post the forum below. Post 2 has a zip file with a tester script, along with the dll, and post 4 has the Imagesearch.au3 that needs to be placed in this directory C:\Program Files (x86)\AutoIt3\Include.

 

 

 

Link to comment
Share on other sites

1. Download ImageSearch LIB from here:  

2. Use this code

#include "_ImageSearch.au3"
#include "_ImageSearch_Debug.au3"

HotKeySet("{Esc}", "_Exit") ; Press ESC for exit
Func _Exit()
    Exit 0
EndFunc   ;==>_Exit

Global $_Image_1 = @ScriptDir & "\example.bmp"

; First, use this function to create a file bmp, maybe a desktop icon for example')
;~ _ImageSearch_Create_BMP($_Image_1)

ConsoleWrite("! Search on Image: "& $_Image_1 &  @CRLF& '! Searching..' & @CRLF)

While 1
    Local $return = _ImageSearch($_Image_1)
    If $return[0] = 1 Then
        ConsoleWrite('! Image found:' & " X=" & $return[1] & " Y=" & $return[2] & @CRLF)
        MsgBox(0, 'Success', 'Image found:' & " X=" & $return[1] & " Y=" & $return[2] )
        MouseMove($return[1], $return[2],1)
    EndIf
    Sleep(200)
WEnd

Goodlucky

Regards,
 

Link to comment
Share on other sites

5 hours ago, aa2zz6 said:

I actually helped someone get there image search working some time ago.. I'll post the forum below. Post 2 has a zip file with a tester script, along with the dll, and post 4 has the Imagesearch.au3 that needs to be placed in this directory C:\Program Files (x86)\AutoIt3\Include.

 

 

 

I did what you said and put the Imagesearch.au3 inside my include folder, and followed the video. The ImageSearch didn't ask me if I had the DLL files and if I wanted to install them, so I went ahead and added them in to my System32 folder. Didn't work at all. I have the .JPG in my folder with the script, I have Imagesearch.au3 in my include folder, I have the same .JPG on my desktop for testing the script, I also have the .DLL files in the same folder as my script. 

Link to comment
Share on other sites

2 hours ago, VIP said:

1. Download ImageSearch LIB from here:  

2. Use this code

#include "_ImageSearch.au3"
#include "_ImageSearch_Debug.au3"

HotKeySet("{Esc}", "_Exit") ; Press ESC for exit
Func _Exit()
    Exit 0
EndFunc   ;==>_Exit

Global $_Image_1 = @ScriptDir & "\example.bmp"

; First, use this function to create a file bmp, maybe a desktop icon for example')
;~ _ImageSearch_Create_BMP($_Image_1)

ConsoleWrite("! Search on Image: "& $_Image_1 &  @CRLF& '! Searching..' & @CRLF)

While 1
    Local $return = _ImageSearch($_Image_1)
    If $return[0] = 1 Then
        ConsoleWrite('! Image found:' & " X=" & $return[1] & " Y=" & $return[2] & @CRLF)
        MsgBox(0, 'Success', 'Image found:' & " X=" & $return[1] & " Y=" & $return[2] )
        MouseMove($return[1], $return[2],1)
    EndIf
    Sleep(200)
WEnd

Goodlucky

I used that script, put the files that you shared, inside my script folder. This is what I have for my script: 

#include "_ImageSearch.au3"
#include "_ImageSearch_Debug.au3"

HotKeySet("{Esc}", "_Exit") ; Press ESC for exit
Func _Exit()
    Exit 0
EndFunc   ;==>_Exit

Global $_Image_1 = @ScriptDir & "\Raccoon.JPG"

; First, use this function to create a file bmp, maybe a desktop icon for example')
;~ _ImageSearch_Create_BMP($_Image_1)

ConsoleWrite("! Search on Image: "& $_Image_1 &  @CRLF& '! Searching..' & @CRLF)

While 1
    Local $return = _ImageSearch($_Image_1)
    If $return[0] = 1 Then
        ConsoleWrite('! Image found:' & " X=" & $return[1] & " Y=" & $return[2] & @CRLF)
        MsgBox(0, 'Success', 'Image found:' & " X=" & $return[1] & " Y=" & $return[2] )
        MouseMove($return[1], $return[2],1)
    EndIf
    Sleep(200)
WEnd

 

And this is what the log says when it is ran: 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\steph\Desktop\Scripts\AutoIt\Image Search\image.au3"    
--\\ ImageSearch //: DEBUG  --  OSArch : X64 // AutoIT ver: 3.3.14.5 x86
-- WorkingDir      : C:\Users\steph\Desktop\Scripts\AutoIt\Image Search
-- ScriptFullPath  : C:\Users\steph\Desktop\Scripts\AutoIt\Image Search\image.au3
-- ImageSearchDLL  : C:\Users\steph\Desktop\Scripts\AutoIt\Image Search\_ImageSearch.dll (14.5kb)
! Search on Image: C:\Users\steph\Desktop\Scripts\AutoIt\Image Search\Raccoon.JPG
! Searching..
! Search not found !
! Search not found !
! Search not found !

 

Link to comment
Share on other sites

19 minutes ago, Stuvven said:

I have the same .JPG on my desktop for testing the script

What exactly do you mean by this? Is the jpg open in a viewer, or are you just putting the file on your desktop?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The script needs to "see" the image.

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

4 hours ago, Stuvven said:

Just put the file on my desktop. 

 

Facepalm_statue.jpg

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

8 hours ago, careca said:

The script needs to "see" the image.

Wouldn't the script be able to see the image that's on my desktop? I can sure see the picture of what the jpg contains. I'll include a pic of what it shows on my desktop. After reading your replies, I tried opening the jpg and then running the image search and still nothing. Says runtime is like .19 secs

Desktop.PNG

Link to comment
Share on other sites

7 hours ago, Stuvven said:

...tried opening the jpg and then running the image search and still nothing. Says runtime is like .19 secs

I suspect there is a error happening somewhere, because the way the code is, it's not supposed to exit, and it seems to be exiting very fast.

Can you try this one? with the included image? It works here so i figure it must work there, also no include, uses the dll call directly.

ImageSearch DLL Call - No Include.rar

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

4 hours ago, careca said:

I suspect there is a error happening somewhere, because the way the code is, it's not supposed to exit, and it seems to be exiting very fast.

Can you try this one? with the included image? It works here so i figure it must work there, also no include, uses the dll call directly.

ImageSearch DLL Call - No Include.rar

Put all 3 files inside a folder, opened the image and then ran the .au3 you sent and this is what the log says when ran: 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\steph\Desktop\Scripts\AutoIt\Image Search\test\Example.au3"    
"C:\Users\steph\Desktop\Scripts\AutoIt\Image Search\test\Example.au3" (8) : ==> Subscript used on non-accessible variable.:
If $result[0]<>0 Then
If $result^ ERROR
>Exit code: 1    Time: 0.05777

 

Link to comment
Share on other sites

There is a problem, not with the script, it's something else, the same thing that is interfering with your previous script, maybe permissions or something else.

You see, $result[0] is the result of the dll call, so you could put an error check right after the call to see if  you can get an error from it.

Did you try requireadmin? i know it's a long shot, but sometimes seemingly unrelated things do make it work.

DLLCall: @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.
Edited by careca
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

8 hours ago, careca said:

There is a problem, not with the script, it's something else, the same thing that is interfering with your previous script, maybe permissions or something else.

You see, $result[0] is the result of the dll call, so you could put an error check right after the call to see if  you can get an error from it.

Did you try requireadmin? i know it's a long shot, but sometimes seemingly unrelated things do make it work.

DLLCall: @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.

I added a requireadmin at the top of the script and when that was added, it didn't pull up anything besides  >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\steph\Desktop\Scripts\AutoIt\Image Search\test\Example.au3"    
>Exit code: 0    Time: 0.1915

 

I'm new to Autoit and don't have much experience with programming in general, so I'm not sure how to do an error check, so this probably looks stupid but I added the DLLCall:@error in there and it didn't change anything. And so I tried doing it myself, and it probably is completely off of what you wanted and prob wouldn't logically work either but I figured I'd try it anyways. Pretty embarassing to post this lol so don't make fun of me for it prob not even making any sense!: 

 

#requireadmin
#include <MsgBoxConstants.au3>
Local $HBMP = 0
Local $x1 = 0, $y1 = 0
Local $right = @DesktopWidth
Local $bottom = @DesktopHeight
Local $findImage = @ScriptDir&'\Capture.PNG'
While 1
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
    If $result[0]<>0 Then
       DLLCall: @error
        $array = StringSplit($result[0],"|")
        ConsoleWrite('XPos - '& $array[2] &' - YPos - '& $array[3] &' - XSize - '&$array[4]&' - YSize - '&$array[5]&@CRLF)
     EndIf
     if $result = 1 Then
        MsgBox($MB_OK, 1 , "unable to use the DLL file")
        sleep (5000)
     EndIf
     if $result = 2 Then
        MsgBox($MB_OK, 2 , "unknown return type")
        sleep (5000)
     EndIf
     if $result = 3 Then
        MsgBox($MB_OK, 3, "function not found in the DLL file"
        sleep (5000)
     EndIf
     if $result = 4 Then
        MsgBox($MB_OK, 4, "bad number of parameters"
        sleep (5000)
     EndIf
    Sleep(100),
WEnd

Link to comment
Share on other sites

Hi, can you try it like this?

;#requireadmin ;Disables the console output, if the code still doesn't work, comment it.
#include <MsgBoxConstants.au3>
Local $HBMP = 0
Local $x1 = 0, $y1 = 0
Local $right = @DesktopWidth
Local $bottom = @DesktopHeight
Local $findImage = @ScriptDir & '\Capture.PNG'
While 1
    $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage, "ptr", $HBMP)
    If @error Then
        ConsoleWrite('There was an error: ' & @error & @CRLF)
    Else
        If IsArray($result) = 1 Then
            If $result[0] <> 0 Then
                $array = StringSplit($result[0], "|")
                ConsoleWrite('XPos - ' & $array[2] & ' - YPos - ' & $array[3] & ' - XSize - ' & $array[4] & ' - YSize - ' & $array[5] & @CRLF)
            Else
                ConsoleWrite('Not found' & @CRLF)
            EndIf
        EndIf
    EndIf
    Sleep(100)
WEnd

ps: "DLLCall: @error" this was just a hint for you to get the error number, not an actual line of code, my bad, i wasn't clear on that.

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

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...