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.


Now we filter the blue color.


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


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.


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


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 *