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:
    Finding colored objects in your vision system

    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) ...

Get BeagleBone: Creative Projects for Hobbyists now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.