Reader small image

You're reading from  Raspberry Pi Robotics Essentials

Product typeBook
Published inJun 2015
Publisher
ISBN-139781785284847
Edition1st Edition
Concepts
Right arrow
Author (1)
Richard Grimmett
Richard Grimmett
author image
Richard Grimmett

Dr. Richard Grimmett has been fascinated by computers and electronics from his very first programming project, which used Fortran on punch cards. He has bachelor's and master's degrees in electrical engineering and a PhD in leadership studies. He also has 26 years of experience in the radar and telecommunications industries, and even has one of the original brick phones. He now teaches computer science and electrical engineering at Brigham Young University, Idaho, where his office is filled with his many robotics projects.
Read more about Richard Grimmett

Right arrow

Chapter 6. Adding Vision to Your Biped

Now that your biped is up and mobile, is able to find barriers, and knows how to plan its path, you can now start to have it move around autonomously. However, you may want your robot to follow a color or motion.

In this chapter, you will be learning:

  • How to add a webcam to your biped robot

  • How to add RaspiCam to your biped robot

  • How to install and use OpenCV, an open source vision package

  • How to follow motion with your biped robot

Installing a camera on your biped robot


Having vision capability is a real advantage for your biped robot; you'll use this functionality in lots of different applications. Fortunately, adding hardware and software for vision is both easy and inexpensive. There are two choices as far as vision hardware is concerned. You can add a USB webcam to your system, or you can add RaspiCam, a camera designed specifically for Raspberry Pi.

Installing a USB camera on Raspberry Pi

Connecting a USB camera is very easy. Just plug it into the USB slot. To make sure that your device is connected, type lsusb. You should see the following:

This shows a Creative Webcam located at Bus 001 Device 004: ID 041e:4095. To make sure that the system sees this as a video device, type ls /dev/v* command and you should see something like the following:

The /dev/video0 is the webcam device. Now that your device is connected, let's actually see if you can capture images and video. There are several tools that can allow you to...

Edge Detection and OpenCv


Fortunately, one of the examples in the OpenCV Python set is a program named edge.py. The following is that file (with blank lines removed):

This program uses the Canny image detection algorithm implemented by OpenCV to find the edges in any image. For more on the Canny edge algorithm, refer to http://dasl.mem.drexel.edu/alumni/bGreen/www.pages.drexel.edu/_weg22/can_tut.html or http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_canny/py_canny.html. You captured an image earlier; you can use this program to look at the edges and to also see how setting a different threshold can show more/less edges. Run the program with the image captured earlier and you will see the following:

You will notice that there is a threshold slide bar setting at the top. If you adjust this threshold up, it will find fewer edges—the edges that have a larger threshold. The picture for a setting of 30 is as follows:

Now you can see how this process could be translated...

Color and motion finding


OpenCV and your webcam can also track colored objects. This will be useful if you want your biped to follow a colored object. OpenCV makes this amazingly simple by providing some high-level libraries that can help us with this task. To accomplish this, you'll edit a file to look something like what is shown in the following screenshot:

Let's look specifically at the code that makes it possible to isolate the colored ball:

  • hue_img = cv.CvtColor(frame, cv.CV_BGR2HSV): This line creates a new image that stores the image as per the values of hue (color), saturation, and value (HSV), instead of the red, green, and blue (RGB) pixel values of the original image. Converting to HSV focuses our processing more on the color, as opposed to the amount of light hitting it.

  • threshold_img = cv.InRangeS(hue_img, low_range, high_range): The low_range, high_range parameters determine the color range. In this case, it is an orange ball, so you want to detect the color orange. For a good...

Summary


Your biped robot can walk, use sensors to avoid barriers, plans its path, and even see barriers or target. In the final chapter, you'll learn to connect your biped robot remotely so that you can control it and monitor it, without the wires.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Robotics Essentials
Published in: Jun 2015Publisher: ISBN-13: 9781785284847
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Richard Grimmett

Dr. Richard Grimmett has been fascinated by computers and electronics from his very first programming project, which used Fortran on punch cards. He has bachelor's and master's degrees in electrical engineering and a PhD in leadership studies. He also has 26 years of experience in the radar and telecommunications industries, and even has one of the original brick phones. He now teaches computer science and electrical engineering at Brigham Young University, Idaho, where his office is filled with his many robotics projects.
Read more about Richard Grimmett