FastTrack
5.0.0
Tracks multiples objects dealing with occlusion and identities.

This class is intended to execute a tracking analysis on an image sequence. It is initialized with the path to the folder where images are stored. This class can be used inside an application by creating a new thread and calling the method startProcess. The tracking workflow can be changed by reimplementing the method startProcess and imageProcessing. This class can also be used as a library by constructing Tracking tracking("", "") to access the public class members and builds a new workflow. More...
Public Slots  
void  startProcess () 
Initializes a tracking analysis and triggers its execution. Constructs from the path to a folder where the image sequence is stored, detects the image format and processes the first image to detect objects. First, it computes the background by averaging images from the sequence, then it subtracts the background from the first image and then binarizes the resulting image. It detects the objects by contour analysis and extracts features by computing the object moments. It triggers the analysis of the second image of the sequence.  
void  updatingParameters (const QMap< QString, QString > &) 
Updates the private members from the external parameters. This function links the tracking logic with the graphical user interface. More...  
void  imageProcessing () 
Processes an image from an images sequence and tracks and matchs objects according to the previous image in the sequence. Takes a new image from the image sequence, substracts the background, binarises the image and crops according to the defined region of interest. Detects all the objects in the image and extracts the object features. Then matches detected objects with objects from the previous frame. This function emits a signal to display the images in the user interface.  
Signals  
void  progress (int) 
Emitted when an image is processed. More...  
void  backgroundProgress (int) 
Emitted when an image to compute the background is processed. More...  
void  finishedProcessFrame () 
Emitted when the first image has been processed to trigger the starting of the analysis.  
void  finished () 
Emitted when all images have been processed.  
void  forceFinished (QString message) 
Emitted when a crash occurs during the analysis.  
void  error (int code) 
Emitted when an error occurs.  
void  statistic (long long int time) 
Emitted at the end of the analysis.  
Public Member Functions  
Tracking (string path, string background, int startImage=0, int stopImage=1)  
Constructs the tracking object from a path to an image sequence and an optional path to a background image. More...  
Tracking (string path, UMat background, int startImage=0, int stopImage=1)  
Constructs the tracking object from a list of path, a background image and a range of image. More...  
~Tracking ()  
Destructs the tracking object.  
Point2d  curvatureCenter (const Point3d &tail, const Point3d &head) 
Computes the center of the curvature, defined as the intersection of the minor axis of the head ellipse with the minor axis of the tail ellipse of the object. More...  
double  curvature (Point2d center, const Mat &image) 
Computes the radius of curvature of the object defined as the inverse of the mean distance between each pixel of the object, and the center of the curvature. The center of curvature is defined as the intersection of the two minor axes of the head and tail ellipse. More...  
double  divide (double a, double b) 
Computes the float division and handle the division by 0 by returning 0. More...  
bool  objectDirection (const UMat &image, vector< double > &information) 
Computes the direction of the object from the object parameter (coordinate of the center of mass and orientation). To use this function, the object major axis has to be the horizontal axis of the image. Therefore, it is necessary to rotate the image before calling objectDirection. More...  
vector< double >  objectInformation (const UMat &image) 
Computes the equivalent ellipse of an object by computing the moments of the image. If the image is a circle, return nan as the orientation. More...  
vector< Point3d >  reassignment (const vector< Point3d > &past, const vector< Point3d > &input, const vector< int > &assignment) 
Sorts a vector accordingly to a new set of indexes. The sorted vector at index i is the input at index assignment[i]. More...  
UMat  backgroundExtraction (VideoReader &video, int n, const int method, const int registrationMethod) 
Computes the background of an image sequence by averaging n images. More...  
void  registration (UMat imageReference, UMat &frame, int method) 
Register two images. To speedup, the registration is made in a pyramidal way: the images are downsampled then registered to have a an approximate transformation then upslampled to have the precise transformation. More...  
void  binarisation (UMat &frame, char backgroundColor, int value) 
Binarizes the image by thresholding. More...  
vector< vector< Point3d > >  objectPosition (const UMat &frame, int minSize, int maxSize) 
Computes the positions of the objects and extracts the object's features. More...  
vector< int >  costFunc (const vector< vector< Point3d >> &prevPos, const vector< vector< Point3d >> &pos, double LENGHT, double ANGLE, double LO, double AREA, double PERIMETER) 
Computes a cost function and use a global optimization association to associate targets between images. Method adapted from: "An effective and robust method for Tracking multiple fish in video image based on fish head detection" YQ Chen et al. Uses the Hungarian method implemented by Cong Ma, 2016 "https://github.com/mcximing/hungarianalgorithmcpp" adapted from the Matlab implementation by Markus Buehren "https://fr.mathworks.com/matlabcentral/fileexchange/6543functionsfortherectangularassignmentproblem". More...  
void  cleaning (const vector< int > &occluded, vector< int > &lostCounter, vector< int > &id, vector< vector< Point3d >> &input, double param_maximalTime) 
Cleans the data if an object is lost more than a certain time. More...  
vector< Point3d >  prevision (vector< Point3d > past, vector< Point3d > present) 
Predicts the next position of an object from the previous position. More...  
vector< Point3i >  color (int number) 
Computes a random set of colors. More...  
vector< int >  findOcclusion (vector< int > assignment) 
Finds the objects that are occluded during the tracking. More...  
Static Public Member Functions  
static double  modul (double angle) 
Computes the usual mathematical modulo 2*PI of an angle. More...  
static double  angleDifference (double alpha, double beta) 
Computes the least difference between two angles, alpha  beta. The difference is oriented in the trigonometric convention. More...  
Public Attributes  
UMat  m_binaryFrame 
UMat  m_visuFrame 
vector< vector< Point3d > >  m_out 
vector< vector< Point3d > >  m_outPrev 
Private Attributes  
QElapsedTimer *  timer 
UMat  m_background 
bool  statusBinarisation 
VideoReader *  video 
int  m_im 
QString  m_error 
int  m_startImage 
int  m_stopImage 
Rect  m_ROI 
QTextStream  m_savefile 
QFile  m_outputFile 
QFile  m_logFile 
vector< cv::String >  m_files 
vector< Point3i >  m_colorMap 
vector< vector< Point > >  m_memory 
vector< int >  m_id 
vector< int >  m_lost 
int  m_idMax 
string  m_path 
string  m_backgroundPath 
int  m_displayTime 
int  param_n 
int  param_maxArea 
int  param_minArea 
int  param_spot 
double  param_len 
double  param_angle 
double  param_area 
double  param_perimeter 
double  param_lo 
double  param_to 
int  param_thresh 
double  param_nBackground 
int  param_methodBackground 
int  param_methodRegistrationBackground 
int  param_registration 
int  param_x1 
int  param_y1 
int  param_x2 
int  param_y2 
int  param_kernelSize 
int  param_kernelType 
int  param_morphOperation 
QMap< QString, QString >  parameters 
This class is intended to execute a tracking analysis on an image sequence. It is initialized with the path to the folder where images are stored. This class can be used inside an application by creating a new thread and calling the method startProcess. The tracking workflow can be changed by reimplementing the method startProcess and imageProcessing. This class can also be used as a library by constructing Tracking tracking("", "") to access the public class members and builds a new workflow.
Contact: gallo is.b enjam in08 @gmai l.co m
Tracking::Tracking  (  string  path, 
string  backgroundPath,  
int  startImage = 0 , 

int  stopImage = 1 

) 
Constructs the tracking object from a path to an image sequence and an optional path to a background image.
[in]  path  The path to a folder where images are stocked. 
[in]  backgroundPath  The path to a background image. 
[in]  startImage  Index of the beginning image. 
[in]  stopImage  Index of the ending image. 
Tracking::Tracking  (  string  path, 
UMat  background,  
int  startImage = 0 , 

int  stopImage = 1 

) 
Constructs the tracking object from a list of path, a background image and a range of image.
[in]  imagePath  List of path to the images. 
[in]  background  A background image. 
[in]  startImage  Index of the beginning image. 
[in]  stopImage  Index of the ending image. 

