Jump to content

Trying to make the mouse follow a black line/circle


fixitrod
 Share

Recommended Posts

  • Moderators

BetaLeaf & mikell,

Thanks for the kind words - much appreciated.

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

Melba 23, I have several images I use and they aren't to scale. I stretch them onto google earth and line them up when needed. That would make it almost impossible to "pre-record" the mouse movement and line it up after but I REALLY appreciate what you've done and how you are thinking! This is great. Any other ideas or if I'm thinking of your idea incorrectly let me know. I'm good at that. Or, do you know what the mouse works differently in Google Earth?

Link to comment
Share on other sites

I've had PM's asking for more detail of exactly what I'm actually trying to do. Maybe this info will help with you autoit experts creating a solution.

Here's the manual process I'm trying to replace as much as I can. 

I take an image of a lake contour map and put it on top of the lake in google earth. I set it on the map and stretch or shrink it to make the shorelines match up. I turn on the path tool and create a path over each contour line by tracing each contour line and clicking along the way or holding the mouse. One contour like may be the ten foot depth line. Another path might be the twenty foot depth line etc. I'll save a separate path for each depth to use in my lake modeling software. I'm trying to replace manually tracing the line so it will be more accurate than me doing it with the mouse and hopefully faster.

Link to comment
Share on other sites

On 2/24/2016 at 1:24 PM, Melba23 said:

 

If you do not have some form of pointer as a mouse cursor (you say you have a "hand") I wonder if the point from which you are trying to start is not sufficiently close (1 pixel) to the line for the code to detect it?

M23

I edited the code to follow any color you click on. It would just follow the wrong thing if I "miss" the line. 

Link to comment
Share on other sites

8 hours ago, mikell said:

Melba,
I played a little with your code - pretty nice even if I'm a bit lost on the purpose of your $aSearch array  :)


fixitrod,
For shade variation you could use

PixelSearch($iX, $iY, $iX, $iY, $color, 10)
If not @error Then ...

; instead of

If PixelGetColor($iX, $iY) = $color Then ...

and change the HotKeySet("{SPACE}",...) to use the spacebar to pause and resume the script
My 2 cents :

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

HotKeySet("{SPACE}", "_Follow")
HotKeySet("{ESC}", "_Exit")

$hGUI = GUICreate("Test", 500, 500)
$cGraphic = GUICtrlCreateGraphic(0, 0, 500, 500)
GUICtrlSetGraphic($cGraphic, $GUI_GR_ELLIPSE, 50, 50, 400, 400)
GUICtrlSetGraphic($cGraphic, $GUI_GR_RECT, 150, 150, 200, 200)
GUICtrlSetGraphic($cGraphic, $GUI_GR_PIE, 200, 300, 100, 30, 70)
GUISetState()

Global $pause

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd



Func _Follow()
    Local $color = 0x000000

    ; Array holding next position to check for each direction [delta-X, Delta-Y]
    Local $aDir[8][2] = [[0, -1], _
                          [1, -1], _
                          [1, 0], _
                          [1, 1], _
                          [0, 1], _
                          [-1, 1], _
                          [-1, 0], _
                          [-1, -1]]

    ; Array to hold search directions relative to current direction
    Local $aSearch[] = [0, 1, -1, 2, -2, 3, -3]

;=====================================
; determine start point

    ; See if on line
    $aStartPos = MouseGetPos()
    $iStart_X = $aStartPos[0]
    $iStart_Y = $aStartPos[1]
    PixelSearch($iStart_X, $iStart_Y, $iStart_X, $iStart_Y, $color, 10, 1)
    If not @error Then
  ;  If PixelGetColor($iStart_X, $iStart_Y) = $color Then
        ; Set start position
        $iCurr_X = $iStart_X
        $iCurr_Y = $iStart_Y
    Else
        ConsoleWrite("Searching for line" & @CRLF)
        ; Search for initial point in immediately surrounding pixels
        For $iFindDir = 0 To UBound($aSearch) - 1
            $iFind_X = $iStart_X + $aDir[$iFindDir][0]
            $iFind_Y = $iStart_Y + $aDir[$iFindDir][1]
            PixelSearch($iFind_X, $iFind_Y, $iFind_X, $iFind_Y, $color, 10, 1)
            If not @error Then
          ;  If PixelGetColor($iFind_X, $iFind_Y) = $color Then
                ExitLoop
            EndIf
        Next
        ; Check if found
        If $iFindDir > UBound($aSearch) - 1 Then
            ConsoleWrite("Cannot find line!" & @CRLF & @CRLF)
            Return
        EndIf
        ; Set start position
        $iCurr_X = $iFind_X
        $iCurr_Y = $iFind_Y
        $iStart_X = $iFind_X
        $iStart_Y = $iFind_Y
    EndIf

    ConsoleWrite("Ready to go!" & @CRLF)
