Jump to content

Coordinants on a picture


Recommended Posts

Hey. I've got a picture of a field that is to the scale of 1 pixel on the screen being one inch on the field. I basically need to be able to get a coordinant off of this picture but (0,0) would be the upper left corner of this picture, not of the whole screen. It is also on a window that can be moved so the position can change. The control ID for it is 6 and i've been trying to use that but with no luck. It is also part of my gui if that makes a difference. Thanks and I hope that somebody can help with this because my last few requests have gone unanswered and i've had to either give up on those ideas or work for hours trying to fix 1 thing.

Link to comment
Share on other sites

ok. its a little big so go to http://img400.imageshack.us/img400/1561/programcy7.jpg. basically that gray/red/blue picture is the field i want a coordinant off of. I can get it if I have the window go to the very upper left and top but The coordinants are still only accurate on my computer because some people have different window title heights and other things. Right now I am just having it subtract 53 from the X coord and 92 from the Y coord but I know there has to be a way to just get a Coord relative to the upper left of the field picture.

Link to comment
Share on other sites

um... basically, I click on the screen and it will (eventually) translate all of those coordinates and angles into code that will drive a robot wherever i click on the screen automatically. It will be very cool once I get it to work but untill then... I've got a lot of it worked out but I'm still having issues with getting the right coordinants. also, even if you lock the window in the upper left, On some other computers (i've tested it) it will get the wrong coordinants because they have a different title bar height or something like that.

Link to comment
Share on other sites

  • Moderators

I'm so confused on what you 2 are talking about.

So I'm going to take a stab at what I'm thinking you are talking about.

ControlGetPos() << Does that do it for you if you use Opt('MouseCoordMode', 2) and Opt('PixelCoordMode', 2)?

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

Hey. I've got a picture of a field that is to the scale of 1 pixel on the screen being one inch on the field. I basically need to be able to get a coordinant off of this picture but (0,0) would be the upper left corner of this picture, not of the whole screen. It is also on a window that can be moved so the position can change. The control ID for it is 6 and i've been trying to use that but with no luck. It is also part of my gui if that makes a difference. Thanks and I hope that somebody can help with this because my last few requests have gone unanswered and i've had to either give up on those ideas or work for hours trying to fix 1 thing.

Look in the help file at OPt("PixelCoordMode",2)

Link to comment
Share on other sites

ok since I don't think the OPT stuff will work i'll just paste my code.

#include <GUIConstants.au3>
#include <Math.au3>
Opt('MouseCoordMode', 2)
Opt("PixelCoordMode", 2) 


 $count = 0
Dim $Mpos_1 = "", $Mpos_1A = "", $Mpos_2 = "", $Mpos_2A = "", $line = ""
$LineColor = 0x00FF00; color BGR
$LineWidth = 2
$text = ""
$x_old = ""
$y_old = ""

HotKeySet( "z", "everything")

GUICreate("   WÌÑÑÒVÅTÍÓÑ -- P§   ",1024,768,0,0)
$reset = GUICtrlCreateButton("Reset",50,20,50,30)
$save = GUICtrlCreateButton("Save",375,20,50,30)
$exit = GUICtrlCreateButton("Exit",700,20,50,30)
GUICtrlCreatePic(@DesktopDir & "\field1.bmp",50,70,648,315)
$input = GUICtrlCreateInput($text,50,400,700,150,"0x00201004")
GUISetState()
While 1
   ;$dll = DllOpen("user32.dll")
   ;    If _IsPressed("02", $dll) Then
   ;        waypoint()
   ;        line1()
   ;        code()
   ;        sleep(100)
   ;    Else
   ;        sleep(20)
   ;    EndIf
   ;DllClose($dll)
    Sleep(5)
    $msg = GUIGetMsg()
    If $msg = $reset Then reset()
    If $msg = $save then save()
    If $msg = $exit then exit1()
    If $msg = $GUI_EVENT_CLOSE Then exit1()
WEnd
    
Func everything()
    waypoint()
    line1()
    code()
    waypoint()
    sleep(100)
EndFunc
    
Func reset()
    $count = 0
    GUICtrlCreatePic(@DesktopDir & "\field1.bmp",50,70,648,315)
    GUICtrlCreatePic(@DesktopDir & "\field1.bmp",50,70,648,315)
   ;GUICtrlSetImage(6,"C:\Documents and Settings\HP_Administrator\Desktop\field.bmp")
    $text = ""
    GUICtrlSetData(7,$text)
EndFunc

Func save()
    ClipPut($text)
EndFunc

Func exit1()
    Exit
EndFunc

Func waypoint()
    $win = WinGetPos("   WÌÑÑÒVÅTÍÓÑ -- P§   ")
    $off_x = $win[0]
    $off_y = $win[1]
    $pos = MouseGetPos()
    $x = $pos[0] - 4 - $off_x
    $y = $pos[1] - 4 - $off_y
   ;MsgBox(0,"",$off_x & "   " & $off_y & "   " & $x & "   " & $y)
    GUICtrlCreatePic(@DesktopDir & "\dot.bmp",$x,$y,9,9)
EndFunc

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc  ;==>_IsPressed


Func code()
    $win = WinGetPos("   WÌÑÑÒVÅTÍÓÑ -- P§   ")
    $pos = MouseGetPos()
        $x_move = $pos[0] - 53
        $y_move = $pos[1] - 92
   ;$x_move = $pos[0] - $win[0] - 105
   ;$y_move = $pos[1] - $win[1] - 97
    $distance = ""
    If $text <> "" Then
        $text = GUICtrlRead(7)
        $distance = Sqrt ( ($x_move - $x_old)^2 + ($y_move - $y_old)^2 )
        $feet1 = Floor($distance / 12) 
        $feet2 = Round($distance - ($feet1 * 12),1)
        $feet = " OR " & $feet1 & "'" & $feet2 & '" '
       ;$y_move1 = _Radian( $y_move )
       ;$y_old1 = _Radian( $y_old )
       ;$x_move1 = _Radian( $x_move )
       ;$x_old1 = _Radian( $x_old )
       ;$value1 = ATan(($y_move1 - $y_old1)/($x_move1 - $x_old1))
       ;$value = _Degree($value1)
        $value = ATan(($y_move - $y_old)/($x_move - $x_old)) * -57.2957795130823
       ;MsgBox(0,"",$value & "   " & ($y_move1 - $y_old1)/($x_move1 - $x_old1))
        $text = $text & "(" & $x_move & "," & $y_move & ")" & @CRLF & "Distance is: " & $distance & " OR " & $feet & @CRLF & "Angle is: " &  $value & @CRLF & @CRLF
    EndIf
    If $text = "" Then $text = "(" & $x_move & "," & $y_move & ")" & @CRLF & "Begin Point" & @CRLF & @CRLF
    $x_old = $x_move
    $y_old = $y_move
   ;GUICtrlCreateInput($text,50,400,700,150,"0x00201004")
   ;GUISetState()
    GUICtrlSetData(7,$text)
    
EndFunc

Func line1()
    line()
    line()
EndFunc

Func line()
    If $count = 0 Then
        Get_pos_one()
    EndIf
    If $count = 1 Then
        Get_pos_two()
        Get_drawing()
        Get_pos_one()
    EndIf
    If $count = 2 Then
        Get_pos_two()
        $count = 0
    EndIf
    $count = $count + 1
EndFunc


Func MouseClick2()
        Do
        $a = GUIGetCursorInfo()
        Sleep(100)
    Until $a[2]
EndFunc;==>mouseclick2


Func Get_pos_one()
    GUICtrlDelete($line)
    
    $Ms_In = MouseGetPos()
    $Mpos_1 = $Ms_In[0]
    $Mpos_2 = $Ms_In[1]
    
EndFunc;==>Get_pos_one

Func Get_pos_two()
    GUICtrlDelete($line)
    $Ms_In2 = MouseGetPos()
    $Mpos_1A = $Ms_In2[0]
    $Mpos_2A = $Ms_In2[1]
    
EndFunc;==>Get_pos_two

Func Get_drawing()
    
    If $Mpos_1 = "" Or $Mpos_1A = "" Then
        MsgBox(0, "Draw Error", " Two points of reference are required")
        MsgBox(0, "User Info", "Press *ESC* to exit" & @CRLF & "Press *F1* to set First position" & @CRLF & "Press *F2* to set Second position" & @CRLF & "Press *F3* to Draw the Line")
        Return
    EndIf
    $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    $pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", $LineWidth, "int", $LineColor)
    DllCall("gdi32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int", $Mpos_1, "int", $Mpos_2, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $Mpos_1A, "int", $Mpos_2A)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])
    
