Chapter 4. Vision and Image Processing

Now that your tracked platform can move around, you'll want to add a more complex sensor to provide information to it—the webcam. Using a webcam, you can allow your robot to see its environment. You'll learn how to use a powerful open source software platform called OpenCV to add powerful vision algorithms to your robotic platform.

In this chapter, you will be doing the following:

  • Connecting a webcam
  • Learning image processing using OpenCV
  • Discovering edge detection for barrier finding
  • Adding color and motion detection for targeting

Connecting a webcam to the BeagleBone Black

In order to enable computer vision, you'll need to connect a USB web camera to the USB port. Most standard USB webcams will work. This example uses a Logitech HD 720.

Here are the steps:

  1. Check if your USB webcam is connected. You'll do this using a program called guvcview. Install this by typing sudo apt-get install guvcview.
  2. Connect your USB camera and power up the BeagleBone Black. After the system is booted, go to the /dev directory and type ls. You should see the following screenshot:
    Connecting a webcam to the BeagleBone Black
  3. The video0 device is the USB webcam. If you see its entry in the directory, then it means the system can access your camera.

Now you can use guvcview to see images from the camera. Since these are graphic images, you'll need to use either a monitor connected directly to the BeagleBone Black or the remote graphics connection VNC server. If you want to use the remote connection, make sure you start the server on the BeagleBone Black by typing vncserver via SSH. Then start VNC viewer as described in Chapter 1, Preparing the BeagleBone Black. Once you have a VNC viewer window, then open a terminal and type sudo guvcview. You should see an output similar to the following screenshot:

Connecting a webcam to the BeagleBone Black

The video window displays the webcam images and the GUVCViewer Controls window controls the output from the camera. The default settings may work fine for your USB webcam. However, if you get a black display for the camera images, you will need to adjust the settings. Select the GUVCViewer Controls window and then the Video & Files tab. You will see a set of selections where you can adjust the settings for your camera:

Connecting a webcam to the BeagleBone Black

The setting that will affect your image the most is the Resolution setting. If you cannot see an image, then adjust the resolution down; often this will resolve the issue. The Resolution selection will tell you what resolutions are supported for your camera. If you want to display the frame rate, you can do it by checking the Show box at the right of the Frame Rate setting. Beware that the VNC viewer will also affect the refresh rate, so if you are doing this through the VNC viewer, your frame rate will be much slower than if you're using the BeagleBone Black and a monitor directly.

With your camera up and running and a desired resolution set, you can now start using OpenCV to process the image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.32.116