Raspberry Pi Computer Vision Tutorial for the BrickPi

OpenCV_Logo
OpenCV for the Raspberry Pi robots.

How computers see the world.
Credits: “OfxOpenCV” by Screenshot of openFrameworks. Licensed under MIT via Wikimedia Commons

What if your robot could “see” the world around it?

One of the most “eye-opening” things you can do with your robot project is to add vision.  This is commonly called computer vision, and has recently been made affordable by the dropping cost of digital cameras (thanks to the massive amounts of smartphones being cranked out!).

Even if buying a camera for your Pi is now pretty cheap, integrating it into your software has always been intimidating.  Sure, you can take pictures, bu can your robot figure out what they mean?

Raspberry Pi Computer Vision

Raspberry Pi Robot holding a tennis ball

The APL Picker grabs a yellow ball.

OpenCV, or Open Source Computer Vision, is an open-source library of programming functions that handle computer vision.  Translation: this software analyzes computer pictures and extracts data.

For example, let’s say you had a robotic arm (such as a APL Picker!) trying to watch different bouncing balls, and grab a particular color (yellow, for example).  How does OpenCV give the Raspberry Pi computer vision?

Magic.

OpenCV is open vision for the Raspberry Pi.

OpenCV for the Raspberry Pi.

Actually, no magic.  The robot has a digital camera.  The robot takes pictures of the balls it is thinking about grabbing constantly.  That’s easy enough and pretty straightforward.  But just because you have the picture, how do you figure out where the balls are in the picture?

OpenCV is a visual analysis program that will analyze the pictures and tell you where the balls are.  OpenCV is super-powerful with a lot of tools for analyzing pictures.  But in our example, we’re going to try to do something pretty simple: look for the round yellow blob (which is pretty much what a tennis ball will look like).  OpenCV software has libraries that find the position of the center of the ball in a picture of a particular color.  If you can calibrate the picture to the robotic arm, your Raspberry Pi is grabbing yellow tennis balls!

OpenCV Tutorial for BrickPi

The Brickpi Bookreader robot reads real paper booksWoolfel, a frequent contributor to our forums, has written a tutorial for getting started with vision analysis, OpenCV, the Raspberry Pi, and the BrickPi.  He has kindly documented it all on his blog, and with a contribution to our Python libraries for the BrickPi.

Woolfel’s blog walks us through installation of OpenCV, updating the Github examples, and running them.  He also does a great job of breaking down what each component of the project does, and how they talk to each other.

Installing OpenCV on the Raspberry Pi can take some time, but computer vision is a pretty compelling thing to add to your robot!

You can see Woolfel’s blog post on this here.

And check out the code in the Github project here.

See more projects like a streaming robotInstalling a BrickPi on Raspberry Pi B+, and BrickPi hacking.

More Projects From the Forums

Get help, show off, and see more projects for the Raspberry Pi, the BrickPi, and LEGOs like it in the forums.

1 Comment

  1. peter lin February 4, 2015

    thanks for posting a blog about my explorations. OpenCV is fun stuff and I hope other people are inspired to play with it. I’m working on a C module to do line detection, since python is way too slow. It takes any where from 7-10seconds on a 640×480 color image, when it really should take less than 40ms.

Leave a reply

{"cart_token":"","hash":"","cart_data":""}