27#include <QDirIterator> 
   28#include <QElapsedTimer> 
   34#include <QProgressBar> 
   35#include <QRandomGenerator> 
   36#include <QSharedPointer> 
   37#include <QSqlDatabase> 
   48#include <opencv2/calib3d.hpp> 
   49#include <opencv2/core/types.hpp> 
   50#include <opencv2/highgui/highgui.hpp> 
   51#include <opencv2/imgproc/imgproc.hpp> 
   52#include <opencv2/video/tracking.hpp> 
   57#include "opencv2/features2d/features2d.hpp" 
   58#include "videoreader.h" 
   63class Tracking : 
public QObject {
 
   91  explicit Tracking(QWidget *parent = 
nullptr) : QObject(parent){};
 
   92  Tracking(
const string &path, 
const string &background, 
int startImage = 0, 
int stopImage = -1);
 
   93  Tracking(
const string &path, 
const UMat &background, 
int startImage = 0, 
int stopImage = -1);
 
  100  const QString connectionName;
 
  101  Point2d 
curvatureCenter(
const Point3d &tail, 
const Point3d &head) 
const;
 
  102  double curvature(Point2d center, 
const Mat &image) 
const;
 
  103  double divide(
double a, 
double b) 
const;
 
  104  bool objectDirection(
const UMat &image, vector<double> &information) 
const;
 
  106  vector<Point3d> 
reassignment(
const vector<Point3d> &past, 
const vector<Point3d> &input, 
const vector<int> &assignment) 
const;
 
  107  vector<vector<Point3d>> 
objectPosition(
const UMat &frame, 
int minSize, 
int maxSize) 
const;
 
  108  vector<int> 
costFunc(
const vector<vector<Point3d>> &prevPos, 
const vector<vector<Point3d>> &pos, 
double LENGHT, 
double ANGLE, 
double LO, 
double AREA, 
double PERIMETER) 
const;
 
  109  void cleaning(
const vector<int> &occluded, vector<int> &lostCounter, vector<int> &
id, vector<vector<Point3d>> &input, 
double param_maximalTime) 
const;
 
  110  vector<Point3d> 
prevision(vector<Point3d> past, vector<Point3d> present) 
const;
 
  112  static double modul(
double angle);
 
  115  static void registration(UMat imageReference, UMat &frame, 
int method);
 
  116  static void binarisation(UMat &frame, 
char backgroundColor, 
int value);
 
 
This class is intended to execute a tracking analysis on an image sequence. It is initialized with th...
Definition tracking.h:63
virtual void startProcess()
Initializes a tracking analysis and triggers its execution. Constructs from the path to a folder wher...
Definition tracking.cpp:813
static double modul(double angle)
Computes the usual mathematical modulo 2*PI of an angle.
Definition tracking.cpp:109
static bool importTrackingResult(const QString &path, QSqlDatabase db)
Imports the tracking data from a text file to the database.
Definition tracking.cpp:1021
void statistic(long long int time)
Emitted at the end of the analysis.
int m_startImage
Definition tracking.h:79
~Tracking()
Destructs the tracking object.
Definition tracking.cpp:978
void finished()
Emitted when all images have been processed.
string m_path
Definition tracking.h:70
UMat m_background
Definition tracking.h:72
vector< int > m_lost
Definition tracking.h:85
vector< vector< Point3d > > objectPosition(const UMat &frame, int minSize, int maxSize) const
Computes the positions of the objects and extracts the object's features.
Definition tracking.cpp:377
double curvature(Point2d center, const Mat &image) const
Computes the radius of curvature of the object defined as the inverse of the mean distance between ea...
Definition tracking.cpp:90
bool m_isMorph
Definition tracking.h:87
int m_displayTime
Definition tracking.h:73
static UMat backgroundExtraction(VideoReader &video, int n, const int method, const int registrationMethod)
Computes the background of an image sequence by averaging n images.
Definition tracking.cpp:214
int m_im
Definition tracking.h:77
vector< vector< Point3d > > m_outPrev
Definition tracking.h:122
QFile m_logFile
Definition tracking.h:82
void forceFinished(QString message)
Emitted when a crash occurs during the analysis.
vector< cv::String > m_files
Definition tracking.h:83
UMat m_binaryFrame
Definition tracking.h:120
static void registration(UMat imageReference, UMat &frame, int method)
Register two images. To speed-up, the registration is made in a pyramidal way: the images are downsam...
Definition tracking.cpp:287
int m_stopImage
Definition tracking.h:80
vector< Point3d > prevision(vector< Point3d > past, vector< Point3d > present) const
Predicts the next position of an object from the previous position.
Definition tracking.cpp:655
vector< int > costFunc(const vector< vector< Point3d > > &prevPos, const vector< vector< Point3d > > &pos, double LENGHT, double ANGLE, double LO, double AREA, double PERIMETER) const
Computes a cost function and use a global optimization association to associate targets between image...
Definition tracking.cpp:515
static double angleDifference(double alpha, double beta)
Computes the least difference between two angles, alpha - beta. The difference is oriented in the tri...
Definition tracking.cpp:134
vector< Point3d > reassignment(const vector< Point3d > &past, const vector< Point3d > &input, const vector< int > &assignment) const
Sorts a vector accordingly to a new set of indexes. The sorted vector at index i is the input at inde...
Definition tracking.cpp:590
Point2d curvatureCenter(const Point3d &tail, const Point3d &head) const
Computes the center of the curvature, defined as the intersection of the minor axis of the head ellip...
Definition tracking.cpp:47
vector< int > m_id
Definition tracking.h:84
static void binarisation(UMat &frame, char backgroundColor, int value)
Binarizes the image by thresholding.
Definition tracking.cpp:358
vector< double > objectInformation(const UMat &image) const
Computes the equivalent ellipse of an object by computing the moments of the image....
Definition tracking.cpp:146
virtual void imageProcessing()
Processes an image from an images sequence and tracks and matchs objects according to the previous im...
Definition tracking.cpp:676
void progress(int)
Emitted when an image is processed.
static bool exportTrackingResult(const QString &path, const QSqlDatabase &db)
Exports the tracking data from the database to a text file.
Definition tracking.cpp:988
bool m_statusBinarisation
Definition tracking.h:68
QString m_savingPath
Definition tracking.h:74
string m_backgroundPath
Definition tracking.h:71
Rect m_ROI
Definition tracking.h:81
bool objectDirection(const UMat &image, vector< double > &information) const
Computes the direction of the object from the object parameter (coordinate of the center of mass and ...
Definition tracking.cpp:175
vector< int > findOcclusion(vector< int > assignment) const
Finds the objects that are occluded during the tracking.
Definition tracking.cpp:571
double divide(double a, double b) const
Computes the float division and handle the division by 0 by returning 0.
Definition tracking.cpp:119
QString m_error
Definition tracking.h:78
void cleaning(const vector< int > &occluded, vector< int > &lostCounter, vector< int > &id, vector< vector< Point3d > > &input, double param_maximalTime) const
Cleans the data if an object is lost more than a certain time.
Definition tracking.cpp:627
QHash< QString, QString > m_parameters
Definition tracking.h:88
void updatingParameters(const QHash< QString, QString > &)
Updates the private members from the external parameters. This function links the tracking logic with...
Definition tracking.cpp:966
void backgroundProgress(int)
Emitted when an image to compute the background is processed.
vector< vector< Point3d > > m_out
Definition tracking.h:121
void finishedProcessFrame()
Emitted when the first image has been processed to trigger the starting of the analysis.
QSharedPointer< QElapsedTimer > m_timer
Definition tracking.h:66
This class is intended to abstract the opening of a video, it can load image sequence and video with ...
Definition videoreader.h:36