You're reading from BeagleBone Robotic Projects
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.
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.
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.
To access the USB webcam, I like to use a program called
guvcview. Install this by typing sudo apt-get install guvcview
.
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...
Now that you have your camera connected, you can begin to access some amazing capabilities that have been provided by the open source community. The most popular of these for computer vision is OpenCV.
Now you need to install OpenCV, a complete vision library that provides tools for you to use to capture, process, and save your images. Before you do this, you need to expand the partition on your SD card so that you can download all the applications that you need. When you wrote the Linux operating system to your SD card, you copied a 2 GB image; so now your card thinks it is only a 2 GB card, no matter what size it really is. You need to reclaim this space.
To do this, you'll need to issue some fairly cryptic commands, but you can use the defaults, so it will be straightforward. First, open a terminal window. The card I am using is an 8 GB card, so if your card is of a different size, you might not see the...
Now that you have access to the OpenCV library, let's see what it can do.
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.
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...
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:/...