Recognize circles of a given color

OpenMV related project discussion.
laufil
Posts: 4
Joined: Thu Nov 02, 2017 9:55 am

Recognize circles of a given color

Postby laufil » Tue Dec 12, 2017 9:27 am

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
User avatar
iabdalkader
Posts: 629
Joined: Sun May 24, 2015 3:53 pm

Re: Recognize circles of a given color

Postby iabdalkader » Tue Dec 12, 2017 7:20 pm

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")
User avatar
kwagyeman
Posts: 2459
Joined: Sun May 24, 2015 2:10 pm

Re: Recognize circles of a given color

Postby kwagyeman » Tue Dec 12, 2017 8:27 pm

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

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests