JeVoisBase  1.1
JeVois Smart Embedded Machine Vision Toolkit Base Modules
ObjectTracker Class Reference

Simple color-based object detection/tracking. More...

Inheritance diagram for ObjectTracker:
Collaboration diagram for ObjectTracker:

Public Member Functions

virtual ~ObjectTracker ()
 Virtual destructor for safe inheritance. More...
 
virtual void process (jevois::InputFrame &&inframe) override
 Processing function, no USB video output. More...
 
virtual void process (jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
 Processing function, with USB video output. More...
 
- Public Member Functions inherited from jevois::Module
 Module (std::string const &instance)
 
virtual ~Module ()
 
virtual void sendSerial (std::string const &str)
 
virtual void parseSerial (std::string const &str, std::shared_ptr< UserInterface > s)
 
virtual void supportedCommands (std::ostream &os)
 
- Public Member Functions inherited from jevois::Component
 Component (std::string const &instance)
 
virtual ~Component ()
 
std::shared_ptr< ComponentgetSubComponent (std::string const &instance) const
 
std::shared_ptr< Comp > addSubComponent (std::string const &instance, Args &&...args)
 
void removeSubComponent (std::shared_ptr< Comp > &component)
 
void removeSubComponent (std::string const &instance, bool warnIfNotFound=true)
 
std::shared_ptr< Comp > getSubComponent (std::string const &instance) const
 
bool isTopLevel () const
 
bool initialized () const
 
std::string const & className () const
 
std::string const & instanceName () const
 
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 
getParamValUnique (std::string const &paramdescriptor) const
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 
void freezeParam (std::string const &paramdescriptor)
 
void unFreezeParam (std::string const &paramdescriptor)
 
void freezeAllParams ()
 
void unFreezeAllParams ()
 
std::string descriptor () const
 
void setParamsFromFile (std::string const &filename)
 
std::istream & setParamsFromStream (std::istream &is, std::string const &absfile)
 
void setPath (std::string const &path)
 
std::string absolutePath (std::string const &path="")
 
std::shared_ptr< Comp > addSubComponent (std::string const &instance, Args &&...args)
 
void removeSubComponent (std::shared_ptr< Comp > &component)
 
void removeSubComponent (std::string const &instance, bool warnIfNotFound=true)
 
std::shared_ptr< Comp > getSubComponent (std::string const &instance) const
 
bool isTopLevel () const
 
bool initialized () const
 
std::string const & className () const
 
std::string const & instanceName () const
 
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 
getParamValUnique (std::string const &paramdescriptor) const
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 
void freezeParam (std::string const &paramdescriptor)
 
void unFreezeParam (std::string const &paramdescriptor)
 
void freezeAllParams ()
 
void unFreezeAllParams ()
 
std::string descriptor () const
 
void setParamsFromFile (std::string const &filename)
 
std::istream & setParamsFromStream (std::istream &is, std::string const &absfile)
 
void setPath (std::string const &path)
 
std::string absolutePath (std::string const &path="")
 
- Public Member Functions inherited from jevois::ParameterRegistry
virtual ~ParameterRegistry ()
 

Related Functions

(Note that these are not member functions.)

 JEVOIS_DECLARE_PARAMETER (hrange, jevois::Range< unsigned char >,"Range of H values for HSV window", jevois::Range< unsigned char >(10, 245), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (srange, jevois::Range< unsigned char >,"Range of S values for HSV window", jevois::Range< unsigned char >(10, 245), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (vrange, jevois::Range< unsigned char >,"Range of V values for HSV window", jevois::Range< unsigned char >(10, 245), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (maxnumobj, size_t,"Max number of objects to declare a clean image", 10, ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (objectarea, jevois::Range< unsigned int >,"Range of object area (in pixels) to track", jevois::Range< unsigned int >(20 *20, 100 *100), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (erodesize, size_t,"Erosion structuring element size (pixels)", 3, ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (dilatesize, size_t,"Dilation structuring element size (pixels)", 8, ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (debug, bool,"Show contours of all object candidates if true", true, ParamCateg)
 Parameter. More...
 

Additional Inherited Members

- Protected Member Functions inherited from jevois::Component
virtual void preInit ()
 
virtual void postInit ()
 
virtual void preUninit ()
 
virtual void postUninit ()
 
virtual void preInit ()
 
virtual void postInit ()
 
virtual void preUninit ()
 
virtual void postUninit ()
 
- Protected Member Functions inherited from jevois::ParameterRegistry
void addParameter (ParameterBase *const param)
 
void removeParameter (ParameterBase *const param)
 
void callbackInitCall ()
 

Detailed Description

Simple color-based object detection/tracking.

This modules isolates pixels within a given HSV range (hue, saturation, and value of color pixels), does some cleanups, and extracts object contrours. It sends information about object centers over serial. This module usually works best with the camera sensor set to manual exposure, gain, color balance, etc so that HSV color values are reliable. See the cript.cfg file in this module's directory for an example of how to set the camera settigs each time this module is loaded.

This code was loosely inspired by: https://raw.githubusercontent.com/kylehounslow/opencv-tuts/master/object-tracking-tut/objectTrackingTut.cpp written by Kyle Hounslow, 2013.

Serial output

This module sends serial messages of the form

T2D x y

where x and y are the standardized coordinates of the center of each detected and good object (good objects have a pixel area within the range specified by objectarea, and are only reported when the image is clean enough according to maxnumobj. See Helper functions to convert coordinates from camera resolution to standardized for standardized coordinates. One message is sent for every good object on every frame.

Trying it out

The default parameter settings (which are set in script.cfg explained below) attempt to detect light blue objects. Present a light blue object to the JeVois camera and see whether it is detected. When detected and good enough according to objectarea and maxnumobj, a green circle will be drawn at the center of each good object.

Tuning

You should adjust parameters hrange, srange, and vrange to isolate the range of Hue, Saturation, and Value (respectively) that correspond to the objects you want to detect. Note that there is a params.cfg file in this module's directory that provides a range tuned to a lighgt blue object, as shown in the demo screenshot.

Tuning the parameters is best done interactively by connecting to your JeVois camera while it is looking at some object of the desired color. Once you have achieved a tuning, you may want to set the hrange, srange, and vrange parameters in your script.cfg file for this module on the microSD card (see below).

Typically, you would start by narrowing down on the hue, then the value, and finally the saturation. Make sure you also move your camera around and show it typical background clutter so check for false positives (detections of things which you are not interested, which can happen if your ranges are too wide).

Config file

JeVois allows you to store parameter settings and commands in a file named script.cfg stored in the directory of a module. The file script.cfg may contain any sequence of commands as you would type them interactively in the JeVois command-line interface. For the ObjectTracker module, a default script is provided that sets the camera to manual color, gain, and exposure mode (for more reliable color values), and to setup communication with a pan/tilt head as described in Tutorial on how to write Arduino code that interacts with JeVois.

The script.cfg file for ObjectTracker is stored on your microSD at JEVOIS:/modules/JeVois/ObjectTracker/script.cfg and is shown in Tutorial on how to write Arduino code that interacts with JeVois as an example.

Author
Laurent Itti
Videomapping:
YUYV 320 254 60.0 YUYV 320 240 60.0 JeVois ObjectTracker
Videomapping:
NONE 0 0 0.0 YUYV 320 240 60.0 JeVois ObjectTracker
Email:
itti@usc.edu
Address:
University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
Main URL:
http://jevois.org
Support URL:
http://jevois.org/doc
Other URL:
http://iLab.usc.edu
License:
GPL v3
Distribution:
Unrestricted
Restrictions:
None

Definition at line 160 of file ObjectTracker.C.

Constructor & Destructor Documentation

virtual ObjectTracker::~ObjectTracker ( )
inlinevirtual

Virtual destructor for safe inheritance.

Definition at line 169 of file ObjectTracker.C.

Member Function Documentation

virtual void ObjectTracker::process ( jevois::InputFrame &&  inframe)
inlineoverridevirtual

Friends And Related Function Documentation

JEVOIS_DECLARE_PARAMETER ( hrange  ,
jevois::Range< unsigned char >  ,
"Range of H values for HSV window"  ,
jevois::Range< unsigned char >  10, 245,
ParamCateg   
)
related

Parameter.

JEVOIS_DECLARE_PARAMETER ( srange  ,
jevois::Range< unsigned char >  ,
"Range of S values for HSV window"  ,
jevois::Range< unsigned char >  10, 245,
ParamCateg   
)
related

Parameter.

JEVOIS_DECLARE_PARAMETER ( vrange  ,
jevois::Range< unsigned char >  ,
"Range of V values for HSV window"  ,
jevois::Range< unsigned char >  10, 245,
ParamCateg   
)
related

Parameter.

JEVOIS_DECLARE_PARAMETER ( maxnumobj  ,
size_t  ,
"Max number of objects to declare a clean image"  ,
10  ,
ParamCateg   
)
related

Parameter.

JEVOIS_DECLARE_PARAMETER ( objectarea  ,
jevois::Range< unsigned int >  ,
"Range of object area (in pixels) to track"  ,
jevois::Range< unsigned int >  20 *20, 100 *100,
ParamCateg   
)
related

Parameter.

JEVOIS_DECLARE_PARAMETER ( erodesize  ,
size_t  ,
"Erosion structuring element size (pixels)"  ,
,
ParamCateg   
)
related

Parameter.

JEVOIS_DECLARE_PARAMETER ( dilatesize  ,
size_t  ,
"Dilation structuring element size (pixels)"  ,
,
ParamCateg   
)
related

Parameter.

JEVOIS_DECLARE_PARAMETER ( debug  ,
bool  ,
"Show contours of all object candidates if true"  ,
true  ,
ParamCateg   
)
related

Parameter.


The documentation for this class was generated from the following file: