Book Image

Mastering Beaglebone Robotics

By : Richard Grimmett
Book Image

Mastering Beaglebone Robotics

By: Richard Grimmett

Overview of this book

Table of Contents (18 chapters)
Mastering BeagleBone Robotics
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Finding colored objects in your vision system


OpenCV can be used to track objects. As an example, let's build a system that tracks and follows a colored ball. OpenCV makes this activity amazingly simple; here are the steps:

  1. Create a directory to hold your image-based work. Once you have created the directory, go there and begin with your camera.py file.

  2. Now edit the file until it looks similar to the following screenshot:

    Let's look specifically at the changes you need to make to camera.py. The first three lines you add are as follows:

    cv.Smooth(img,img,cv.CV_BLUR,3)
    hue_img = cv.CreateImage(cv.GetSize(img), 8, 3)
    cv.CvtColor(img,hue_img, cv.CV_BGR2HSV)
    

    We are going to use the OpenCV library to first smooth the image, taking out any large deviations. The next two lines create a new image that stores the image in 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 your processing more on the...