Reader small image

You're reading from  BeagleBone Robotic Projects

Product typeBook
Published inDec 2013
PublisherPackt
ISBN-139781783559329
Edition1st Edition
Right arrow
Author (1)
Richard Grimmett
Richard Grimmett
author image
Richard Grimmett

Richard Grimmett has more fun that should be allowed working on robotics projects while teaching Computer Science and Electrical Engineering at Brigham Young University Idaho. He has a Bachelors and Masters degree 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 has written books on the basics of using the BeagleBone Black for robotics projects, and another for the Raspberry PI and yet another for the Arduino.
Read more about Richard Grimmett

Right arrow

Chapter 4. Allowing the BeagleBone Black to See

Your projects can communicate via voice; now you are going to add vision with a webcam. You'll use this functionality in lots of different applications. Fortunately, adding hardware and software for vision is both easy and inexpensive.

Mission briefing


In this chapter, you'll add a USB webcam to your system. Having the standard USB interface on your board opens a wide range of amazing possibilities. On top of that, there are several amazing open-source libraries. These offer complex capabilities that you can use in your projects without spending months coding them.

Why is it awesome?

Vision will open a set of possibilities for your project. These can range from simple motion detection to advanced capabilities such as facial recognition, object identification, and even object tracking. The robot can also use vision to detect its surroundings and avoid obstacles.

Your objectives

In this chapter we will cover:

  • Connecting your USB camera to your BeagleBone Black and viewing the images

  • Downloading and installing OpenCV, a full-featured vision library

  • Using the vision library to detect colored objects

Tip

Downloading the example code and colored images

You can download the example code files and colored images for this Packt book you...

Connecting the USB camera to the BeagleBone Black and viewing the images


Our first step in enabling computer vision is connecting the USB camera to the USB port. I have a new Logitech HD 720 camera as my example.

Prepare for lift off

To access the USB webcam, I like to use a program called guvcview. Install this by typing sudo apt-get install guvcview.

Engage thrusters

Connect your USB camera and make sure your LAN cable is plugged in. Then apply power to the BeagleBone Black. After the system is booted, you can check to see if the BeagleBone Black has found your USB camera. Go to the /dev directory and type ls. You should see the output as shown in the following screenshot:

Look for the video0 device, the webcam. If you see it, the system knows your camera is there.

Now let's use guvcview to see the output of the camera. Since this will need to output some graphics, you either need to use a monitor connected to the board as well as a keyboard and a mouse, or you can use vncserver. If you are...

Using the vision library to detect colored objects


Now that you have access to the OpenCV library, let's see what it can do.

Prepare for lift off

OpenCV and your webcam can track objects. This might be useful if you are building a system that needs to track and follow a colored ball. OpenCV makes this amazingly simple by providing some high-level libraries that can help you with this task. I'm going to do this in Python, as I find it much easier to work with than C. If you feel more comfortable in C, these instructions should be fairly easy to translate. Also, performance will be better if implemented in C, so you might create the initial capability in Python, and then finalize the code in C.

Engage thrusters

If you'd like, create a directory to hold your image-based work. From your home directory, create a directory named imageplay by typing mkdir imageplay. Then change directory to imageplay by typing cd imageplay.

Once there, let's bring over your camera.py file as a starting point by typing...

Mission accomplished


Your projects can now speak and see! You can issue commands, and your projects can respond to changes in the physical environment sensed by the webcam. Next, you will add mobility using motors, servos, and in other ways.

Challenges


Having a webcam connected to your system provides all kinds of additional capabilities. One of the absolute neatest devices out there is Kinect for the Xbox. This device provides not only video, but depth using an infrared device. There are individuals working to make Kinect work with the BeagleBone Black. Several good libraries enable Kinect on Ubuntu. If you'd like to try, buy a used Kinect and then go to http://speculatrix.tumblr.com/post/23043561344/kinect-on-the-beagleboard-and-ubuntu or http://kinepeutics.blogspot.com/2012/04/ethernet-working-installing-kinect.html and give it a try. Just a word of warning, this task is not for beginners. Later we will talk about the Robot Operating System, which may make it easier.

Also, you can get 3D vision with OpenCV using two cameras. There are several good places for example code, for example in the samples/cpp directory that came with OpenCV there is an example stereo_match.cpp. Also, for more code examples, you can visit http:/...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
BeagleBone Robotic Projects
Published in: Dec 2013Publisher: PacktISBN-13: 9781783559329
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

Richard Grimmett has more fun that should be allowed working on robotics projects while teaching Computer Science and Electrical Engineering at Brigham Young University Idaho. He has a Bachelors and Masters degree 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 has written books on the basics of using the BeagleBone Black for robotics projects, and another for the Raspberry PI and yet another for the Arduino.
Read more about Richard Grimmett