Miliardsto Posted June 7, 2019 Share Posted June 7, 2019 In attachmens are the similiar rectangular shapes which one I want to detect and then make a mouse click inside center of this square. So on the screen would appear shape like this (various colors) And how to detect them? Thats what I invented and tried to do but it is still inefficient. If you have any ideas how to detect these shapes or there are UDFs to use in this case or something. Please tell me. ImageSearch would be useless I think becouse cant set transparent inside square. I can search for a piece of square (corners better) but there could be a few colors and sometimes corners and pieces of rectangulars are covered. I can use pixelsearch. It should search from top left to right bottom always but it doesnt I dont know why . If it would then I can get x and y of first top-left pixel of square and then check pixelgetcolor for some next pixels and be sure thats the searched square but pixelsearch, sometimes detect pixel with definied color in right of square, sometimes in left, sometimes in bottom... its code for this pixelsearch but it does not work properly so its here only for viewing purposes expandcollapse popup; Press Esc to terminate script, Pause/Break to "pause" Global $Paused, $Runner HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("{F9}", "ShowMe") ;;;; Body of program would go here ;;;; While 1 Sleep(10) WEnd ;;;;;;;; Func TogglePause() $Paused = Not $Paused While $Paused Sleep(10) ToolTip('Script is "Paused"', 0, 0) WEnd ToolTip("") EndFunc ;==>TogglePause Func Terminate() Exit 0 EndFunc ;==>Terminate Func ShowMe() $shadeVariation = 2 $red = 0xFF0000 $redSec = 0xF40000 $red3 = 0x8B0000 $green = 0x00ff00 $green2 = 0x00f200 $leftTopX = 130 $leftTopY = 130 $rightBottomX = 800 $rightBottomY = 800 $red_cord = PixelSearch($leftTopX, $leftTopY,$rightBottomX, $rightBottomY, $red,$shadeVariation) $redSec_cord = PixelSearch($leftTopX, $leftTopY,$rightBottomX, $rightBottomY, $redSec,$shadeVariation) $red3_cord = PixelSearch($leftTopX, $leftTopY,$rightBottomX, $rightBottomY, $red3,$shadeVariation) If IsArray($red_cord) = True Then checkIfIts($red,$red_cord) ; -------------------------------------------------------- Elseif IsArray($redSec_cord) = True Then checkIfIts($red3,$redSec_cord) ; -------------------------------------------------------- Elseif IsArray($red3_cord) = True Then checkIfIts($redSec,$red3_cord) ; -------------------------------------------------------- Else MsgBox(0,"!","Could not find colur") EndIf EndFunc ;==>ShowMe Func checkIfIts($color,$cord) MouseMove($cord[0], $cord[1], 1) ConsoleWrite($cord[0] & " " & $cord[1]+90) ; check 2 x times in bottom and 2x in right to be sure its a target $firstShift = 20 $secondShift = 50 $bottom1 = Hex(PixelGetColor($cord[0], $cord[1]+$firstShift)) ;Sleep(1000) MouseMove($cord[0], $cord[1]+$firstShift, 1) $bottom2 = Hex(PixelGetColor($cord[0], $cord[1]+$secondShift)) $right1 = Hex(PixelGetColor($cord[0]+$firstShift, $cord[1])) $right2 = Hex(PixelGetColor($cord[0]+$secondShift+10, $cord[1])) ConsoleWrite("color = " & Hex($color) & @LF) ConsoleWrite("color bottom = " & $bottom1 & @LF) ConsoleWrite("color bottom2 = " & $bottom2 & @LF) ConsoleWrite("color right1 = " & $right1 & @LF) ConsoleWrite("color right2 = " & $right2 & @LF) If $bottom1 = $color Or $bottom2 = $color Or $right1 = $color Or $right2 = $color Then MouseMove($cord[0], $cord[1], 1) EndIf EndFunc Link to comment Share on other sites More sharing options...
Werty Posted June 7, 2019 Share Posted June 7, 2019 Check out mylise's OpenCV UDF, examples for just that. Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Miliardsto Posted June 8, 2019 Author Share Posted June 8, 2019 4 hours ago, Werty said: Check out mylise's OpenCV UDF, examples for just that. Wow I made research. Tried your examples. This tool is so powerfull. I am interested in tracking these objects (squares) in real time on the computer screen. Have you already done such things with the use of opencv and autoit? Please give me links, examples of code, tips , whatever, on how to achieve this with the help of your functions rewritten in autoit. Thanks you man Link to comment Share on other sites More sharing options...
Werty Posted June 8, 2019 Share Posted June 8, 2019 Umm, it's not my udf, you should ask the question in the thread i linked to, the only experience i have with opencv are some webcam functions. Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Miliardsto Posted June 8, 2019 Author Share Posted June 8, 2019 aaa ok xd. sorry man I dont know why I made assumption in my mind its your UDF without comparing your nick and this thread author nick xD Link to comment Share on other sites More sharing options...
junkew Posted June 8, 2019 Share Posted June 8, 2019 GDI functions can help to do it in a simpler way if what you want is more pixel comparison logic to do it yourself. An example (not for squares) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now