static 
Computes the least difference between two angles, alpha  beta. The difference is oriented in the trigonometric convention.
[in]  alpha  Input angle. 
[in]  beta  Input angle. 
UMat Tracking::backgroundExtraction  (  VideoReader &  video, 
int  n,  
const int  method,  
const int  registrationMethod  
) 
Computes the background of an image sequence by averaging n images.
[in]  files  List of paths to each image in the images sequence. 
[in]  n  The number of images to average to computes the background. 
[in]  Method  0: minimal projection, 1: maximal projection, 2: average projection. 

signal 
Emitted when an image to compute the background is processed.
int  The number of processed image. 
void Tracking::binarisation  (  UMat &  frame, 
char  backgroundColor,  
int  value  
) 
Binarizes the image by thresholding.
[in,out]  frame  The image to binarize. 
[in]  backgroundColor  If equals to 'w' the thresholded image will be inverted, if equal to 'b' it will not be inverted. 
[in]  value  The value at which to threshold the image. 
void Tracking::cleaning  (  const vector< int > &  occluded, 
vector< int > &  lostCounter,  
vector< int > &  id,  
vector< vector< Point3d >> &  input,  
double  param_maximalTime  
) 
Cleans the data if an object is lost more than a certain time.
[in]  occluded  The vector with the index of object missing in the current image. 
[in]  input  The vector at current image of size m <= n to be sorted. 
[in]  lostCounter  The vector with the number of times each objects are lost consecutively. 
[in]  id  The vector with the id of the objects. 
[in]  param_maximalTime 
vector< Point3i > Tracking::color  (  int  number  ) 
Computes a random set of colors.
[in]  number  The number of colors to generate. 
vector< int > Tracking::costFunc  (  const vector< vector< Point3d >> &  prevPos, 
const vector< vector< Point3d >> &  pos,  
double  LENGTH,  
double  ANGLE,  
double  LO,  
double  AREA,  
double  PERIMETER  
) 
Computes a cost function and use a global optimization association to associate targets between images. Method adapted from: "An effective and robust method for Tracking multiple fish in video image based on fish head detection" YQ Chen et al. Uses the Hungarian method implemented by Cong Ma, 2016 "https://github.com/mcximing/hungarianalgorithmcpp" adapted from the Matlab implementation by Markus Buehren "https://fr.mathworks.com/matlabcentral/fileexchange/6543functionsfortherectangularassignmentproblem".
[in]  prevPos  The vector of objects parameters at the previous image. 
[in]  pos  The vector of objects parameters at the current image that we want to sort in order to conserve objects identity. 
[in]  LENGTH  The typical displacement of an object in pixels. 
[in]  ANGLE  The typical reorientation angle in radians. 
[in]  LO  The maximal assignment distance in pixels. 
double Tracking::curvature  (  Point2d  center, 
const Mat &  image  
) 
Computes the radius of curvature of the object defined as the inverse of the mean distance between each pixel of the object, and the center of the curvature. The center of curvature is defined as the intersection of the two minor axes of the head and tail ellipse.
[in]  center  Center of the curvature. 
[in]  image  Binary image CV_8U. 
Point2d Tracking::curvatureCenter  (  const Point3d &  tail, 
const Point3d &  head  
) 
Computes the center of the curvature, defined as the intersection of the minor axis of the head ellipse with the minor axis of the tail ellipse of the object.
[in]  tail  The parameters of the tail ellipse: coordinate and direction of the major axis. 
[in]  head  The parameters of the head ellipse: coordinate and direction of the major axis. 
double Tracking::divide  (  double  a, 
double  b  
) 
Computes the float division and handle the division by 0 by returning 0.
[in]  a  Dividend. 
[in]  a  Divisor. 
vector< int > Tracking::findOcclusion  (  vector< int >  assignment  ) 
Finds the objects that are occluded during the tracking.
[in]  assignment  The vector with the new indexes that will be used to sort the input vector. 

