VAT  3.0
Video Analysis Tool
MobileObject.h
1 #ifndef __MOBILE_OBJECT_H__
2 #define __MOBILE_OBJECT_H__
3 
4 #include "blob.h"
5 #include "calibration.h"
6 #include "parallelpiped.h"
7 #include "ModelInterface.h"
8 #include "MobileObject2D.h"
9 #include "trajectory.h"
10 #include <iostream>
11 #include <map>
12 #include <deque>
13 #include <QImage>
14 
15 #define MOBILE_DEBUG_DATA
16 #define MOBILE_DETAILS
17 #define SHOW_BLOB_BUFFER
18 
20  //General
21  double prevCooling2D, sumCooling2D, prevCooling3D, sumCooling3D;
22  double totalNumClassified;
23 };
24 
26  //For 3D orientation
27  double alphaEstimated, sumRDalpha, sumRDValpha;
28  //For 3D dimensions
29  double wEstimated, sumRDw, sumRDVw, sumPw;
30  double lEstimated, sumRDl, sumRDVl, sumPl;
31  double hEstimated, sumRDh, sumRDVh, sumPh;
32  //For 3D position
33  double sumRDxy, sumRDVxy, sumPxy, sumPVxy, xEstimated, yEstimated;
34 };
35 
36 
37 typedef struct IncrementalExtraGeneralData IncrementalExtraGeneralData;
38 typedef struct IncrementalExtra3DData IncrementalExtra3DData;
39 
41  double alpha, RDalpha, RCalpha, Ralpha, SDalpha;
42  double Valpha, RDValpha, RCValpha, RValpha, SDValpha;
43 
44  double w, Pw, Rw, RCw, RDw, SDw;
45  double l, Pl, Rl, RCl, RDl, SDl;
46  double h, Ph, Rh, RCh, RDh, SDh;
47 
48  double Vw, RVw, RCVw, RDVw, SDVw;
49  double Vl, RVl, RCVl, RDVl, SDVl;
50  double Vh, RVh, RCVh, RDVh, SDVh;
51 
52 };
53 
54 typedef struct tracking3DimensionalData tracking3DimensionalData;
55 
57  double x, SDx, Rx, RCx; //x 3D coordinate of object position
58  double y, SDy, Ry, RCy; //y 3D coordinate of object position
59  double RDxy; //Reliability of position due to mean reliability of parallelepiped base dimensions.
60  double Ppos; //Probability of position due to mean probability of parallelepiped base dimensions.
61 
62  double Vx, SDVx, RVx, RCVx; //Velocity vector component in 3D x coordinates
63  double Vy, SDVy, RVy, RCVy; //Velocity vector component in 3D y coordinates
64  double RDV; //Reliability of velocity according to positions reliability
65  double RCV; //Reliability of velocity according to coherence
66 
67  double V, //Velocity Magnitude
68  PV, //Probability of Velocity given positions probability
69  RV, //Reliability of Velocity
70  SDV, //Standard deviation of velocity magnitude
71  MPV; //Probability of Velocity Magnitude according to best type
72  double theta, SDtheta; //Velocity Angle w/r to the xy 3D plane.
73 
74 };
75 
76 typedef struct tracking3DSpatialData tracking3DSpatialData;
77 
78 struct info3D {
79  IncrementalExtraGeneralData iGData;
80  IncrementalExtra3DData i3DData;
81  tracking3DimensionalData t3DDimData;
82  tracking3DSpatialData t3DSpatialData;
83 };
84 
85 typedef struct info3D info3D;
86 
87 
88 class MobileObject;
90 
91 typedef QSharedPointer<MobileObject> SpMobileObject;
92 
94  bool operator()(SpMobileObject mobile1, SpMobileObject mobile2);
95 };
96 
98  bool operator()(SpMobileObject mobile1, SpMobileObject mobile2);
99 };
100 
102 
103  public:
104  static double ONE_OVER_SQRT_2_TIMES_PI;
105 
106  static SceneModel *m_context;
107  static ReliabilityClassification *m_rc;
108  static QImage *m_pSegmentation;
109  static double m_maxSpeed;
110  static double m_maxKnownSpeed;
111 
112  static int m_currentTrackingBlobsNumber;
113  static double m_lambda; //Cooling parameter
114  static int m_blobsBufferSize;
115  static int m_trajectoryMaxSize;
116  static double m_knownSolutionThreshold;
117 
118  static std::map<ObjectType, bool> rigidModel;
119  static std::map<ObjectType, int> objectModelMap;
120  static std::map<ObjectType, std::map<ObjectSubtype, int> > objectSubModelMap;
121  static SpModelInterface *objectModelsList;
122  static SpModelInterface **objectSubModelsList;
123 
124  static double **objectSubModelMinWidth;
125  static double **objectSubModelMeanWidth;
126  static double **objectSubModelMaxWidth;
127  static double **objectSubModelMinLength;
128  static double **objectSubModelMeanLength;
129  static double **objectSubModelMaxLength;
130  static double **objectSubModelMinHeight;
131  static double **objectSubModelMeanHeight;
132  static double **objectSubModelMaxHeight;
133  static double **objectSubModelMinVelocity;
134  static double **objectSubModelMeanVelocity;
135  static double **objectSubModelMaxVelocity;
136 
137  static double *objectModelMinWidth;
138  static double *objectModelMeanWidth;
139  static double *objectModelMaxWidth;
140  static double *objectModelMinLength;
141  static double *objectModelMeanLength;
142  static double *objectModelMaxLength;
143  static double *objectModelMinHeight;
144  static double *objectModelMeanHeight;
145  static double *objectModelMaxHeight;
146  static double *objectModelMinVelocity;
147  static double *objectModelMeanVelocity;
148  static double *objectModelMaxVelocity;
149 
150  static int m_objectModelsNumber;
151  static bool m_firstFrame;
152  static int m_numberOfPostures;
153 
154  static double m_SpatialCoherenceReliabilityThreshold;
155  static double m_SpatialCoherenceProbabilityThreshold;
156  static double m_DimensionalCoherenceReliabilityThreshold;
157  static double m_DimensionalCoherenceProbabilityThreshold;
158  static double m_MinimalHistoryProbability;
159  static double m_Maximal3DDimensionChangeSpeed;
160 
161  static std::map<ObjectType, ObjectSubtype> lastFoundSubtypeTemplate;
162 
163  //Used to find the best type and to update buffer information
164  static double m_classifThreshold;
165  static double m_maximalAlphaRotationSpeed;
166 
167  static double *secDiffSequence;
168  static double *secDiffToCurrent;
169  static double *coolingValue;
170 
171  static double m_maxFocalDistance;
172  static double m_objectSizeForMaxReliability;
173  static double m_objectDimensionForMaxReliability;
174  static double m_objectDistanceForMaxReliability;
175 
176  static double *g_postureMinw, *g_postureMinl, *g_postureMinh;
177  static double *g_postureMeanw, *g_postureMeanl, *g_postureMeanh;
178  static double *g_postureMaxw, *g_postureMaxl, *g_postureMaxh;
179  static ObjectSubtype *g_posturesList;
180 
181  static double m_probabilityToEnsureMode;
182  static int m_2DLevelFrames;
183 
184  static double *g_secDiffSequence;
185  static double *g_coolingValue;
186  static double *g_secDiffToCurrent;
187  static tracking2DimensionalData *g_t2DDimData;
188  static tracking2DSpatialData *g_t2DSpatialData;
189  static IncrementalExtraGeneralData *g_iGData;
190  static IncrementalExtra2DData *g_i2DData;
191  static Rectangle<int> *g_newBBoxesToAnalyze;
192  static double *g_newVisualSupport;
193  static DetectionProblemType *g_newDPFlags;
194  static int g_currentBufferSize;
195  static double zeroTolerance;
196  static double m_minimalTolerance;
197 
198  private:
199  unsigned long mobile_id;
200  unsigned long rmobile_id;
201  ObjectType best_type;
202  ObjectSubtype best_subtype;
203 
204  //Global Probability Measure
205  double P;
206 
207  public:
208  bool ensureMode; //Flag for indicating when a mobile object becomes "sure" in terms of type.
209  //Important flag for performing coherence validation just for one class type,
210  //optimizing computational cost.
211  // bool estimativeResult; //Marks if estimated are based in a priori information
212 
213  bool productionMode; //Flag for indicating to certain functions to not to add trajectory points
214  //because several alternatives are being tested (if false, it means "Test Mode").
215  bool lastUnknown, *lastKnownPerType;
216  int best_index;
217  int numberOfFramesNotSeen, numberOfFramesSinceFirstTimeSeen;
218  int previousBufferSize;
219  int currentBufferSize;
220  Shape3DData **s3dsToAnalyzeAllTypes;
221  Shape3DData **s3dsToAnalyze;
222  info3D *i3D;
223  Rectangle<int> *bboxesToAnalyze;
224  double *visualSupport;
225  DetectionProblemType *dpFlags;
226  DetectionProblemType currentVisualState;
227  bool *classifiedS3ds;
228  bool *foundS3ds;
229 
230  double *PSumPerType;
231  int debug_data_flag;
232 
233  int numberOfClassifiedS3ds, numberOfFoundS3ds;
234  double RKnownSolutions, RVKnownSolutions;
235  double RFoundSolutions, RVFoundSolutions;
236  //Global Probabilities
237  double P2D, R2D; //2D Dimensional Coherence Probability and Reliability
238  double P3D, R3D; //3D Dimensional Coherence Probability and Reliability
239  double PVC, RVC; //Velocity Coherence Probability and Reliability
240  double PV2DC, RV2DC; //Velocity Coherence Probability and Reliability
241 
242  //Best type limits
243  double current_min_w_model;
244  double current_max_w_model;
245  double current_min_l_model;
246  double current_max_l_model;
247  double current_min_h_model;
248  double current_max_h_model;
249  double current_min_velocity_model;
250  double current_max_velocity_model;
251 
252  //Encapsulated tracking data
253  tracking3DimensionalData t3DDimData;
254  tracking2DimensionalData t2DDimData;
255  tracking3DSpatialData t3DSpatialData;
256  tracking2DSpatialData t2DSpatialData;
257  //Data for incremental values update
258  IncrementalExtraGeneralData iGData;
259  IncrementalExtra2DData i2DData;
260  IncrementalExtra3DData i3DData;
261 
262  //History of previously seen blobs
263  blobBuffer blobHistory;
264 
265  //History of previously seen blobs
266  Trajectory trajectory3D;
267  Trajectory trajectory2D;
268 
269  //Variables used by Reliability Tracker
270  bool *usedBlobs;
271  int numUsed;
272  bool *involvedBlobs;
273  int numInvolved;
274  bool accepted_solution;
275  std::map<ObjectType, ObjectSubtype> lastFoundSubtype;
276  int unknownsNumber;
277  bool classificationAllowed;
278  bool comparedMobile;
279  bool toErase;
280 
281  MobileObject();
282  MobileObject(SpMobileObject);
283  ~MobileObject();
284 
285  //Init functions
286  void initUsedBlobs();
287  void initInvolvedBlobs();
288  void initMaps();
289  //Inserting Functions
290  void insertNewBlob(Blob *blob);
291  void insertNewBlob(Blob *blob, int lastMilliSecondsDifference);
292 
293  //Setting Functions
294  void setMobileId(unsigned long i_id);
295  void setRMobileId(unsigned long i_id);
296  void setNewMobileFromBlob(Blob *blob, unsigned long mobile_id, unsigned long rmobile_id);
297  void setNumberOfFramesNotSeen(int num);
298  void incrementNumberOfFramesNotSeen();
299  void incrementNumberOfFramesSinceFirstTimeSeen();
300  void setGlobalProbability();
301  Blob *determineMostLikelyBlob();
302  //Getting Functions
303  unsigned long getMobileId();
304  unsigned long getRMobileId();
305  ObjectType getBestType();
306  ObjectSubtype getBestSubType();
307  int getNumberOfFramesNotSeen();
308  int getNumberOfFramesSinceFirstTimeSeen();
309  double getGlobalProbability();
310 
311  //Auxiliar fuctions
312  static double NormalizeOrientation(double);
313  static double minimalAngularDistance(double alpha1, double alpha2);
314  static double NormalizeVelocityAngle(double);
315  static double coolingFunction(double x);
316 
317  void velocityMagnitudeAccordingToModels(Shape3DData *s3d);
318  double velocityAngleAccordingToEntranceToScene(Shape3DData *s3d);
319  void setAprioriVelocity(Shape3DData *s3d);
320 
321  void updateMobilePath(Blob *blob);
322  void updateMobileData();
323 
324  double DimensionalCoherenceReliability(double sigma_dim, double min, double max);
325 
326  //Rendering Functions
327  friend std::ostream& operator<<(std::ostream&, SpMobileObject);
328 
329  //Data for best types history
330  Shape3DData **getS3DBufferToAnalyze(ObjectType type);
331  Shape3DData **getS3DBufferToAnalyzeByIndex(int index);
332  Shape3DData *getS3DToAnalyze(ObjectType type, int frame);
333  Shape3DData *getS3DToAnalyzeByIndex(int index, int frame);
334  void setS3DToAnalyzeByIndex(int index, int frame, Shape3DData *s3d);
335  void insertS3DToAnalyzeByIndex(int index, Shape3DData *s3d);
336 
337  Shape3DData *getRightS3D(std::map<ObjectType, Shape3DData> *list, ObjectType type);
338  Shape3DData *getBestPostureCoherentS3DReclassifying(Blob *blob, std::map<ObjectType, Shape3DData> *normal,
339  std::map<ObjectType, Shape3DData> *occ, ObjectType type);
340 
341  double dimensional2DReliability(double distance2D, double blobW, double blobH);
342  double position2DReliability(double distance2D);
343 
344  double get2DDistanceToFocalPoint(Blob *blob);
345  double get2DDistanceToFocalPoint(Rectangle<int> *rectangle);
346  double get2DDistanceToFocalPoint(double X, double Y);
347 
348  bool mobile3DCoherenceIsAcceptable();
349  bool mobile2DCoherenceIsAcceptable();
350 
351  bool mobile3DVelocityCoherenceIsAcceptable();
352 
353  Shape3DData *getMostCoherentDataFromMobileAndBBoxLimit(std::map<ObjectType, Shape3DData> *normal,
354  std::map<ObjectType, Shape3DData> *occ, Blob *blob);
355 
356  void initPostureLimits(ObjectType type);
357 
358  void freePostureLimits();
359 
360  //Incremental Implementation for Updating Mobile Information
361  void updateBestType3DInformation();
362  void incrementalUpdateCooling(int bufferSize);
363  void incrementalUpdateOrientation(int bufferSize, Shape3DData **data, DetectionProblemType *dpFlags, double *visualSupport);
364  void incrementalUpdate3DDimensions(int bufferSize, Shape3DData **data, DetectionProblemType *dpFlags, double *visualSupport);
365  void incrementalUpdate3DPosition(int bufferSize, Shape3DData **data, DetectionProblemType *dpFlags, double *visualSupport);
366  void incrementalUpdate2DPosition(int bufferSize, Rectangle<int> *bboxesToAnalyze, DetectionProblemType *dpFlags, double *visualSupport, double maxDistanceFactor);
367  void incrementalUpdate2DDimensions(int bufferSize, Rectangle<int> *bboxesToAnalyze, DetectionProblemType *dpFlags, double *visualSupport, double maxDistanceFactor);
368 
369  void getCurrentBoundingBoxForMobile(Rectangle<int> *bbox);
370  void getCurrentBoundingBoxForMobileKeepingSize(Rectangle<int> *bbox);
371 
372  void improveBBoxSupport(Rectangle<int> *improvedBBox, Rectangle<int> *estimatedBBox, Rectangle<int> *visualEvidence);
373  void generateS3DFrom3DInformation(Shape3DData *outS3D);
374 
375  bool mobileOutOfScene(); //ACA!!! MIRAR QUE HACE
376  void generateFirstClassifiedSequence();
377  void setBestS3DSequence(std::deque<SpBlob>::iterator first_blob_it, int frame_index, int newBufferSize);
378  void generateMostCoherentS3DSequence(std::deque<SpBlob>::iterator first_blob_it, Shape3DData *firstClassified, int newBufferSize, int frame_index, ObjectType current_type, int current_index);
379 
380  double probabilisticCoherenceReliability(double data, double mean, double sigma, double acuity);
381 
382  double initialSDEstimateFor2DHorizontalAttribute();
383  double initialSDEstimateFor2DVerticalAttribute();
384 
385  void setSpecialBBoxToAnalyze(Rectangle<int> *bboxResult, Rectangle<int> *realBBox, double visualSupport);
386 
387  void setInitialNormalList(Blob *current_blob);
388 
389  bool coherentWithRespectOfCurrent3DInformation(Shape3DData *s3d);
390 
391  void repositionS3D(Shape3DData *s3d, double x, double y);
392 
393  void orient3DModel(Shape3DData *improved3DInfo, Rectangle<int> *improvedBBox, DetectionProblemType dptype);
394 
395  Shape3DData *generateBestLikelyS3D(Blob *blob, ObjectType type);
396 
397  Shape3DData *getBestS3D(bool &lastUnknown, Blob *current_blob);
398 
399  void getMobile3DTolerances(double *Wtol, double *Htol);
400  };
401 
402 
404 
405 #endif
Definition: MobileObject.h:56
Definition: MobileObject.h:25
Definition: MobileObject.h:78
Definition: blob.h:364
Definition: MobileObject.h:93
Definition: MobileObject.h:19
Definition: MobileObject2D.h:36
Definition: MobileObject2D.h:24
Definition: blob.h:34
Definition: calibration.h:51
Definition: MobileObject.h:40
Definition: ReliabilityClassification.h:37
Definition: MobileObject.h:97
Definition: MobileObject2D.h:46
Definition: blob.h:79
Definition: trajectory.h:20
Definition: BackgroundRecLigth.h:20
Definition: MobileObject.h:101