FastTrack  5.0.0
Tracks multiples objects dealing with occlusion and identities.
tracking.h
1 /*
2 This file is part of Fast Track.
3 
4  FastTrack is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  FastTrack is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with FastTrack. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef TRACKING_H
19 #define TRACKING_H
20 #include <math.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <time.h>
24 #include <QDate>
25 #include <QDebug>
26 #include <QDir>
27 #include <QDirIterator>
28 #include <QElapsedTimer>
29 #include <QFile>
30 #include <QFileInfo>
31 #include <QList>
32 #include <QMap>
33 #include <QMessageBox>
34 #include <QObject>
35 #include <QString>
36 #include <QTextStream>
37 #include <QThread>
38 #include <QTimer>
39 #include <QVector>
40 #include <algorithm>
41 #include <fstream>
42 #include <iostream>
43 #include <numeric>
44 #include <opencv2/calib3d.hpp>
45 #include <opencv2/core/types.hpp>
46 #include <opencv2/highgui/highgui.hpp>
47 #include <opencv2/imgproc/imgproc.hpp>
48 #include <opencv2/video/tracking.hpp>
49 #include <string>
50 #include <tuple>
51 #include <utility>
52 #include "opencv2/features2d/features2d.hpp"
53 #include "videoreader.h"
54 
55 using namespace cv;
56 using namespace std;
57 
58 class Tracking : public QObject {
59  Q_OBJECT
60 
61  QElapsedTimer *timer;
63  UMat m_background;
67  VideoReader *video;
68  int m_im;
69  QString m_error;
72  Rect m_ROI;
73  QTextStream m_savefile;
74  QFile m_outputFile;
75  QFile m_logFile;
76  vector<cv::String> m_files;
77  vector<Point3i> m_colorMap;
78  vector<vector<Point>> m_memory;
79  vector<int> m_id;
80  vector<int> m_lost;
81  int m_idMax;
82 
83  string m_path;
87  int param_n;
90  int param_spot;
91  double param_len;
92  double param_angle;
93  double param_area;
94  double param_perimeter;
95  double param_lo;
96  double param_to;
102  int param_x1;
103  int param_y1;
104  int param_x2;
105  int param_y2;
109  QMap<QString, QString> parameters;
111  public:
112  Tracking(string path, string background, int startImage = 0, int stopImage = -1);
113  Tracking(string path, UMat background, int startImage = 0, int stopImage = -1);
114  ~Tracking();
115 
116  Point2d curvatureCenter(const Point3d &tail, const Point3d &head);
117  double curvature(Point2d center, const Mat &image);
118  static double modul(double angle);
119  double divide(double a, double b);
120  static double angleDifference(double alpha, double beta);
121  bool objectDirection(const UMat &image, vector<double> &information);
122  vector<double> objectInformation(const UMat &image);
123  vector<Point3d> reassignment(const vector<Point3d> &past, const vector<Point3d> &input, const vector<int> &assignment);
124  UMat backgroundExtraction(VideoReader &video, int n, const int method, const int registrationMethod);
125  void registration(UMat imageReference, UMat &frame, int method);
126  void binarisation(UMat &frame, char backgroundColor, int value);
127  vector<vector<Point3d>> objectPosition(const UMat &frame, int minSize, int maxSize);
128  vector<int> costFunc(const vector<vector<Point3d>> &prevPos, const vector<vector<Point3d>> &pos, double LENGHT, double ANGLE, double LO, double AREA, double PERIMETER);
129  void cleaning(const vector<int> &occluded, vector<int> &lostCounter, vector<int> &id, vector<vector<Point3d>> &input, double param_maximalTime);
130  vector<Point3d> prevision(vector<Point3d> past, vector<Point3d> present);
131  vector<Point3i> color(int number);
132  vector<int> findOcclusion(vector<int> assignment);
133 
135  UMat m_visuFrame;
136  vector<vector<Point3d>> m_out;
137  vector<vector<Point3d>> m_outPrev;
139  public slots:
140  void startProcess();
141  void updatingParameters(const QMap<QString, QString> &);
142  void imageProcessing();
143 
144  signals:
149  void progress(int);
150 
155  void backgroundProgress(int);
156 
160  void finishedProcessFrame();
161 
165  void finished();
166 
170  void forceFinished(QString message);
171 
175  void error(int code);
176 
180  void statistic(long long int time);
181 };
182 
183 #endif
QFile m_logFile
Definition: tracking.h:75
vector< vector< Point3d > > m_out
Definition: tracking.h:136
UMat m_visuFrame
Definition: tracking.h:135
vector< cv::String > m_files
Definition: tracking.h:76
This class is intended to execute a tracking analysis on an image sequence. It is initialized with th...
Definition: tracking.h:58
double param_area
Definition: tracking.h:93
vector< vector< Point3d > > m_outPrev
Definition: tracking.h:137
int m_displayTime
Definition: tracking.h:85
int param_kernelSize
Definition: tracking.h:106
int param_methodBackground
Definition: tracking.h:99
vector< vector< Point > > m_memory
Definition: tracking.h:78
string m_path
Definition: tracking.h:83
int param_spot
Definition: tracking.h:90
double param_perimeter
Definition: tracking.h:94
double param_to
Definition: tracking.h:96
int m_im
Definition: tracking.h:68
int param_thresh
Definition: tracking.h:97
UMat m_background
Definition: tracking.h:63
bool statusBinarisation
Definition: tracking.h:65
QMap< QString, QString > parameters
Definition: tracking.h:109
int param_y2
Definition: tracking.h:105
int param_methodRegistrationBackground
Definition: tracking.h:100
int m_stopImage
Definition: tracking.h:71
double param_len
Definition: tracking.h:91
int param_x1
Definition: tracking.h:102
vector< int > m_id
Definition: tracking.h:79
int param_registration
Definition: tracking.h:101
string m_backgroundPath
Definition: tracking.h:84
int param_y1
Definition: tracking.h:103
double param_nBackground
Definition: tracking.h:98
QString m_error
Definition: tracking.h:69
QTextStream m_savefile
Definition: tracking.h:73
int param_minArea
Definition: tracking.h:89
int param_kernelType
Definition: tracking.h:107
int param_maxArea
Definition: tracking.h:88
UMat m_binaryFrame
Definition: tracking.h:134
QFile m_outputFile
Definition: tracking.h:74
vector< Point3i > m_colorMap
Definition: tracking.h:77
int param_n
Definition: tracking.h:87
double param_angle
Definition: tracking.h:92
vector< int > m_lost
Definition: tracking.h:80
int param_morphOperation
Definition: tracking.h:108
double param_lo
Definition: tracking.h:95
int m_startImage
Definition: tracking.h:70
This class is intended to abstract the opening of a video, it can load image sequence and video with ...
Definition: videoreader.h:34
QElapsedTimer * timer
Definition: tracking.h:61
int param_x2
Definition: tracking.h:104
Rect m_ROI
Definition: tracking.h:72