Tracking an object based on color
In this recipe we will show how to track objects with a specified color using the OpenCV library.
Getting ready
In this recipe we will use OpenCV, so please refer to the Integrating with OpenCV recipe from Chapter 3, Using Image Processing Techniques. We will also need InterfaceGl which is covered in the Setting up a GUI for parameter tweaking recipe from Chapter 2, Preparing for Development.
How to do it…
We will create an application that tracks an object with a selected color.
Include the necessary header files:
#include "cinder/gl/gl.h" #include "cinder/gl/Texture.h" #include "cinder/Surface.h" #include "cinder/ImageIo.h" #include "cinder/Capture.h" #include "cinder/params/Params.h" #include "CinderOpenCV.h"
Add members to store the original and processed frame:
Surface8u mImage;
Add members to store the tracked object's coordinates:
vector<cv::Point2f> mCenters; vector<float> mRadius;
Add members to store the parameters that will be passed to the...