VAT  3.0
Video Analysis Tool
colorModelLearning.h
1 #ifndef COLORMODELLEARNING_H
2 #define COLORMODELLEARNING_H
3 
4 #include <opencv/cv.h>
5 #include <opencv/highgui.h>
6 #include "opencv2/opencv.hpp"
7 #include <opencv2/ml.hpp>
8 
9 #include <QString>
10 
11 #include <src/footballConstants.h>
12 
13 enum Source
14 {
15  CSV,
16  MATS,
17  DATABASE
18 };
19 
20 enum MatrixType
21 {
22  MEAN,
23  COV,
24  WEIGHT
25 };
26 
27 typedef struct sampleColorModel sampleColorModel;
29 {
30  double R;
31  double G;
32  double B;
33  unsigned long frame;
34 };
35 
36 typedef struct colorModel colorModel;
37 struct colorModel
38 {
39  QString name;//Name of Model
40  cv::Ptr<cv::ml::EM> emAl; //EM Algorithm for each class
41  bool isTrained; //Flag que indica si la clase esta entrenada
42  unsigned long nSamples; //Enumera la cantidad de muestras actuales en cada Modelo
43  unsigned long pSamples; //Cantidad de muestras con la que se entreno el Modelo
44  double probability; //Confiabilidad del Modelo
45  std::vector<sampleColorModel> samples; //Muestras actuales por cada Clase
46 };
47 
48 //ModelType To QString
49 QString colorModelTypeToQString(ColorModelType m);
50 
52 {
53 public:
55  colorModelLearning(ColorModelType type, int n_clusters);
57 
58  bool getSamplesFromCSV(QString file,int control); //Obtiene nuevas muestras desde un archivo CSV
59  bool trainEM();
60  void resetTrain();
61  void saveModel(); //Save Model Parameters in CSV file or XML
62  bool updateModel();//Actualiza la clase del Modelo de Color referenciado
63  void showModel(); //Show model in GUI
64 
65  //With these methods we obtain Mixture of Gaussians Parameters
66  bool getWeights(cv::Mat &mat);
67  bool getMeans(cv::Mat &mat);
68  bool getCovs(std::vector< cv::Mat > &vmat);
69  QString getName();
70  cv::Ptr<cv::ml::EM> getEM();
71 
72 
73 
74 private:
75 
76  void addSamples();//Agrega nuevas muestras a la base de datos
77  void eraseSamples(unsigned long init, unsigned long end); //Elimina muestras
78  unsigned long samplesToMap(cv::Mat &mat);
79 
80  colorModel model; // Modelos de Color
81  int n_clusters;
82  ColorModelType type;
83 
84  int n_parametersCSV;
85 };
86 
87 #endif // COLORMODELLEARNING_H
Definition: colorModelLearning.h:28
Definition: colorModelLearning.h:51
Definition: colorModelLearning.h:37