Object Tracker
Simple color-based object detection/tracking.
By Laurent Ittiitti@usc.eduhttp://jevois.orgGPL v3
 Language:   C++            Supports mappings with USB output:   Yes            Supports mappings with NO USB output:   Yes
 Video Mapping:   YUYV 320 254 60.0 YUYV 320 240 60.0 JeVois ObjectTracker
 Video Mapping:   NONE 0 0 0.0 YUYV 320 240 60.0 JeVois ObjectTracker

Module Documentation

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.


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.

ParameterTypeDescriptionDefaultValid Values
(ObjectTracker) hrangejevois::Range<unsigned char>Range of H values for HSV windowjevois::Range<unsigned char>(10, 245)-
(ObjectTracker) srangejevois::Range<unsigned char>Range of S values for HSV windowjevois::Range<unsigned char>(10, 245)-
(ObjectTracker) vrangejevois::Range<unsigned char>Range of V values for HSV windowjevois::Range<unsigned char>(10, 245)-
(ObjectTracker) maxnumobjsize_tMax number of objects to declare a clean image10-
(ObjectTracker) objectareajevois::Range<unsigned int>Range of object area (in pixels) to trackjevois::Range<unsigned int>(20*20, 100*100)-
(ObjectTracker) erodesizesize_tErosion structuring element size (pixels)3-
(ObjectTracker) dilatesizesize_tDilation structuring element size (pixels)8-
(ObjectTracker) debugboolShow contours of all object candidates if truetrue-
script.cfg file
# Demo configuration script for ObjectTracker module.

# Set camera to fixed color balance, gain, and exposure, so that we get more reliable colors than we would obtain under
# automatic mode:
setcam autowb 0
setcam autogain 0
setcam autoexp 0
setcam redbal 110
setcam bluebal 170
setcam gain 16
setcam absexp 500

# Detect a light blue flash drive:
setpar hrange 95...110
setpar srange 100...255
setpar vrange 60...253

# Send info log messages to None, send serial strings from module to Hard serial port:
setpar serlog None
setpar serout Hard

# Apply high gain to our pan/tilt servos, sending the commands below to our Arduino over the Hard serial port that we
# configured above to handle the serout messages. The Arduino controlling the pan/tilt servos will receive and parse
# these commands, and will set the servo gains:
serout PANGAIN 400
serout TILTGAIN 300
Detailed docs:ObjectTracker
Copyright:Copyright (C) 2016 by Laurent Itti, iLab and the University of Southern California
License:GPL v3
Support URL:http://jevois.org/doc
Other URL:http://iLab.usc.edu
Address:University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA