VAT  3.0
Video Analysis Tool
RMMMobileObject.h
1 #ifndef __RMM_MOBILE_OBJECT_H__
2 #define __RMM_MOBILE_OBJECT_H__
3 
4 #include "MODELS/reliabilitymultimodel.h"
5 #include "src/ModelInterface.h"
6 #include <iostream>
7 #include <map>
8 #include <deque>
9 #include <QImage>
10 
11 #define MOBILE_DEBUG_DATA
12 #define MOBILE_DETAILS
13 #define SHOW_BLOB_BUFFER
14 
15 class RMMMobileObject;
16 
17 class RMMTracker;
18 
20 
23 
24 typedef QSharedPointer<RMMMobileObject> SpRMMMobileObject;
25 
27  bool operator()(SpRMMMobileObject mobile1, SpRMMMobileObject mobile2);
28 };
29 
31  bool operator()(SpRMMMobileObject mobile1, SpRMMMobileObject mobile2);
32 };
33 
34 
35 
37  public:
38  static SceneModel *m_context;
39 
40  static double m_maxSpeed;
41  static int m_currentTrackingBlobsNumber;
42  static double m_lambda; //Cooling parameter
43  static int m_MultiModelBufferSize;
44  static int m_trajectoryMaxSize;
45  static double m_knownSolutionThreshold;
46  static double m_mobile2DCoverageRateToConsiderEqual;
47  static double m_mobile2DCoverageSegmentationToConsiderEqual;
48  static double m_mobileMinProbabilityToClassify;
49 
50  //Used to find the best type and to update buffer information
51  static double m_CoherenceReliabilityThreshold; //REMOVE FROM PARAMETERS FIRST
52  static double m_CoherenceProbabilityThreshold; //REMOVE FROM PARAMETERS FIRST
53  static double m_probabilityToEnsureMode; //REMOVE FROM PARAMETERS FIRST
54  static int m_reliableFrames;
55  static double zeroTolerance;
56 
57  static double *secDiffSequence;
58  static double *secDiffToCurrent;
59  static double *coolingValue;
60  static ReliabilityMultiModelTemplate *m_modelTemplate;
61  static RMMTracker *m_tracker;
62 
63  static cv::KalmanFilter m_kalman;
64 
65  static bool m_useKalman;
66  static int m_kalmanMaxPixelError;
67 
68  static SpRMMHypothesis activeHypothesis;//Active Hypothesis on update phase of tracking
69 
70  Datapool *m_data;
71 
72  unsigned long mobile_id;
73 
74  ObjectType best_type;
75  ObjectSubtype best_subtype;
76 
77  int best_index;
78 
79  bool ensureMode; //Flag for indicating when a mobile object becomes "sure" in terms of type.
80  //Important flag for performing coherence validation just for one class type,
81  //optimizing computational cost.
82 
83  int numberOfFramesNotSeen, numberOfFramesSinceFirstTimeSeen;
84 
85  int currentFrame; //Marks if the mobile information is updated to the current frame (made by updateMobileBufferStructures method)
86  long timeStamp; //Time in milliseconds, corresponding to the time of current frame.
87  bool firstUpdate;
88 
89  DetectionProblemType currentVisualState;
90  bool foundSupport;
91  int numberOfFound;
92 
93  //General cooling variables:
94  double prevCooling, sumCooling;
95 
96  //Global Probabilities
97  double P; //Model Coherence (tracker probability)
98  double R; //Input Data Reliability (tracker reliability)
99 
100  //Variables used by RMM Tracker
101  bool *usedBlobs;
102  int numUsed;
103  bool *involvedBlobs;
104  int numInvolved;
105  Rectangle<int> iestimator;
106  bool comparedMobile;
107  bool toErase;
108 
109  int firstForwardModel; //Flag for indicating if model processing completion is required.
110  //It indicates the first processed model index for a new object.
111  //If index is -1, it means no reprocessing is required (for initial object).
112 
113  std::deque<SpRMMMobileObject> history; //History of objects before specialization
114  int firstFrameSeen; //First frame in sequence where the object appears: useful to establish the history of the object.
115 
116  //The multi-model object
117  ReliabilityMultiModel multiModel;
118 
119 
120  RMMMobileObject(Datapool *i_data, bool init_models=true);
121  RMMMobileObject(SpRMMMobileObject m);
123  ~RMMMobileObject();
124 
125  //Copy elements when a new object is created from a model
126  void copyForNewObject(RMMMobileObject *to_copy);
127 
128  //Init functions
129  void initUsedBlobs();
130  void initInvolvedBlobs();
131  static void initKalman();
132 
133  //Inserting Functions
134  std::set<SpRMMHypothesis, hypothesesOrderedByBestProbabilityOperator> setInitialMultiModel(BoundingBox &bbox);
135 
136  //Build new model instances from template and associate pointer to mobile object
137  void renewModels();
138  //Build new model instances from existing ReliabilityModel and associate pointer to mobile object
139  void renewModels(ReliabilityMultiModel &rm);
140 
141  //Setting Functions
142  void setMobileId(unsigned long i_id);
143  void setNewMobileFromBlob(Blob *blob, unsigned long mobile_id);
144  void setNumberOfFramesNotSeen(int num);
145  void incrementNumberOfFramesNotSeen();
146  void incrementNumberOfFramesSinceFirstTimeSeen();
147  void setGlobalProbability();
148  BoundingBox determineMostLikelyBoundingBox();
149  //Getting Functions
150  unsigned long getMobileId();
151  ObjectType getBestType();
152  ObjectSubtype getBestSubType();
153  int getNumberOfFramesNotSeen();
154  int getNumberOfFramesSinceFirstTimeSeen();
155  double getGlobalProbability();
156  SpReliabilitySingleModelInterface getSubModel(QString);
157  SpReliabilitySingleModelInterface getSubModel(QString name, std::deque<SpReliabilitySingleModelInterface> &models);
158 
159  bool findSingleModelByName(QString name);
160 
161  //Auxiliar fuctions
162  static double NormalizeOrientation(double);
163  static double minimalAngularDistance(double alpha1, double alpha2);
164  static double NormalizeVelocityAngle(double);
165  static double coolingFunction(double x);
166 
167  std::set<SpRMMHypothesis, hypothesesOrderedByBestProbabilityOperator> updateMobilePath(BoundingBox &bbox, DetectionProblemType dp_type);
168  void updateMobileBufferStructures(BoundingBox &bbox, DetectionProblemType dp_type);
169  void updateMobileDynamics();
170  void initDynamics();
171 
172  void initCooling();
173 
174  double DimensionalCoherenceReliability(double sigma_dim, double min, double max);
175 
176  //Rendering Functions
177  friend std::ostream& operator<<(std::ostream&, SpRMMMobileObject);
178 
179  //Incremental Implementation for Updating Mobile Information
180  void updateBestTypeInformation();
181  void incrementalUpdateDynamics(std::deque<SpReliabilitySingleModelInterface> &dyn);
182  void updateCooling();
183  bool mobileOutOfScene();
184 
185  void setMobileReference();
186 
187  Rectangle<int> getVisualEvidenceEstimator();
188  Rectangle<int> getVisualEvidenceEstimator(double &R);
189 
190  void prepareNewMobile(BoundingBox &bbox, unsigned long mobile_id, DetectionProblemType dp_type);
191  void prepareExistingMobile(BoundingBox &bbox, DetectionProblemType dp_type);
192  bool differentEnoughForWorthyBackReprocessing(SpReliabilitySingleModelInterface current, SpReliabilitySingleModelInterface dependant);
193  static bool diffEnoughSegmentation(cv::Mat &current, cv::Mat &dependant);
194  void genROIFromFg(cv::Mat &image_roi, BoundingBox &roi);
195  void mergeSegmentation(ModelInstanceGeneralPack &m1, ModelInstanceGeneralPack &m2);
196  void mergeGeneralPacks(ModelInstanceGeneralPack *packs[], int size, ModelInstanceGeneralPack &result);
197  void weightedMergeGeneralPacks(ModelInstanceGeneralPack *packs[], int size, ModelInstanceGeneralPack &result);
198  bool oneStrongClass(int index, int &strong_dep_index, ModelInstanceGeneralPack *post[], int size);
199 
200  void integrateInsideForeground(ModelInstanceGeneralPack &result, ModelInstanceGeneralPack &toCopy);
201  double segmentationSimilarity(ModelInstanceGeneralPack &m1, ModelInstanceGeneralPack &m2);
202  double segmentationSimilarity(ModelInstanceGeneralPack &m1, BoundingBox &roi2);
203  void cloneSegmentation(ModelInstanceGeneralPack &result, ModelInstanceGeneralPack &copy, bool gen_fg);
204 
205  static void genROIFromSpecificSegmentation(cv::Mat &image_roi, BoundingBox &roi, BoundingBox &original_roi, cv::Mat &original_seg);
206  static double boundingBoxSimilarity(BoundingBox &b1, BoundingBox &b2);
207  static double segmentationSimilarity(cv::Mat &m1, cv::Mat &m2);
208  static double classSimilarity(ModelInstanceGeneralPack &m1, ModelInstanceGeneralPack &m2);
209 
210 
211  ModelInstanceGeneralPack &generatePostCompletion(int origin, int modelIndex, ModelInstanceGeneralPack &dpack);
212  void generatePostCompletion(int modelIndex, ModelInstanceGeneralPack& dpack);
213 
214  };
215 
216 
217 
219 
220 #endif
Definition: reliabilitymultimodel.h:126
Definition: RMMTracker.h:60
Definition: RMMMobileObject.h:36
Definition: RMMMobileObject.h:30
Definition: calibration.h:51
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: RMMMobileObject.h:26
Definition: reliabilitymultimodel.h:24
Definition: blob.h:79
Definition: reliabilitysinglemodelinterface.h:21