;======================================
; determine direction 

    ; Check for possible directions
    $iCurrDir = -1
    For $iDirCheck = 0 To 7
        ; Search around for another pixel
        $iFirstMove_X = $iCurr_X + $aDir[$iDirCheck][0]
        $iFirstMove_Y = $iCurr_Y + $aDir[$iDirCheck][1]
        PixelSearch($iFirstMove_X, $iFirstMove_Y, $iFirstMove_X, $iFirstMove_Y, $color, 10, 1)
        If not @error Then
   ;     If PixelGetColor($iFirstMove_X, $iFirstMove_Y) = 0x000000 Then
            ; Set direction
            $iCurrDir = $iDirCheck
            ExitLoop
        EndIf
    Next
    ; Check direction is set
    If $iCurrDir = -1 Then
        ConsoleWrite("Cannot follow!" & @CRLF & @CRLF)
        Return
    EndIf

;===================================

HotKeySet("{SPACE}", "_Pause")

   While 1

        ; Check likely directions for pixel
        For $iDirChange = 0 To UBound($aSearch) - 1

            ; Determine direction to check
            $iCheckDir = $iCurrDir + $aSearch[$iDirChange]

            If $iCheckDir < 0 Then
                $iCheckDir = $iCheckDir + 8
            ElseIf $iCheckDir > 7 Then
                $iCheckDir = $iCheckDir - 8
            EndIf

            ; Prevent backtracking
            If Abs($iCurrDir - $iCheckDir) = 4 Then ContinueLoop

            ; Look for pixel in that direction
            $iCheck_X = $iCurr_X + $aDir[$iCheckDir][0]
            $iCheck_Y = $iCurr_Y + $aDir[$iCheckDir][1]
       ;;     If PixelGetColor($iCheck_X, $iCheck_Y) = 0x000000 Then
            PixelSearch($iCheck_X, $iCheck_Y, $iCheck_X, $iCheck_Y, $color, 10, 2)
            If not @error Then
                ; Move to this pixel
                ExitLoop
            EndIf

        Next

        If $iDirChange > UBound($aSearch) - 1 Then
            ConsoleWrite("Lost it!" & @CRLF & @CRLF)
        Else
            ; Check if back to start
            If $iCheck_X = $iStart_X And $iCheck_Y = $iStart_Y Then
                ConsoleWrite("Back to the beginning!" & @CRLF & @CRLF)
                ExitLoop
            Else
                ; Set new coords
                $iCurr_X = $iCheck_X
                $iCurr_Y = $iCheck_Y
                ; Set new direction
                $iCurrDir = $iCheckDir

                ; Move mouse
                MouseMove($iCurr_X, $iCurr_Y)

              While $pause
                  Sleep(10)
              WEnd

             ;   Sleep(10)
            EndIf
        EndIf
    WEnd

HotKeySet("{SPACE}", "_Follow")
EndFunc


;=============================================
Func _Pause()
    $pause = not $pause
EndFunc

Func _Exit()
    Exit
EndFunc


 

Thank you for these ideas and snippets. I will add them to the code. They are perfect additions to this code especially if I can get it to work in google earth. I want to note these weren't original request. I thought of them after the fact. Melba23 nailed everything I was trying to do in the beginning like it was nothing. And you have the solution for me wanting to add to it. This is awesome. Thanks Mikell

I have show this Autoit to several people at work in the last few days since I'm new to it. I'm a CCNP network administrator and Microsoft Domain administrator. My coding is at level "dangerous" so I truly appreciate everyone's help and time. This is for a project I'm trying to do for the local lakes and community. 

Thank you again!!!!

