JeVoisBase  1.5
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
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::StdModule
 StdModule (std::string const &instance)
 
virtual ~StdModule ()
 
void sendSerialImg1Dx (unsigned int camw, float x, float size=0.0F, std::string const &id="", std::string const &extra="")
 
void sendSerialStd1Dx (float x, float size=0.0F, std::string const &id="", std::string const &extra="")
 
void sendSerialImg1Dy (unsigned int camh, float y, float size=0.0F, std::string const &id="", std::string const &extra="")
 
void sendSerialStd1Dy (float y, float size=0.0F, std::string const &id="", std::string const &extra="")
 
void sendSerialImg2D (unsigned int camw, unsigned int camh, float x, float y, float w=0.0F, float h=0.0F, std::string const &id="", std::string const &extra="")
 
void sendSerialStd2D (float x, float y, float w=0.0F, float h=0.0F, std::string const &id="", std::string const &extra="")
 
void sendSerialContour2D (unsigned int camw, unsigned int camh, std::vector< cv::Point_< T > > points, std::string const &id="", std::string const &extra="")
 
void sendSerialStd3D (float x, float y, float z, float w=0.0F, float h=0.0F, float d=0.0F, float q1=0.0F, float q2=0.0F, float q3=0.0f, float q4=0.0F, std::string const &id="", std::string const &extra="")
 
void sendSerialStd3D (std::vector< cv::Point3f > points, std::string const &id="", std::string const &extra="")
 
- 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)
 
 JEVOIS_DEFINE_ENUM_CLASS (SerStyle,(Terse)(Normal)(Detail)(Fine)) JEVOIS_DECLARE_PARAMETER(serstyle
 
 JEVOIS_DECLARE_PARAMETER (serprec, unsigned int, "Number of decimal points in standardized serial messages as " "defined in http://jevois.org/doc/UserSerialStyle.html", 0U, ParamCateg)
 
- 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 Messages

This module can send standardized serial messages as described in Standardized serial messages formatting. One message is issued for on every video frame for 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). The id field in the messages simply is blob for all messages.

  • Serial message type: 2D
  • id: always blob
  • x, y, or vertices: standardized 2D coordinates of blob center or of corners of bounding box (depending on serstyle)
  • w, h: standardized object size
  • extra: none (empty string)

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 161 of file ObjectTracker.C.

Constructor & Destructor Documentation

◆ ~ObjectTracker()

virtual ObjectTracker::~ObjectTracker ( )
inlinevirtual

Virtual destructor for safe inheritance.

Definition at line 170 of file ObjectTracker.C.

Member Function Documentation

◆ process() [1/2]

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

Processing function, no USB video output.

Reimplemented from jevois::Module.

Definition at line 173 of file ObjectTracker.C.

References area(), jevois::rawimage::convertToCvBGR(), jevois::RawImage::height, jevois::StdModule::sendSerialContour2D(), and jevois::RawImage::width.

◆ process() [2/2]

Friends And Related Function Documentation

◆ JEVOIS_DECLARE_PARAMETER() [1/8]

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() [2/8]

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() [3/8]

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() [4/8]

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

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [5/8]

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() [6/8]

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

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [7/8]

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

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [8/8]

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: