Using OpenCV and Python on the Raspberry Pi for simple object detection UPDATE

I recently wrote about detecting blue objects. Now that I have refined the code somewhat I am going to show how detect a round blue object and post the full source at the end. Most of it is the same as in the previous post but the circle detection is new.

The basic idea is that we take all contours from the image and then test it they are convex. If they are convex and the area of the contour is roughly pi*radius^2 it is a circle. The radius we get by applying a minimum enclosing circle around the contour.

Like before we have a couple of preprocessing steps.

This is our stater image, we have 3 blue objects.

ball_distinction_light

Now we filter the blue color.

ball_distinction_light_1_only_blue

Now we filter out the saturation channel of our HSV image and blur it.

ball_distinction_light_2_blur

Now we threshold it and erode it a little, we have still some other objects left.

ball_distinction_light_3a_morphNow we use a canny edge detection.

ball_distinction_light_3b_edges

And finally we detect all circles and mark their location on the original image.

ball_distinction_light_4_output

And here is the source for this:

 

This entry was posted in computer vision, Linux, python, raspberry pi. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*