Link to comment
Share on other sites

  • Moderators

fixitrod,

Given your explanation of the process you undertake I am not entirely convinced that my "pre-record" idea is as unworkable as you suggest.

We can fairly easily place a semi-transparent GUI including the sonar image over a Google Earth window and adjust it for size and position. Once we have that new size and location, we can then make it fully opaque and do the "recording" - once that is done, we remove the sonar image and "playback" the mouse moves into the now visible Google Earth. 

So would you mind posting one of the sonar image files and giving its actual location so that I can see what I can produce. I really do not mind spending a bit of time on this even if it does not work in the end as it is one of those nice problems that we get here from time to time which require a bit of lateral thinking to solve and which I really enjoy.

M23

Edit: I have a "proof of concept" script working based on the Google earth/ sonar composite image you posted earlier - but it would be much better to have a real image to use.

Edit 2: The script is now nearly operational - except that the sonar image I copied does not have very well-defined contour lines (I hope because of the compressed image format used to load it to the forum) and so line tracking is not working properly. Thus the plea for a "real" sonar image file to refine the code.

Edit 3: Now have the tracking sorted - even on the poor quality image I was using. Next problem is the green reticule markings which cross the contour lines - I think I have a idea for a solution but it still needs testing.

Edited by Melba23

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

Melba23, You are awesome. I'm loading a couple example so you can see the variety. I really appreciate this!!!!!!

The rectangle shaped one is hurshtown resevoir in Grabil Indiana. Just type in Hurshtown Reservoir in google Earth.

In the toolbar at the top I add the image by clicking add, image overlay. I then turn down the opacity and align the image over the real body of water. I then turn up the opacity, click the path tool and make a path of each depth.. I make a shoreline path first then each one individually after that. I save them something like Hursthown10ftnumber1.kml, Hurshtown20ftnumber.kml1, Hurshtown10ftnumber2.kml, etc. I can take these paths and import them into my lake software and rebuild the image in 3d after putting them all together. 

First Hurshtown Reservoir, ... Hurshtown Reservoir, Grabill, IN

Second is Little Barbee...Little Barbee Lake, Tippecanoe Township, IN

Third West Otter... west otter lake, angola in

I ran into a problem uploading 3 files on this post. I'll try to put the other two on the next post. 

Thank you so much for digging into this!!! If you need any network or Active Directory support let me know :) 

 

Hurshtown.png

Link to comment
Share on other sites

I think I know why it won't work when the path tool is on it Google Earth. A dark blue square appears right at the cursor while the mouse is pressed down. I tried to use mouseclick but it only clicks once. I added color variation ability no and that help follow the line a lot!!! But, If i can make it click instead of staying down and keep following the original color I think it would be ok. When the mouse isn't pressed the blue square isn't there. Or if there is a way to add that color blue as a second color it can follow... not sure how that would work. I've attached an example of the blue box. The mouse disappeared when I did the print screen but normally the mouse is pointing right on the blue box. 

Here's the code so far. I have commented some of the old code, Pause doesn't work and It's not formatted clean yet but here it is. 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

