Page 1 of 1

Recognize circles of a given color

Posted: Tue Dec 12, 2017 9:27 am
by laufil
Hello, has anyone implemented a code to recognize circles of a certain color (for example Red)? He could put the code on me. Thank you

Re: Recognize circles of a given color

Posted: Tue Dec 12, 2017 7:20 pm
by iabdalkader
Hi, you could check the color at the circle center if it's a filled circle, or check the pixels on the circle's circumference if it's empty.

For example:

Code: Select all

# For filled circle:
r,g,b = img.get_pixel(c.x(), c.y())
if r > 200 and g < 25 and b < 25:
    print("red circle")

# For empty circle (you may want to average 5 pixels before and after cx+cr)
r,g,b = img.get_pixel(c.x() + c.r(), c.y())
if r > 200 and g < 25 and b < 25:
    print("red circle")

Re: Recognize circles of a given color

Posted: Tue Dec 12, 2017 8:27 pm
by kwagyeman
Mmm, I thought I answered this... Um, use find_circles combined with get_stats on the returned circle rect. This will find the circle and then return the color.