Computer Vision with the Raspberry Pi

Computer Vision with the Raspberry Pi

A recent development fresh out of CAROBOT is the involvement of computer vision with a Raspberry Pi and Python. Using the open-source library for computer vision – OpenCV – and a Pi Camera attached, the beginnings of a program to help the Pi understand what it’s seeing is taking shape.

So far, the Pi – using the camera attached – can read in the feed of what it’s seeing at a specified resolution. What our program intends to do is to analyze what it’s seeing in every single frame before moving onto the next. This clearly gates high FPS (Frames Per Second) if there are more computationally intensive operations going on with each analysis, so the resolution should remain small and the operations be kept simple.

As a part of the analysis, it reads in the 2D array of pixels of each frame, with each pixel assigned a specific RGB (Red-Green-Blue) value. Using functions from the OpenCV library, we can create contour plots of a specified range in colour. Seeing that the intention is to follow a line (namely a black one on a white background), we would want to filter out all the pixels that aren’t extremely dark and keep a sort of ‘map’ of what is dark.

When we filter this out, we create an outline of areas that are black – these are contours! Using other functions such as erode() and dilate(), we can clear up ‘noise’ which can be seen by the computer and only interpret the spots of contour that are large and dark. Through use of more functions readily available in OpenCV, we can set up ‘rectangles’ around the contours, such that we can figure out the orientation it has with respect to a vertical line in the center.

Using the rectangles previously used, we can set up motion of the rover based on the orientation and distance to the center, where the motion is based on the need to correct itself and have the line be in the middle of the screen. What’s next is to start incorporating motion and colour detection!

With more to come, the program will be only more polished and well-performing in the future!

Leave a Reply

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