Jump to content

Picture recognition


Recommended Posts

I need a (few) line(s) of code to recognize and search for a picture (possibly in same folder as script) and click on specified picture.

Thanks in advance

~Vivvic~

[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Link to comment
Share on other sites

Ok thanks alot guys, Ill look into that.

EDIT: JoshDB, thanks analizer.dll was exactly what I needed.

EDIT: Sorry, I thought that was what I needed, but I am having troubles getting it to work, Here is my script so far and I am including picture I want it to search for and click on below.

--------------------------------

----PICTURE-----------------

----------------

--------------------------------

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Created by Vivvic;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#include <GUIConstants.au3>

GUICreate("Gaia Online Poster - By Vivvic", 300, 80)

$Label = GUICtrlCreateLabel("Start, Gaia Online Poster?", 10, 10)
$YesID  = GUICtrlCreateButton("Yes", 160, 50, 50, 20)
$NoID   = GUICtrlCreateButton("No", 230, 50, 50, 20)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;I have another script that changes this;;;
$Variable = 1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GUISetState(); display the GUI

Do
    $msg = GUIGetMsg()
   
    Select
        Case $msg= $YesID
            MsgBox(0, "Instructions", ">Open forum you want to *bump*." & @CRLF & ">>Scroll down to the bottom." & @CRLF & ">>>Follow instructions on next dialog box.")
            $Title_Bar = InputBox("Imput Data", "Type EXACTLY what appears in the fourms title bar, the part at the top of the screen.                                                                                                                                             EXAMPLE:                                                        Forum - Mozilla Firefox", "Gaia Online")
            While $Variable <= 1
                WinActivate("$Title_Bar", "")
                MouseClick("left", 1184, 356, 1, 0)
                Sleep(150)
                MouseWheel("down", 90)
                Sleep(1500)     
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;THIS IS WHERE I NEED IT TO FIND AND CLICK PICTURE;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                Sleep(7000)
                WinActivate("Gaia Online", "")
                Sleep(1000)
                MouseClick("left", 1184, 356, 1, 0)
                Sleep(1000)
                MouseWheel("down", 10)
                Sleep(1500)
                MouseClick("left", 456, 174, 1, 0)
                Sleep(1000)
                Send( "{*}bump{*}" )
                Sleep(1000)
                MouseClick("left", 605, 398, 1, 0)
                Sleep(10000)
                MouseClick("left", 442, 427, 1, 0)
                Sleep(45000)
            WEnd
            
        Case $msg= $NoID
            MsgBox(0,"Ok, Exiting.", "Ok, Exiting.")
        Case $msg= $GUI_EVENT_CLOSE
        
    EndSelect
Until $msg = $GUI_EVENT_CLOSE or $msg = $NoID

Thanks in advance.

~Vivvic~

Edited by Vivvic

[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Link to comment
Share on other sites

Still no luck, if anyone can do somthing I cant please speak up and let me know how to make it work, thanks for the help.

~Vivvic~

[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Link to comment
Share on other sites

  • Moderators

I don't even see where you tried to use it :D

But if your trying to automate something online, why not just use the IE.au3? Not everyone uses FireFox (don't know why but it's true :D )

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I don't even see where you tried to use it :D

But if your trying to automate something online, why not just use the IE.au3? Not everyone uses FireFox (don't know why but it's true :D )

Because I use Firefox, and I have converted all of my friends (who I will be shareing this with) as well, so was looking for a solution (P.S. I would just get screen POS but it changes with each post).

EDIT: I used it where I have the big comment block, but didnt work (all I really did was copy/paste and change the picture file to use mine) so I took it out (so it would look cleaner) and posted it seeing if one of you could help me out.

Edited by Vivvic

[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Link to comment
Share on other sites

Ok, here is my attempt with the analyzer dll.

(The code blocked off by comments wasnt written by me)

>(Has errors with the added code not sure on fixing it)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;     Created by Vivvic     ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#include <GUIConstants.au3>

GUICreate("Gaia Online Poster - By Vivvic", 300, 80)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
global $AZDLLName = "analizer.dll";;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Label = GUICtrlCreateLabel("Start, Gaia Online Poster?", 10, 10)
$YesID  = GUICtrlCreateButton("Yes", 160, 50, 50, 20)
$NoID   = GUICtrlCreateButton("No", 230, 50, 50, 20)
$Variable = 1                       
GUISetState()  ; display the GUI

Do
    $msg = GUIGetMsg()
   
    Select
        Case $msg= $YesID
            MsgBox(0, "Instructions", ">Open forum you want to *bump*." & @CRLF & ">>Scroll down to the bottom." & @CRLF & ">>>Follow instructions on next dialog box.")
            $Title_Bar = InputBox("Imput Data", "Type what appears in the fourms title bar, the part at the top of the screen.                                                                                                                                               EXAMPLE:                                                           Forum - Mozilla Firefox", "Gaia Online")
            While $Variable <= 10
                WinActivate("$Title_Bar", "")
                MouseClick("left", 1184, 356, 1, 0)
                Sleep(150)
                MouseWheel("down", 90)
                ; ~TAKEN OUT~ Sleep(500)
                ; ~TAKEN OUT~ Send( "{PGDN}" )
                ; ~TAKEN OUT~ Sleep(500)
                ; ~TAKEN OUT~ Send( "{PGDN}" )
                ; ~TAKEN OUT~ Sleep(500)
                ; ~TAKEN OUT~ Send( "{PGDN}" )
                Sleep(1500)
                        
                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                AZPrintWindow()
                $var = _findImageOnScreen("forum_postreply.gif", "0,0,0,0", 0)
                
                If $var <> 0 Then
                    For $r = 1 to UBound($var)-1
                        MouseMove($var[$r][1] , $var[$r][2], 20 )
                        Sleep(200)
                    Next
                EndIf
                
                ;Find image on screen and return cords
                ;findFile: File you want to find on the screen
                ;rect: x,y,width,height
                ;first: 1 = find first 0 = find all
                Func _findImageOnScreen($findFile, $rect, $first)
                    Dim $mouseCords[1][3]
                    
                    $rects = ""
                    $trans = 0
                    $color = ""
                
                    $result = DllCall($AZDLLName, "int", "image_in_clipscreen_rects", "str", $findFile, "int", $first, "int", $trans, "str", $color, "str", $rect, "str", $rects)
                
                    AZDllError("AZTextRects")
                    $rects = $result[6]
                ;MsgBox(0,"",$rects)
                
                    if $rects <> "" then
                        $rects = stringright($rects, stringlen($rects) - 1)
                        $rects = stringsplit($rects, ";")
                        $mouseIndex = $rects[0]
                        ReDim $mouseCords[$mouseIndex+1][3]
                    else
                        $rects = _arraycreate(0)
                    endif
                
                    if $rects[0] < 1 then
                        return 0
                    endif
                    
                    
                        if ($rects[0] <> 0) then
                        For $n = 1 to $mouseIndex
                    ;MsgBox(0,$n,$rects[$n])
                            $items = stringsplit($rects[$n], ",")
                            if $items[0] = 4 then
                                $mouseCords[$n][1] = $items[1] + $items[3] / 2
                                $mouseCords[$n][2] = $items[2] + $items[4] / 2
                            
                                $pWidth  = $items[3]
                                $pHeight = $items[4]
                            ElseIf $items[0] = 3 then
                                $mouseCords[$n][1] = $items[1] + $pWidth / 2
                                $mouseCords[$n][2] = $items[2] + $pHeight / 2
                            Else
                                AZTraceError("Index of the needed text rect out of bounds.")
                                AZPrintWindowExit()
                            Endif
                            
                        ;MsgBox(0,$mouseCords[$n][1],$mouseCords[$n][2])
                            
                
                        Next
                    else
                        $items = _arraycreate(0)
                    endif
                
                    return $mouseCords
                EndFunc
                
                
                ; Print window to clipboard (don't ALT PRINTSCREEN)
                func AZPrintWindow()
                    $result = DllCall($AZDLLName, "none", "active_window_to_clip")
                    AZDllError("AZPrintWindow")
                endfunc
                
                ;Error
                func AZDllError($func)
                    if @error <> 0 then AZTraceError("'" & $func & "' function run error")
                endfunc
                
                ; Tracing error
                func AZTraceError($error)
                    MsgBox(16, "Analizer error.", $error)
                endfunc
                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                
                Sleep(7000)
                WinActivate("Gaia Online", "")
                Sleep(1000)
                MouseClick("left", 1184, 356, 1, 0)
                Sleep(1000)
                MouseWheel("down", 10)
                Sleep(1500)
                MouseClick("left", 456, 174, 1, 0)
                Sleep(1000)
                Send( "{*}bump{*}" )
                Sleep(1000)
                MouseClick("left", 605, 398, 1, 0)
                Sleep(10000)
                MouseClick("left", 442, 427, 1, 0)
                Sleep(45000)
            WEnd
            
        Case $msg= $NoID
            MsgBox(0,"Ok, Exiting.", "Ok, Exiting.")
        Case $msg= $GUI_EVENT_CLOSE
        
    EndSelect
Until $msg = $GUI_EVENT_CLOSE or $msg = $NoID

[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Link to comment
Share on other sites

You need to include one of the .au3 files that came with the package, that have the functions in it. It doesn't appear that you have.

EDIT:

Take the functions out of the main While loop :D

Edited by JoshDB
Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite
Link to comment
Share on other sites

Hmm, Im sorry but I am new to auto it and was just able to try and fix my script and am confused as to what to take out, I am not good at all with functions.

[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

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