EndFunc;==>Get_drawing

Func Get_Exit()
    Exit
EndFunc;==>Get_Exit

also, since for some reason it won't let me host a picture of the field so i'll have a link for that in a few mins.

Link to comment
Share on other sites

  • Moderators

I suppose that finding the position of the image on the screen would do the same thing if it told me the upper left corner's coords but if i do controlgetpos(), I get (50,70) and I'm not sure why. I want the position relative the screen, not the gui.

Then you'll need to convert them over to screen coords mathmatically. Out of curiousity (because I NEVER use screen coords)... why does it need to be screen coords when you are interacting within a GUI itself?

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

um... i just want to know where that a user is pressing "z" over that picture. I need the (0,0) coord that I'm going to be measuring to be in the upper left corner of the field picture though so that I can have an accurate position to later have my robot go to. I'm not sure how to do this at all so If theres a way do this in the gui, I'd like to know it.

Link to comment
Share on other sites

  • Moderators

Wouldn't _IsPressed() and GUIGetCursorInfo() do what you want?

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

Wouldn't _IsPressed() and GUIGetCursorInfo() do what you want?

thanks a bunch for the GUIGetCursorInfo(). It gives me a number that I can work with for the position now so that problem is solved. I was using the _IsPressed() at first but it was recording the point like 4 times and when I tried to put in delays, It wasn't running the waypoint() function right and wasn't showing the dots. is there a way to make it so that the lines it draws on the field will come back if i minimize the window?

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