HotKeySet("{SPACE}", "_Follow")
HotKeySet("{ESC}", "_Exit")


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Follow()

    ; Array holding next position to check for each direction [delta-X, Delta-Y]
    Local $aDirn[8][2] = [[0, -1], _
                          [1, -1], _
                          [1, 0], _
                          [1, 1], _
                          [0, 1], _
                          [-1, 1], _
                          [-1, 0], _
                          [-1, -1]]

    ; Array to hold search directions relative to current direction
    Local $aSearch[] = [0, 1, -1, 2, -2, 3, -3]

    ; See if on line
    $aStartPos = MouseGetPos()
    $iStart_X = $aStartPos[0]
    $iStart_Y = $aStartPos[1]
    $color=PixelGetColor($iStart_X, $iStart_Y)
    PixelSearch($iStart_X, $iStart_Y, $iStart_X, $iStart_Y , $color,95 )
    If not @error Then
        ; Set start position
        $iCurr_X = $iStart_X
        $iCurr_Y = $iStart_Y
    Else
        ConsoleWrite("Searching for line" & @CRLF)
        ; Search for initial point in immediately surrounding pixels
        For $iFindDirn = 0 To UBound($aSearch) - 1
            $iFind_X = $iStart_X + $aDirn[$iFindDirn][0]
            $iFind_Y = $iStart_Y + $aDirn[$iFindDirn][1]
            ;If PixelGetColor($iFind_X, $iFind_Y) = 0x000000
    PixelSearch($iFind_X, $iFind_Y, $iFind_X, $iFind_Y , $color,95)
    If not @error Then
                ExitLoop
            EndIf
        Next
        ; Check if found
        If $iFindDirn > UBound($aSearch) - 1 Then
            ConsoleWrite("Cannot find line!" & @CRLF & @CRLF)
            Return
        EndIf
        ; Set start position
        $iCurr_X = $iFind_X
        $iCurr_Y = $iFind_Y
        $iStart_X = $iFind_X
        $iStart_Y = $iFind_Y
    EndIf

    ConsoleWrite("Ready to go!" & @CRLF)

    ; Check for possible directions
    $iCurrDirn = -1
    For $iDirnCheck = 0 To 7
        ; Search around for another pixel
        $iFirstMove_X = $iCurr_X + $aDirn[$iDirnCheck][0]
        $iFirstMove_Y = $iCurr_Y + $aDirn[$iDirnCheck][1]
        ;If PixelGetColor($iFirstMove_X, $iFirstMove_Y) = 0x000000
    PixelSearch($iFirstMove_X, $iFirstMove_Y, $iFirstMove_X, $iFirstMove_Y , $color,95)
    If not @error Then
            ; Set direction
            $iCurrDirn = $iDirnCheck
            ExitLoop
        EndIf
    Next
    ; Check direction is set
    If $iCurrDirn = -1 Then
        ConsoleWrite("Cannot follow!" & @CRLF & @CRLF)
        Return
    EndIf

HotKeySet("{SPACE}", "_Pause")

    While 1

        ; Check likely directions for pixel
        For $iDirnChange = 0 To UBound($aSearch) - 1
            ; Determine direction to check
            $iCheckDirn = $iCurrDirn + $aSearch[$iDirnChange]

            If $iCheckDirn < 0 Then
                $iCheckDirn = $iCheckDirn + 8
            ElseIf $iCheckDirn > 7 Then
                $iCheckDirn = $iCheckDirn - 8
            EndIf

            ; Prevent backtracking
            If Abs($iCurrDirn - $iCheckDirn) = 4 Then ContinueLoop

            ; Look for pixel in that direction
            $iCheck_X = $iCurr_X + $aDirn[$iCheckDirn][0]
            $iCheck_Y = $iCurr_Y + $aDirn[$iCheckDirn][1]

            ;If PixelGetColor($iCheck_X, $iCheck_Y) = 0x000000 Then
                PixelSearch($iCheck_X, $iCheck_Y, $iCheck_X, $iCheck_Y , $color,95)
    If not @error Then
                ; Move to this pixel

                ExitLoop
            EndIf
        Next

        If $iDirnChange > UBound($aSearch) - 1 Then
            ConsoleWrite("Lost it!" & @CRLF & @CRLF)
        Else
            ; Check if back to start
            If $iCheck_X = $iStart_X And $iCheck_Y = $iStart_Y Then
                ConsoleWrite("Back to the beginning!" & @CRLF & @CRLF)
                ExitLoop
            Else
                ; Set new coords
                $iCurr_X = $iCheck_X
                $iCurr_Y = $iCheck_Y
                ; Set new direction
                $iCurrDirn = $iCheckDirn

                ; Move mouse

                MouseMove($iCurr_X, $iCurr_Y)
                MouseClick("left")

                Sleep(10)
            EndIf
        EndIf
    WEnd
HotKeySet("{SPACE}", "_Follow")
EndFunc

Func _Pause()
   MouseUp("left")    $pause = not $pause
EndFunc

Func _Exit()
   MouseUp("left")
    Exit
EndFunc

 

2016-02-28_2302.png

Link to comment
Share on other sites

  • Moderators

fixitrod,

Sorry for the delay in replying, I was busy flying all day Sunday.

That blue box indeed looks as if it is the cause of the problem - and makes my "record - playback" suggestion seem like the perfect solution. I will rehash the earlier code I developed using that new image you posted yesterday so that you have a concrete example of the technique to incorporate into your code.

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

  • Moderators

