VAT  3.0
Video Analysis Tool
templateclass.h
1 #ifndef TEMPLATECLASS_H
2 #define TEMPLATECLASS_H
3 
4 #include "opencv2/opencv.hpp"
5 #include "QString"
6 #include "map"
7 #include "json.h"
8 #include <QDir>
9 #include <QTextStream>
10 
11 #include <src/footballConstants.h>
12 
13 //Lookup tables Limit for rgb intensity
14 #define B_LIMIT 256
15 #define G_LIMIT 256
16 #define R_LIMIT 256
17 
18 
19 void RGB2XYZ(const int& sR,
20  const int& sG,
21  const int& sB,
22  double& X,
23  double& Y,
24  double& Z
25  );
26 
27 void RGB2LAB(const int& sR,
28  const int& sG,
29  const int& sB,
30  double& lval,
31  double& aval,
32  double& bval
33  );
34 
36 
37 typedef std::map<soccerClass, std::map< playerPart , cv::Mat > > soccerIntImType;
38 typedef std::map< soccerClass , std::map< playerPart, gaussianMixtureColorModel > > colorClassType;
39 
41 {
42 public:
43 
44  templateClass();
45  ~templateClass();
46  void clearIntegralImages();
47  void clearRectParts();
48 
49  void setColor(const gaussianMixtureColorModel &gM, playerPart part , soccerClass clase);
50  void setColor(QString filename, playerPart part, soccerClass clase, bool i, QString distFilename = NULL, QString probFileName = NULL );
51  void setROI(cv::Mat roi, cv::Mat froi);
52  void setRectParts(cv::Rect roi, int x, int y, int height, int width);
53 
54  std::string partToString(playerPart part);
55 
56  gaussianMixtureColorModel getColors(playerPart part, soccerClass clase);
57 
58 
59  double getDistance(cv::Vec3b bgrPixel, soccerClass team, playerPart part);
60 
61  double getColorMapProb(soccerClass team);
62 
63  double getRectangleSum(cv::Rect rect, const cv::Mat &integral );
64 
65  cv::Rect getPartOnFrameCoordinate(cv::Point offset, playerPart p);
66 
67  std::map< playerPart, cv::Rect > part;
68  soccerIntImType integralImages;
69 
70 private:
71 
72  cv::Rect setRectPart(int heightROI, int widthROI, int x, int y, int height, int width, playerPart part);
73 
74  //First: Clase , Second: Pair( part, MOG )
75  colorClassType ColorClasses; //MOG for each part en each class
76 
77  //Tabla para comprensioón de imagen a mapa de colores de 16 Bits
78  uchar table5[256];
79  uchar table6[256];
80 };
81 
83 {
84 public:
85 
88 
89  void readParamsfromJSONFile(QString fileName); //Read Parameters of Model from file
90  void setParameters(const cv::Mat &means, const cv::Mat &weights, std::vector<cv::Mat> covs);
91  void deleteParameters(); //Delete Parameters
92  void deleteTables(); //delete Tables
93  void generateMahalanobisTable(QString fileName = NULL); //Compute Mahalanobis distance Table
94  void generateProbTable(QString fileName = NULL);
95 
96  //Save in CSV file
97  void saveDistTable(QString filename);
98  void saveProbTable(QString filename);
99  void saveParameters(QString filename, QString model);
100  void readParameters(QString filename, QString model);
101  void showModel(std::string name);
102 
103  cv::Mat getMeans(int c); //Get Means (RGB) to ith component
104  cv::Mat getCov(int c); //Get Cov Matrix to ith component
105 
106  double getWeight(int c); //Get Weight to ith component
107  double calcMahalanobisDistance(cv::Mat bgr_points, int c); //Compute Mahalanobis Distance to rgb_value for ith component
108  double calcEuclideanDistance(cv::Mat bgr_points, int c);
109  double getTableMValue(unsigned long value, int c); //Get Mahalanobis Table value for component c
110  double getTableValue(unsigned long value); //Get Total Mahalanobis Table value
111  int getIndexTableValue(unsigned long value);
112  double getProbTableValue(unsigned long value);
113  double getMaxDist();
114  double getMinDist();
115 
116  int getComponents();
117 
118  void release();
119 
120  static unsigned long createBGR(int r, int g, int b)
121  {
122  return ((b & 0xff) << 16) + ((g & 0xff) << 8) + (r & 0xff);
123  }
124 
125  cv::Ptr<cv::ml::EM> emPointer;
126 
127 
128 private:
129 
130  int n_components; //Number of components
131  cv::Mat means; //Mixture of Gaussians Means
132  cv::Mat weights; //Mixture of Gaussians Weights
133 
134  std::vector<cv::Mat> covs; //Mixture of Gaussians Covariance Matrix
135 
136  std::map< unsigned long, std::vector < double > > mahalanobisDistTable; //Mahalanobis Distance Table
137  std::map< unsigned long, double> distTable; //Mahalanobis Distance Table
138  std::map< unsigned long, double > logLikeTable;//LogLikelihood AlgorithmTable
139  std::map< unsigned long, int > indexClassTable;//Index to most near class
140 
141  double maxDist;
142  double minDist;
143 
144  bool autoGeneratedTables;
145 
146 };
147 
148 #endif // TEMPLATECLASS_H
Definition: templateclass.h:82
Definition: templateclass.h:40