static 
Computes the usual mathematical modulo 2*PI of an angle.
[in]  angle  Input angle. 
bool Tracking::objectDirection  (  const UMat &  image, 
vector< double > &  information  
) 
Computes the direction of the object from the object parameter (coordinate of the center of mass and orientation). To use this function, the object major axis has to be the horizontal axis of the image. Therefore, it is necessary to rotate the image before calling objectDirection.
[in]  image  Binary image CV_8U. 
[in,out]  information  The parameters of the object (x coordinate, y coordinate, orientation). 
vector< double > Tracking::objectInformation  (  const UMat &  image  ) 
Computes the equivalent ellipse of an object by computing the moments of the image. If the image is a circle, return nan as the orientation.
[in]  image  Binary image CV_8U. 
vector< vector< Point3d > > Tracking::objectPosition  (  const UMat &  frame, 
int  minSize,  
int  maxSize  
) 
Computes the positions of the objects and extracts the object's features.
[in]  frame  Binary image CV_8U. 
[in]  minSize  The minimal size of an object. 
[in]  maxSize  The maximal size of an object. 
vector< Point3d > Tracking::prevision  (  vector< Point3d >  past, 
vector< Point3d >  present  
) 
Predicts the next position of an object from the previous position.
past  The previous position parameters. 
present  The current position parameters. 