fixitrod,

This works fine for me using Paint as a base. Open Paint and get the drawing area large enough to accommodate the sonar image (I used the one you posted above). Run the script and you should see a transparent sonar image appear. Select "Record" in the tray menu - the sonar image becomes fully opaque and you get a nice little magnified section to help position the mouse over a contour. When you are ready press {SPACE} to begin tracking - if the colour under the mouse is not "yellowish" then it refuses to track. When the tracking is done (I have set a limit of 20 secs for testing) select "Playback" in the tray menu - this will only run if a valid track has taken place. The sonar image is removed and the track is replayed in Paint with the mouse button down to draw a line. Once the replay is complete the sonar image returns so you can confirm that the correct line was followed and start the next. See if it works for you:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <Color.au3>

Global $sRecordFile = "Record.txt", $hRecordFile, $fRecorded = False
Global $hMag_GUI, $hMagDC, $hDeskTopDC, $hPen, $oObj
Global $hDLL = DllOpen("user32.dll")

Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

$cTray_Record = TrayCreateItem("Record")
$cTray_Playback = TrayCreateItem("Playback")
TrayCreateItem("")
$cTray_Exit = TrayCreateItem("Exit")
TraySetState()

$hSonar_GUI = GUICreate("Sonar", 1000, 506, 200, 200, $WS_POPUP, $WS_EX_TOPMOST)
$cPic = GUICtrlCreatePic("Hurshtown_thumb.bmp", 0, 0, 1000, 506)

GUISetState()

WinSetTrans($hSonar_GUI, "", 100)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            DllClose($hDLL)
            Exit
    EndSwitch

    Switch TrayGetMsg()
        Case $cTray_Exit
            DllClose($hDLL)
            Exit
        Case $cTray_Record
            WinSetTrans($hSonar_GUI, "", 255)
            _Record()
        Case $cTray_Playback
            WinMove($hSonar_GUI, "", @DesktopWidth, 200)
            _Playback()
            WinMove($hSonar_GUI, "", 200, 200)
            WinSetTrans($hSonar_GUI, "", 100)
    EndSwitch
WEnd


