VAT  3.0
Video Analysis Tool
reliabilitymultimodel.h
1 #ifndef RELIABILITYMULTIMODEL_H
2 #define RELIABILITYMULTIMODEL_H
3 
4 #include "reliabilitysinglemodelinterface.h"
5 #include "src/trajectory.h"
6 
7 class Blob;
8 
9 class RMMMobileObject;
10 
12 
13 class Datapool;
14 
15 typedef QSharedPointer<ReliabilityMultiModel> SpReliabilityMultiModel;
16 
17 enum MultiModelDynamicsAttributes {
18  WIDTH,
19  HEIGHT,
20  X,
21  Y,
22 };
23 
25 public:
26 
29 
30  //Starts processing of parameters (only for multimodel template)
31  bool setParameters(QDomDocument &);
32 
33  //Set class structure for quick verification on branching nodes
34  void setClassStructure();
35 
36  //Completes a branch with class until a branching node is found.
37  void iterateClassStructure(SpReliabilitySingleModelInterface model, std::set<ObjectType> &new_classes);
38 
39  //Process names for model and model class. Checks availability of classes and unicity of names.
40  // (only for multimodel template)
41  bool setModelList(QDomElement &parent);
42 
43  //Checks model dependences and applies a topological order of models,
44  //to allow processing accomplishing dependences. If ordering is
45  //not achieved, this means that the Directed Graph is not acyclic (error)
46  bool checkDependences(std::map<QString, QString> &dependences, std::deque<QString> &name_list);
47 
48  //Process dependences for each model and checks DAG constraint, using topological ordering.
49  //Generates pre-loaded lists for backward and forward independent models in DAG, based on dependences.
50  void setDependences(std::map<QString, QString> &dependences, std::deque<QString> &ordered_list);
51 
52  //Iteratively completes class hierarchy
53  void processClassHierarchyList(QDomNodeList &l, ObjectType parent);
54 
55  std::vector<SpReliabilitySingleModelInterface> multiModelDAG;
56  std::map<QString, int> namePositionMap;
57  std::map<int, int> dependants_count;
58  std::vector<int> independentModelIndex;
59  std::map<ObjectType, ObjectType> class_hierarchy; //Each considered object class (key), and its parent (value). If parent is UNKNOWN, class
60  //is root.
61  std::vector<ObjectType> parent_classes; //Parent classes in hierarchy
62  Datapool *m_data;
63  std::map<int, std::map<int, std::set<ObjectType> > > class_structure; //Each index (key) (-1 for base branches), with a list of dependants indexes of those branches which perform classification.
64 
65  std::map<int, std::set<ObjectType> > class_synth_structure; //Each index (key) (-1 for base branches), with an accumulated list of dependant classes which perform classification.
66 
67 };
68 
70 public:
72  GeneralModelBuffer(int size);
74  std::deque<ModelInstanceGeneralPack>::iterator begin();
75  std::deque<ModelInstanceGeneralPack>::iterator end();
76  std::deque<ModelInstanceGeneralPack>::reverse_iterator rbegin();
77  std::deque<ModelInstanceGeneralPack>::reverse_iterator rend();
78  ModelInstanceGeneralPack &operator[](int);
79  unsigned int size();
81  ModelInstanceGeneralPack &front();
82  void clear();
83  void insert(ModelInstanceGeneralPack *);
84  void insert(ModelInstanceGeneralPack &pack);
85  void resetMaxLength(int);
86  void copyModels(GeneralModelBuffer *);
87 
88  friend std::ostream& operator<<(std::ostream&,const GeneralModelBuffer&);
89 
90  std::deque<ModelInstanceGeneralPack> instances;
91  unsigned int maxLength;
92 };
93 
95 public:
101 };
102 
104 public:
105  double z;
106  double Rz;
107  double accRz;
108  double sigmaZ;
109  cv::KalmanFilter k;
110  double A; //current acceleration
111  double RA; //
112  double varA; //variance of acceleration
113  cv::Mat prediction;
114  cv::Mat correction;
115 };
116 
118 public:
119  ModelKalmanPack x;
120  ModelKalmanPack y;
121  ModelKalmanPack width;
122  ModelKalmanPack height;
123 };
124 
125 
127 
128 public:
129  ReliabilityMultiModel(Datapool *i_data, int trajectory_max_size, int buffer_size);
132  //sets activation flags for each model, according to the current context
133  void activateModels();
134  void activateModels(std::deque<SpReliabilitySingleModelInterface> &);
135 
136  //Initializes owner mobile object pointer for every model.
137  void init(RMMMobileObject *);
138  void init(RMMMobileObject *, std::deque<SpReliabilitySingleModelInterface> &);
139 
140  //Gets last Model instance according to its name, else return spointer, with spointer.isNull() == true.
141  SpReliabilitySingleModelInterface getSingleModelByName(QString name);
142  SpReliabilitySingleModelInterface getSingleModelByClassName(QString className,
143  std::vector<SpReliabilitySingleModelInterface> &models);
144  SpReliabilitySingleModelInterface getSingleModelByName(QString name,
145  std::vector<SpReliabilitySingleModelInterface> &models);
146 
147  //Returns true if it finds a Model instance according to its name, else returns false.
148  bool findSingleModelByName(QString name);
149  bool findSingleModelByName(QString name, std::vector<SpReliabilitySingleModelInterface> &models);
150 
151  //forward process of models, starting with non-dependant models.
152  void update(BoundingBox &bbox, std::set<SpRMMHypothesis, hypothesesOrderedByBestProbabilityOperator> &hset);
153 
154  //Estimator of position of visual evidence
155  Rectangle<int> getVisualEvidenceEstimator(double &R);
156 
157  void getGlobalProbability(double &R, double &P);
158 
159  void set2DTrajectoryPoint();
160 
161  void set2DTrajectoryPointEstimation();
162 
163  void setPriorDynamics();
164 
165  void updateDynamics();
166 
167  void setProbabilityAndReliability();
168 
169 
170  //Standard attribute dynamics update, with no attribute value constraints
171  void updateAttribute(MultiModelDynamicsAttributes name, double data, double RData, ReliabilityDynamicsAttribute &d);
172 
173  //Using Kalman Filter considering state vector (x, Vx) and acceleration as a control parameter
174  void updateKalmanAttribute(MultiModelDynamicsAttributes name, double data, double RData, ModelKalmanPack &d);
175  void initKalmanAttribute(ModelKalmanPack &d, double value, double r);
176  void updateKalmanDynamics();
177  double setKalmanAcceleration(MultiModelDynamicsAttributes name, double data, double RData, ModelKalmanPack &d, double &R);
178 
179 
180  void getBufferAttributeValue(ModelInstanceGeneralPack &pack, MultiModelDynamicsAttributes name, double &value, double &R);
181  void updateAttributeDynamics(double data, double RData, double acuity,
182  double estimate, double currentCooling, AttributeTripletValue &att);
183  void updateAttributeDynamicsNoData(double estimate, double acuity, double currentCooling, AttributeTripletValue &att);
184  double normalisedSigmaCoherenceReliability(double sigma, double acuity);
185  double getAttributeEstimate(ReliabilityDynamicsAttribute &d, double time_diff);
186  void initAttribute(ReliabilityDynamicsAttribute &d, double value, double r);
187  BoundingBox getEstimator(double &R);
188  BoundingBox getKalmanEstimator(double &R);
189 
190  double projectAttributeValue(ReliabilityDynamicsAttribute &attr, double &R);
191  double projectKalmanAttributeValue(ModelKalmanPack &attr, double &R);
192 
193  void setValidatedModels(ModelInstanceGeneralPack& p);
194  void setMultiModelGeneralInstance(ModelInstanceGeneralPack& p);
195  ModelInstanceGeneralPack *completeBranch(int index, ModelInstanceGeneralPack& p);
196 
197 
198  static ReliabilityMultiModelTemplate *m_template;
199  static int m_pixelAcuity;
200  static double m_minimalAttributeVelocityReliability;
201  static double m_minimalAttributeAccelerationReliability;
202 
203  //accumulatedPclass/accumulatedPclasses_in_branch > m_minimalClassDifferentiationProbability to become a validatedClass (and accumulatedPclass > m_ensureNumber)
204  static double m_minimalClassDifferentiationProbability;
205 
206  Datapool *m_data;
207  RMMMobileObject *mobile;
208  std::vector<SpReliabilitySingleModelInterface> multiModelDAG;
209  std::map <ObjectType, double> accumulatedClassScore; //Stores the accumulated class score to the object model
210  std::set<ObjectType> validatedTypes;
211  //History of previously seen positions
212  Trajectory trajectory2D;
213  Trajectory trajectory2Destimation;
214  Trajectory3D trajectory3D;
215 
216 // bool active;
217  BoundingBox binterface_in;
218  BoundingBox binterface_out;
219 
220  GeneralModelBuffer buffer;
221  ModelGeneralDynamics dynamics;
222  ModelKalmanDynamics kdynamics;
223 
224  //Global Probabilities
225  double P; //Model Coherence (tracker probability)
226  double R; //Input Data Reliability (tracker reliability)
227 
228  double currentTimeDiffSeconds;
229 
230  int currentCompareModel;
231 
232 };
233 
234 
235 typedef QSharedPointer<ReliabilityMultiModel> SpReliabilityMultiModel;
236 
237 
238 #endif // RELIABILITYMULTIMODEL_H
Definition: reliabilitymultimodel.h:117
Definition: reliabilitymultimodel.h:126
Definition: trajectory.h:54
Definition: reliabilitymultimodel.h:69
Definition: RMMMobileObject.h:36
Definition: reliabilityattribute.h:101
Definition: reliabilitymultimodel.h:103
Definition: reliabilitymultimodel.h:94
Definition: reliabilitysinglemodelinterface.h:27
An object of this class is instantiated at main code, and this object is used by every class to push ...
Definition: Datapool.h:39
Definition: reliabilityattribute.h:76
Definition: reliabilitymultimodel.h:24
Definition: blob.h:79
Definition: trajectory.h:20
Definition: BackgroundRecLigth.h:20