Jump to content

Detect rectangular shapes


Recommended Posts

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

; 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

 

 

shape.png

Link to comment
Share on other sites

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

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

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