VAT  3.0
Video Analysis Tool
reliabilitysinglemodelinterface.h
1 #ifndef RELIABILITYSINGLEMODELINTERFACE_H
2 #define RELIABILITYSINGLEMODELINTERFACE_H
3 
4 #include <QDomNode>
5 #include <QImage>
6 #include <vector>
7 #include <QSharedPointer>
8 
9 #include "reliabilityattribute.h"
10 #include "src/blob.h"
11 #include "src/common.h"
12 
13 class Datapool;
14 class RMMTracker;
15 class RMMMobileObject;
16 typedef QSharedPointer<RMMMobileObject> SpRMMMobileObject;
17 
18 class RMMHypothesis;
19 typedef QSharedPointer<RMMHypothesis> SpRMMHypothesis;
20 
22  bool operator()(SpRMMHypothesis a1, SpRMMHypothesis a2);
23 };
24 
26 
28 public:
29  ModelInstanceGeneralPack(int frame); //It is a requirement to set the frame number, in order to check when the instance was inserted
30  ModelInstanceGeneralPack(); //It is a requirement to set the frame number, in order to check when the instance was inserted
31  int frameNumber; //Current frame number (automatic fill).
32  long timeStamp; //Current timestamp in milliseconds (automatic fill).
33  bool foundSupport; //true if the bounding box finds support in segmentation (automatic fill).
34  //false commonly indicates that the object is considered lost in this frame.
35  //IT COULD BE CHANGED TO true IF EVIDENCE FROM OTHER SEGMENTATION HAS BEEN FOUND
36  DetectionProblemType dp_type; //It signals different problems that could potentially have the visual evidence from the
37  //bounding box for the object in the current frame (automatic fill, but can be modified).
38 
39  //TO COMPLETE BY EACH MODEL (normally with updateSingleInstance method):
40  AttributeSegmentation segmentation; //Used segmentation. If RD==0, standard segmentation is considered (m_data->fgImage)
41  bool changedSegmentation; //Change as true if segmentation is modified
42  BoundingBox roi; //Region of interest
43  double R_incorporate; //It globally indicates if the roi information should be incorporated as the integrated data from
44  // the multimodel structure in the report to the object. Value 1 indicates full incorporation,
45  // and 0 indicates to ignore it. Values in the middle indicate the degree of trust in the estimated
46  // roi. The multimodel reports the oldest non zero value and roi. When branches exist, it is used as
47  // global weight when merging. If the final report indicates 0 value, the original input bounding
48  // box to the multimodel will be considered.
49  Rectangle<double> Rroi; //ROI bounds reliability
50  std::map <ObjectType, double> classScore;
51 };
52 
54 public:
55  std::map <QString, AttributeDupletValue> attributes;
56  std::map <QString, AttributeDupletImage> attributes_image;
57  std::map <QString, AttributeDupletDataset> attributes_dataset;
59 };
60 
62 public:
63  std::map <QString, ReliabilityDynamicsAttribute> dynamics;
64  std::map <QString, ReliabilityDynamicsAttributeDataset> dynamics_dataset;
65 };
66 
67 class ModelBuffer {
68 public:
69  ModelBuffer(int buffer_size);
70  ~ModelBuffer();
71  std::deque<ModelInstanceDataPack>::iterator begin();
72  std::deque<ModelInstanceDataPack>::iterator end();
73  std::deque<ModelInstanceDataPack>::reverse_iterator rbegin();
74  std::deque<ModelInstanceDataPack>::reverse_iterator rend();
75  ModelInstanceDataPack &operator[](int);
76  unsigned int size();
77  ModelInstanceDataPack &back();
78  ModelInstanceDataPack &front();
79  void pop_front();
80  void clear();
81  void insert(ModelInstanceDataPack *);
82  void insert(ModelInstanceDataPack &pack);
83  void resetMaxLength(int);
84  void copyModels(ModelBuffer *);
85 
86  friend std::ostream& operator<<(std::ostream&,const ModelBuffer&);
87 
88  std::deque<ModelInstanceDataPack> instances;
89  unsigned int maxLength;
90 };
91 
93 
94 typedef QSharedPointer<ReliabilitySingleModelInterface> SpReliabilitySingleModelInterface;
95 
97 {
98 public:
99  ReliabilitySingleModelInterface(int buffer_size);
100 
101  //IMPLEMENT!!
103 
104 
105  //IMPLEMENT!! Initializes the model attributes for the interface.
106  //The function is called by the interface constructor
107  virtual void initInstanceAttributes() = 0;
108 
109  //IMPLEMENT!! Initializes the dynamics model attributes for the interface.
110  //The function is called by the interface constructor
111  virtual void initDynamicsAttributes() = 0;
112 
113  //IMPLEMENT!! Copy function for specific data from the instance (general_copy calls it after copying base info)
114  virtual void copy(SpReliabilitySingleModelInterface);
115 
116  //IMPLEMENT!! Copy general structures and parameters of specific model, without considering instance specific data
117  virtual void copy_structure(SpReliabilitySingleModelInterface);
118 
119  //IMPLEMENT!! sets parameters from xml file
120  virtual void setParameters(QDomNode &i_parameters) = 0;
121 
122  //IMPLEMENT!! sets activation criteria for each model: reliability on input (distance, bad data),
123  // needs (occlusion, priority),
124  //sets priority of models (hierarchy).
125  //Checked before update phase
126  virtual void activate(BoundingBox &) = 0;
127 
128  //IMPLEMENT!! initializes every activated model, according to their own input (region-blob-segments schema)
129  //Executed only once at the begginning of single model creation (after 'copy_structure' and 'copy' methods
130  //are used to copy the information).
131  virtual void init() = 0;
132 
133  //IMPLEMENT!! updates activated model instance attributes for current frame, and returns the set of detected/enriched objects.
134  // It notifies if roi (bounding box, or segmentation) changes compared to the input, for reprocessing.
135  virtual bool updateInstance(BoundingBox &, std::set<SpRMMHypothesis, hypothesesOrderedByBestProbabilityOperator> &) = 0;
136 
137  //IMPLEMENT!! updates activated model instance attributes for current frame and object, and returns the detected/enriched object.
138  // It notifies if roi (bounding box, or segmentation) changes compared to the input, for reprocessing.
139  // This function does NOT generate mobiles or hypotheses. It processes attributes for the current object.
140  // This function could be used by updateInstance to generate mobile information, for the generated mobiles.
141  // IT MUST INSERT A NEW ModelInstanceDataPack IN instances buffer and update ginfo attribute of the ModelInstanceDataPack
142  // properly (see ModelInstanceGeneralPack).
143  // IF CALLED INSIDE ONE METHOD OF THIS CLASS, IT MUST INCLUDE A CALL TO METHOD: updateCurrentGeneralInfo();
144  // ALSO WHEN CREATING NEW OBJECTS (IT MUST BE CALLED FOR THE CREATED OBJECT).
145  virtual void updateSingleInstance(BoundingBox &) = 0;
146 
147  //IMPLEMENT!! updates model dynamics, based on instances information: work on post_dynamics structure
148  virtual void updateModelDynamics() = 0;
149 
150  //Visualization
151  virtual void printInstances();
152 
153  virtual void printDynamics();
154 
155  virtual void printGeneral();
156 
157  virtual void printGeneral(std::ostream& out);
158 
159  virtual bool draw(QImage *image);
160 
161  virtual bool draw(QPainter &painter, int r, int g, int b);
162 
163  //Starts dynamics in multimodel and calls specific model dynamics with updateModelDynamics();
164  void updateDynamics();
165 
166  //sets global probability P for the model (how good is the model)
167  //sets global reliability R for the model (how good is the data used in the model)
168  virtual void setProbabilityAndReliability() = 0;
169 
170  //sets data pack general information of the model in forward process (update)
171  virtual void setForwardInterface() = 0;
172 
173  //Get 2D central bounding box point from the model
174  virtual void setTrajectory2D(double &, double &, double &);
175 
176  //Estimates the bounding box size and position for next
177  //frame according to its own dynamics model
178  //It also sets Reliability R of the model estimation.
179  //The function defaults to the 'binterface' bounding box.
180  //Nevertheless, a better implementation really depending on the
181  //specific dynamics model is expected.
182  virtual BoundingBox getEstimator(double &R);
183 
184  //This function sets parameters from xml
185  void initFromXML(Datapool *i_data, int bsize, QString name);
186 
187  //Copy general structures and call specific copy function, including data for specific instances
188  void general_copy(SpReliabilitySingleModelInterface);
189 
190  //Copy general structures: for new mobiles not related with a previous model
191  void copy_general_structure(SpReliabilitySingleModelInterface);
192 
193  //Adds current classes information to integratedInfo
194  void addCurrentClassInfo();
195  void addCurrentClassInfo(ModelInstanceGeneralPack &gpack);
196  static void addCurrentClassInfo(ModelInstanceGeneralPack &gpack1, ModelInstanceGeneralPack &gpack2);
197 
198  //Adds frame and timeStamp information to current instance of 'instances'
199  void updateCurrentGeneralInfo();
200 
201  //FOR USING IN DETECTION OF MORE THAN ONE OBJECT FROM CURRENT EVIDENCE:
202  //Generates copy of current mobile: copies models, multimodel, dynamics and history, same id
203  SpRMMMobileObject generateCurrentMobile(BoundingBox &bbox);
204 
205  //Generates new mobile: copies structure, multimodel, new id
206  SpRMMMobileObject generateNewMobile(BoundingBox &bbox);
207 
208  //Generates new hypothesis to store new mobiles
209  SpRMMHypothesis generateNewHypothesis();
210 
211  //OPTIONAL IMPLEMENTATION: Project current bounding box with the dynamics model information.
212  //It returns false, if multimodel dynamics are utilized, which is the implemented default behaviour in
213  //this class. If implemented in derived class, it MUST return true to signal the existence of the implementation
214  virtual bool projectBoundingBox(BoundingBox &bbox);
215 
216 
223  static double normalisedSigmaCoherenceReliability(double sigma, double acuity);
224 
225  //Tag name
226  QString name;
227 
228  //Model class name
229  QString model_name;
230 
231 
232  //Static link to the Multimodel template
233  static ReliabilityMultiModelTemplate *m_template;
234 
235  //Link to datapool
236  Datapool *m_data;
237 
238  //Flag for activation according to different criteria
239  bool active;
240 
241  //Global probability and reliability for model
242  double P, R_forward, R_backward;
243 
244  //Object classes able to detect (those classes determined by the model)
245  std::set<ObjectType> dclasses;
246 
247  //Object classes to classify (those classes discriminated by the model, among the different dependant branches)
248  std::set<ObjectType> cclasses;
249 
250 
251  //Required classes to activate (checked from the dependence) and corresponding class probability in [0; 1]
252  std::map<ObjectType, double> rclasses;
253 
254  //Reference to the associated mobile object
255  RMMMobileObject *m_mobile;
256 
257  //Attributes
258 
259  //1. Instance buffer
260  ModelBuffer instances; //Sets frame information (Here insert new information for frame with updateInstance and updateSingle instance)
261 
262  ModelInstanceGeneralPack integratedInfo; //Returned information to be considered as general feedback (automatic)
263 
264  ModelInstanceDataPack instanceTemplate;
265  static RMMTracker *m_tracker;
266 
267  //2. Dynamics model
268  ModelDynamicsDataPack prior_dynamics; //Copy of previous tracker iteration info.
269  ModelDynamicsDataPack post_dynamics; //Resulting dynamics for the object (generated by updateDynamics)
270  //(to start processing dynamics, first do 'post_dynamics = prior_dynamics;')
271 
272  //Output bounding box and information after update (forward) process
273  BoundingBox binterface_in; //Input roi
274 
275  //Output bounding box and information after feedback (backward) process
276  BoundingBox binterface_out; //Output roi
277 
278  //Access to dependence, or dependants indexes
279  //To access a model in the structure do: m_mobile->multiModel.multiModelDAG[index];
280  int dependence; //-1 reflects no dependence
281  std::vector<int> dependants;
282 
283  //Hypotheses structure generated by the model (here copy hypotheses if generated by this model with updateInstance)
284  std::set<SpRMMHypothesis, hypothesesOrderedByBestProbabilityOperator> generated_hypotheses;
285 
286  //Hypotheses structure returned by the forward process (DO NOT EDIT: it integrates hypotheses of dependants)
287  std::set<SpRMMHypothesis, hypothesesOrderedByBestProbabilityOperator> hypotheses;
288 
289 };
290 
291 #endif // RELIABILITYSINGLEMODELINTERFACE_H
Definition: RMMHypothesis.h:24
Definition: RMMTracker.h:60
Definition: reliabilitysinglemodelinterface.h:53
Definition: reliabilityattribute.h:47
Definition: RMMMobileObject.h:36
Definition: reliabilitysinglemodelinterface.h:61
Definition: reliabilitysinglemodelinterface.h:96
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: reliabilitymultimodel.h:24
Definition: reliabilitysinglemodelinterface.h:21
Definition: reliabilitysinglemodelinterface.h:67