SimpleC 0 Posted April 16, 2011 (edited) Hello autoit.. I'm working on a project where I need to search for a triangle. Its your basic 3-4-5 triangle. One side is longer then the other 2. I thought it would be cake to set up a search to look for the color of the triangle and then calculate which point would be the point I want. Say the 90 degree angle point. I have tried pixelsearch and pixelgetcolor with little success. I ended up going with pixelgetcolor because I needed to loop through every possible point. Doesn't matter where the 3 points are on the screen the distance will always be the same. Same for the orientation. If its facing down instead of up it should be able to tell me where that 90 degree angle is. Unfortunately it doesn't work and I can't think of any other way of doing this. If anyone has done anything like this before or might be able to point me in right direction that would be fantastic. Heres my code so far... sorry for the noobish code. expandcollapse popup;for now these points are static but will be user inputed later ;--top point $x1 = 345 $y1 = 167 ;--left point $x2 = 302 $y2 = 234 ;--right point $x3 = 393 $y3 = 230 ;--calculates the distance between the given points. "ahh math" $leSide = _distance($x1, $y1, $x2, $y2) ;from top to left $riSide = _distance($x1, $y1, $x3, $y3) ;from top to right $le2ri = _distance($x2, $y2, $x3, $y3) ;from left to right $color = 0x000000 ;color to be searching for - black ;--Search Area variables. dim $topX, $topY, $botX, $botY $botX = 687 $botY = 433 WinActivate("arrow - Paint") tooltip("Searching. Please wait..", 400, 400) ;-searches through every point in the given search area for a black dot. If it finds one then ;-it will search for 2 other points using the given distance. If it finds those then it will move the mouse ;-to the tip of the arrow for $x = 67 to $botX for $y = 51 to $botY $px = pixelgetcolor($x, $y) if $px = $color Then if _search($x, $y, $leSide, $color) = true and _search($x, $y, $reSide, $color) = true and _search($x, $y, $le2ri , $color) = true Then tooltip("YAYA it works", 400, 400) mousemove($x, $y) Else ContinueLoop EndIf EndIf Next Next func _search($x, $y, $dis, $color ) ;sets the search area for a point using the distance for the search area $xTemp = $x $yTemp = $y for $xTemp = $xTemp - $dis to $xTemp+ $dis for $yTemp = $yTemp - $dis to $yTemp + $dis $px2 = pixelgetcolor($xTemp, $yTemp) if $px2 = $color and _distance($x, $y, $xTemp,$yTemp) = $dis Then return True Else ContinueLoop EndIf Next Next EndFunc func _distance($x1, $y1, $x2, $y2) $num = round(sqrt(abs(($x1-$x2)^2)+abs(($y1 - $y2)^2)),0) return $num EndFunc Edited April 16, 2011 by SimpleC Share this post Link to post Share on other sites
SimpleC 0 Posted April 30, 2011 Well I figured out how to get it to work but its not in real time like I had hoped. If anyone has any suggestions on making this work in real time please let me know. Here's my new code if anyone is interested expandcollapse popup#Include <Array.au3> HotKeySet("{ESC}", "Terminate") ;========================================================================= ;Searches for the top point of an arrow and moves the mouse to it ;stores all found black colors into an array then uses the distance formula ;to calculate the distance between each point. It then stores the found points ;and checks them against the orinal. ;for now these points are static but will be user inputed later ;--top point $x1 = 341 $y1 = 163 ;--left point $x2 = 298 $y2 = 230 ;--right point $x3 = 393 $y3 = 230 ;--bottom point $x4 = 341 $y4 = 291 ;--calculates the distance between each point $leftD = _distance($x1, $y1, $x2, $y2) $rightD = _distance($x1, $y1, $x3, $y3) $lft2rit = _distance($x2, $y2, $x3, $y3) $tp2btm = _distance($x1, $y1, $x4, $y4) ;--Color to search for $color = 0x000000 ;-----search area cordinates $sX1 = 67 $sY1 = 51 $sX2 = 687 $sY2 = 433 ;----array to store all found points dim $xArray[300] dim $yArray[300] ;---Counter $x = 0 WinActivate("arrow - Paint") tooltip("Searching. Please wait..", 400, 400) ;---Loops through every point in the given search area and stores all of the set color to an array based on cordiantes for $i = $sX1 to $sX2 for $z = $sY1 to $sY2 $px = pixelgetcolor($i, $z) if $px = $color Then $xArray[$x] = $i $yArray[$x] = $z $x = $x + 1 EndIf next Next ;---Loops through every found point and finds the longest line top to bottom for $x = 0 to 299 for $j = 0 to 299 $check = _distance($xArray[$x], $yArray[$x], $xArray[$j], $yArray[$j]) if $check = $tp2btm Then ;finds the longest line and stores the top and bottom point then continues the loop $tpbtmX = $xArray[$x] $tpbtmY = $yArray[$x] $tpORbtmX = $xArray[$j] $tpORbtmY = $yArray[$j] ExitLoop EndIf next Next ;---Loops through each point in the array again and compares it to long line. If they dont match then stores the points. for $x = 0 to 299 for $j = 0 to 299 $check = _distance($xArray[$x], $yArray[$x], $xArray[$j], $yArray[$j]) if $check = $lft2rit and $xArray[$x] <> $tpbtmX and $yArray[$x] <> $tpbtmY _ and $xArray[$x] <> $tpbtmX and $yArray[$x] <> $tpbtmY _ and $xArray[$j] <> $tpORbtmX and $yArray[$j] <> $tpORbtmY _ and $xArray[$j] <> $tpORbtmX and $yArray[$j] <> $tpORbtmY Then $lftrghtX = $xArray[$x] $lftrghtY = $yArray[$x] $lftORrghtX = $xArray[$j] $lftORrghtY = $yArray[$j] ExitLoop EndIf next Next ;--Checks the distance of each found point and figures out the left side $lftCheck1 = _distance($lftrghtX, $lftrghtY, $tpbtmX, $tpbtmY) $lftCheck2 = _distance($lftrghtX, $lftrghtY, $tpORbtmX, $tpORbtmY) $lftCheck3 = _distance($lftORrghtX, $lftORrghtY, $tpbtmX, $tpbtmY) $lftCheck4 = _distance($lftORrghtX, $lftORrghtY, $tpORbtmX, $tpORbtmY) select case $lftCheck1 = $leftD mousemove($tpbtmX, $tpbtmY) case $lftCheck2 = $leftD mousemove($tpORbtmX, $tpORbtmY) case $lftCheck3 = $leftD mousemove($tpbtmX, $tpbtmY) case $lftCheck4 = $leftD mousemove($tpORbtmX, $tpORbtmY) EndSelect func _distance($x1, $y1, $x2, $y2) $num = round(sqrt(abs(($x1-$x2)^2)+abs(($y1 - $y2)^2)),1) return $num EndFunc Func Terminate() Exit 0 EndFunc Share this post Link to post Share on other sites