signal 
Emitted when an image is processed.
int  Index of the processed image. 
vector< Point3d > Tracking::reassignment  (  const vector< Point3d > &  past, 
const vector< Point3d > &  input,  
const vector< int > &  assignment  
) 
Sorts a vector accordingly to a new set of indexes. The sorted vector at index i is the input at index assignment[i].
[in]  past  The vector at the previous image. 
[in]  input  The vector at current image of size m <= n to be sorted. 
[in]  assignment  The vector with the new indexes that will be used to sort the input vector. 
[in]  lostCounter  The vector with the number of times each objects are lost consecutively. 
[in]  id  The vector with the id of the objects. 
void Tracking::registration  (  UMat  imageReference, 
UMat &  frame,  
int  method  
) 
Register two images. To speedup, the registration is made in a pyramidal way: the images are downsampled then registered to have a an approximate transformation then upslampled to have the precise transformation.
[in]  imageReference  The reference image for the registration. 
[in,out]  frame  The image to register. 
[in]  method  The method of registration: 0 = simple (phase correlation), 1 = ECC, 2 = Features based. 

slot 
Updates the private members from the external parameters. This function links the tracking logic with the graphical user interface.
[in]  parameterList  The list of all the parameters used in the tracking. 

private 
Background image CV_8U.

private 
Path to an image background.
UMat Tracking::m_binaryFrame 
Binary image CV_8U

private 
Vector containing RBG color.

private 
Binary image CV_8U.

private 
QString containing unreadable images.

private 
Vector containing the path for each image in the images sequence.

private 
Vector containing the objets Id.

private 
Index of the next image to process in the m_files list.

private 
Path to the file where to save logs.

private 
Vector containing the lost objects.

private 
Vector containing the last 50 tracking data.
vector<vector<Point3d> > Tracking::m_out 
Objects information at iteration minus one
vector<vector<Point3d> > Tracking::m_outPrev 
Objects information at current iteration

private 
Path to the file where to save tracking data.

private 
Path to an image sequence.

private 
Rectangular region of interest.

private 
Stream to output tracking data.

private 
Index of the next image to process in the m_files list.

private 
Index of the next image to process in the m_files list.
UMat Tracking::m_visuFrame 
Image 8 bit CV_8U

private 
Maximal change in direction of an object between two images.

private 
Normalization area.

private 
Size of the kernel of the morphological operation.

private 
Type of the kernel of the morphological operation.

private 
Maximal length travelled by an object between two images.

private 
Maximal distance allowed by an object to travel during an occlusion event.

private 
Maximal area of an object.

private 
The method used to compute the background.

private 
The method used to register the images for the background.

private 
Minimal area of an object.

private 
Type of the morphological operation.

private 
Number of objects.

private 
Number of images to average to compute the background.

private 
Normalization perimeter.

private 
Method of registration.

private 
Which spot parameters are used to computes the cost function. 0: head, 1: tail, 2: body.

private 
Value of the threshold to binarize the image.

private 
Maximal time.

private 
Top x corner of the region of interest.

private 
Bottom x corner of the region of interest.

private 
Top y corner of the region of interest.

private 
Bottom y corner of the region of interest.

private 
map of all the parameters for the tracking.

private 
True if wite objects on dark background, flase otherwise.

private 
Timer that measured the time during the analysis execution.