Func _Record()

    ; Create mag GUI
    $hMag_GUI = GUICreate("MAG", 100, 100, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetState(@SW_SHOW, $hMag_GUI)
    ; Get device context for Mag GUI
    $hMagDC = _WinAPI_GetDC($hMag_GUI)
    If @error Then Exit
    ; Get device context for DeskTop
    $hDeskTopDC = _WinAPI_GetDC(0)
    If @error Then
        _WinAPI_ReleaseDC($hMag_GUI, $hMagDC)
        Exit
    EndIf
    ; Create pen
    $hPen = _WinAPI_CreatePen($PS_SOLID, 5, 0x7E7E7E)
    $oObj = _WinAPI_SelectObject($hMagDC, $hPen)

    ; Look for mouse posiiton changes to move Mag GUI
    Local $iLast_Mouse_X = -1, $iLast_Mouse_Y = -1

    ; Wait for user input
    While 1
        Sleep(10)

        $aMouse_Pos = MouseGetPos()
        If $aMouse_Pos[0] <> $iLast_Mouse_X Or $aMouse_Pos[1] <> $iLast_Mouse_Y Then
            ; Redraw Mag GUI
            Loupe($aMouse_Pos)
            ; Reset position
            $iLast_Mouse_X = $aMouse_Pos[0]
            $iLast_Mouse_Y = $aMouse_Pos[1]
        EndIf

        ; {SPACE}
        If _IsPressed("20", $hDLL) Then
            ; Clear up Mag GUI
            _WinAPI_SelectObject($hMagDC, $oObj)
            _WinAPI_DeleteObject($hPen)
            _WinAPI_ReleaseDC(0, $hDeskTopDC)
            _WinAPI_ReleaseDC($hMag_GUI, $hMagDC)
            GUIDelete($hMag_GUI)

            ; Open new record file
            $hRecordFile = FileOpen($sRecordFile, $FO_OVERWRITE)
            ; Record file as line followed and set flag if successful
            $fRecorded = _Record_Line()
            ; Close file
            FileClose($hRecordFile)
            ExitLoop
        EndIf

        ; {ESCAPE}
        If _IsPressed("1B", $hDLL) Then
            ; Clear up Mag GUI
            _WinAPI_SelectObject($hMagDC, $oObj)
            _WinAPI_DeleteObject($hPen)
            _WinAPI_ReleaseDC(0, $hDeskTopDC)
            _WinAPI_ReleaseDC($hMag_GUI, $hMagDC)
            GUIDelete($hMag_GUI)
            ExitLoop
        EndIf
    WEnd

EndFunc   ;==>_Record

Func _Playback()

    If $fRecorded Then

        ; Read first line to position mouse
        $sLine = FileReadLine($sRecordFile)
        $aCoords = StringSplit($sLine, "x")
        MouseMove($aCoords[1], $aCoords[2])

        ; Open file to read all points
        $hRecordFile = FileOpen($sRecordFile, $FO_READ)

        ; Mouse button down
        MouseDown($MOUSE_CLICK_PRIMARY)

        While 1
            ; Read in next line
            $sLine = FileReadLine($hRecordFile)
            If @error Then
                ; End of file
                FileClose($hRecordFile)
                FileDelete($sRecordFile)
                ExitLoop
            EndIf

            ; Read coords
            $aCoords = StringSplit($sLine, "x")
            ; Move mouse
            MouseMove($aCoords[1], $aCoords[2])

            Sleep(10)

        WEnd

    EndIf

    ; Clear flag
    $fRecorded = False

    ; Mouse button up
    MouseUp($MOUSE_CLICK_PRIMARY)

EndFunc   ;==>_Playback

Func _Record_Line()

    ; Array holding next position to check for each direction [delta-X, Delta-Y]
    Local $aDirn[8][2] = [[0, -1], _
            [1, -1], _
            [1, 0], _
            [1, 1], _
            [0, 1], _
            [-1, 1], _
            [-1, 0], _
            [-1, -1]]

    ; Array to hold search directions relative to current direction
    Local $aSearch[] = [0, 1, -1, 2, -2, 3, -3]

    ; See if on line
    $aStartPos = MouseGetPos()
    ; Set start position
    $iCurr_X = $aStartPos[0]
    $iCurr_Y = $aStartPos[1]
    $iStart_X = $aStartPos[0]
    $iStart_Y = $aStartPos[1]

    ; Check for valid colour
    $iColour = PixelGetColor($iStart_X, $iStart_Y)
    $iRed = _ColorGetRed($iColour)
    $iGrn = _ColorGetGreen($iColour)
    If $iRed > 0x70 And $iGrn > 0x70 Then
        ConsoleWrite("Ready to go!" & @CRLF)
    Else
        ConsoleWrite("Not on a contour" & @CRLF)
        Return False
    EndIf

    ; Check for possible directions
    $iCurrDirn = -1
    For $iDirnCheck = 0 To 7
        ; Search around for another pixel
        $iFirstMove_X = $iCurr_X + $aDirn[$iDirnCheck][0]
        $iFirstMove_Y = $iCurr_Y + $aDirn[$iDirnCheck][1]
        PixelSearch($iFirstMove_X, $iFirstMove_Y, $iFirstMove_X, $iFirstMove_Y, $iColour, 95)
        If Not @error Then
            ; Set direction
            $iCurrDirn = $iDirnCheck
            ExitLoop
        EndIf
    Next
    ; Check direction is set
    If $iCurrDirn = -1 Then
        ConsoleWrite("Cannot follow!" & @CRLF & @CRLF)
        Return False
    EndIf

    ; Just for testing
    $nBegin = TimerInit()

    While 1

        ; Just for testing
        If TimerDiff($nBegin) > 20000 Then
            ExitLoop
        EndIf

        ; Check likely directions for pixel
        For $iDirnChange = 0 To UBound($aSearch) - 1
            ; Determine direction to check
            $iCheckDirn = $iCurrDirn + $aSearch[$iDirnChange]

            If $iCheckDirn < 0 Then
                $iCheckDirn = $iCheckDirn + 8
            ElseIf $iCheckDirn > 7 Then
                $iCheckDirn = $iCheckDirn - 8
            EndIf

            ; Prevent backtracking
            If Abs($iCurrDirn - $iCheckDirn) = 4 Then ContinueLoop

            ; Look for pixel in that direction
            $iCheck_X = $iCurr_X + $aDirn[$iCheckDirn][0]
            $iCheck_Y = $iCurr_Y + $aDirn[$iCheckDirn][1]

            PixelSearch($iCheck_X, $iCheck_Y, $iCheck_X, $iCheck_Y, $iColour, 95)
            If Not @error Then
                ExitLoop
            EndIf
        Next

        If $iDirnChange > UBound($aSearch) - 1 Then
            ConsoleWrite("Lost it!" & @CRLF & @CRLF)
            Return False
        Else
            ; Check if back to start
            If $iCheck_X = $iStart_X And $iCheck_Y = $iStart_Y Then
                ConsoleWrite("Back to the beginning!" & @CRLF & @CRLF)
                ExitLoop
            Else
                ; Set new coords
                $iCurr_X = $iCheck_X
                $iCurr_Y = $iCheck_Y
                ; Set new direction
                $iCurrDirn = $iCheckDirn

                ; Move mouse
                MouseMove($iCurr_X, $iCurr_Y)

                ; Store coords
                FileWrite($hRecordFile, $iCurr_X & "x" & $iCheck_Y & @CRLF)

                Sleep(10)
            EndIf
        EndIf
    WEnd

    Return True

EndFunc   ;==>_Record_Line

Func Loupe($aMouse_Pos)

    Local $iX, $iY, $tPoint

    ; Fill Mag GUI with 5x expanded contents of desktop area (10 pixels around mouse)
    DllCall("gdi32.dll", "int", "StretchBlt", _
            "int", $hMagDC, "int", 0, "int", 0, "int", 100, "int", 100, _
            "int", $hDeskTopDC, "int", $aMouse_Pos[0] - 10, "int", $aMouse_Pos[1] - 10, "int", 20, "int", 20, _
            "long", $SRCCOPY)

    ; Draw crosshairs
    _WinAPI_DrawLine($hMagDC, 0, 52, 40, 52) ; horizontal left
    _WinAPI_DrawLine($hMagDC, 60, 52, 100, 52) ; horizontal right
    _WinAPI_DrawLine($hMagDC, 52, 0, 52, 40) ; vertical top
    _WinAPI_DrawLine($hMagDC, 52, 60, 52, 100) ; vertical bottom

    ; Keep Mag GUI on screen
    If $aMouse_Pos[0] < (@DesktopWidth - 120) Then
        $iX = $aMouse_Pos[0] + 20
    Else
        $iX = $aMouse_Pos[0] - 120
    EndIf
    If $aMouse_Pos[1] < (@DesktopHeight - 150) Then
        $iY = $aMouse_Pos[1] + 20
    Else
        $iY = $aMouse_Pos[1] - 120
    EndIf
    WinMove($hMag_GUI, "", $iX, $iY, 100, 100)

EndFunc   ;==>Loupe

Given your explanation above of the manual steps you take, that should not prove too difficult to incorporate into your Google Earth-based script.

The only problem I have found is that the mouse will not follow some of the sharper corners on the contours.  This is because of the way the pixels are set out which leads the mouse into a dead end where retracing its steps is the first available option - a good example is at around 610x60 on the sonar image. I think that trying to code araound this will make the whole thing too complex, so I got around the problem by manually adjusting the contour to a slightly smoother curve - it only means removing 1 or 2 pixels, so I do not see this as a major falsification of the data. So a "test" recording on each contour before you definitively trace the line would be a good idea.

I hope this script will allow you to automate your task. It has been a fun experience so far - let me know if you need any more help!

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

This is amazing, I really appreciate all your time. I will have time in the next few days to work on this and reply. My father is in the hospital so that's conning first right now. 

All of this is helping me learn autoit as well. For those of you following this that are new and want to learn starting a project and working through this and reading and understanding others code is helping me a lot! 

Thanks everyone. 

M23, I will be back to this. I really want this to work. Talk to you in a few days. 

Link to comment
Share on other sites

  • Moderators

fixitrod,

Glad you like it. I will be off to Spain for some of next week to see my new granddaughter so do not be surprised if I take while to answer.

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

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

×
×
  • Create New...