VAT  3.0
Video Analysis Tool
shapeModel.h
1 #ifndef SHAPEMODEL_H
2 #define SHAPEMODEL_H
3 
4 #include <QDomNode>
5 #include <QImage>
6 #include <vector>
7 #include <QSharedPointer>
8 
9 #include "reliabilitysinglemodelinterface.h"
10 #include "src/blob.h"
11 #include "Blob2DFromBGSubstractionModel.h"
12 
13 #include "src/hullmodel.h"
14 
15 //#include "opencv/cv.h";
16 
17 class Datapool;
18 
20 public:
21  ShapeModel(int buffer_size);
22 
23  virtual ~ShapeModel();
24 
25  //IMPLEMENT!! Initializes the model attributes for the interface.
26  //The function is called by the interface constructor
27  virtual void initInstanceAttributes();
28 
29  //IMPLEMENT!! Initializes the dynamics model attributes for the interface.
30  //The function is called by the interface constructor
31  virtual void initDynamicsAttributes();
32 
33  //IMPLEMENT!! Copy function for specific data from the instance (general_copy calls it after copying base info)
34  virtual void copy(SpReliabilitySingleModelInterface);
35 
36  //IMPLEMENT!! Copy general structures and parameters of specific model, without considering instance specific data
37  virtual void copy_structure(SpReliabilitySingleModelInterface);
38 
39  //IMPLEMENT!! sets parameters from xml file
40  virtual void setParameters(QDomNode &i_parameters);
41 
42  //IMPLEMENT!! sets activation criteria for each model: reliability on input (distance, bad data),
43  // needs (occlusion, priority),
44  //sets priority of models (hierarchy).
45  //Checked before update phase
46  virtual void activate(BoundingBox &);
47 
48  //IMPLEMENT!! initializes every activated model, according to their own input (region-blob-segments schema)
49  //Executed only once at the begginning of single model creation (after 'copy_structure' and 'copy' methods
50  //are used to copy the information).
51  virtual void init();
52 
53  //IMPLEMENT!! updates activated model instance attributes for current frame, and returns the set of detected/enriched objects.
54  // It notifies if roi (bounding box, or segmentation) changes compared to the input, for reprocessing.
55  virtual bool updateInstance(BoundingBox &, std::set<SpRMMHypothesis, hypothesesOrderedByBestProbabilityOperator> &);
56 
57  //IMPLEMENT!! updates activated model instance attributes for current frame and object, and returns the detected/enriched object.
58  // It notifies if roi (bounding box, or segmentation) changes compared to the input, for reprocessing.
59  // This function does NOT generate mobiles or hypotheses. It processes attributes for the current object.
60  // This function could be used by updateInstance to generate mobile information, for the generated mobiles.
61  // IT MUST INSERT A NEW ModelInstanceDataPack IN instances buffer and update ginfo attribute of the ModelInstanceDataPack
62  // properly (see ModelInstanceGeneralPack).
63  // IF CALLED INSIDE ONE METHOD OF THIS CLASS, IT MUST INCLUDE A CALL TO METHOD: updateCurrentGeneralInfo();
64  // ALSO WHEN CREATING NEW OBJECTS (IT MUST BE CALLED FOR THE CREATED OBJECT).
65  virtual void updateSingleInstance(BoundingBox &);
66 
67  //IMPLEMENT!! updates model dynamics, based on instances information: work on post_dynamics structure
68  virtual void updateModelDynamics();
69 
70  //Visualization
71 
72  virtual bool draw(QPainter &painter, int r, int g, int b);
73 
74  //Starts dynamics in multimodel and calls specific model dynamics with updateModelDynamics();
75  void updateDynamics();
76 
77  //sets global probability P for the model (how good is the model)
78  //sets global reliability R for the model (how good is the data used in the model)
79  virtual void setProbabilityAndReliability();
80 
81  //sets data pack general information of the model in forward process (update)
82  virtual void setForwardInterface();
83 
84  //Get 2D central bounding box point from the model
85  //virtual void setTrajectory2D(double &, double &, double &);
86 
87  //Estimates the bounding box size and position for next
88  //frame according to its own dynamics model
89  //It also sets Reliability R of the model estimation.
90  //The function defaults to the 'binterface' bounding box.
91  //Nevertheless, a better implementation really depending on the
92  //specific dynamics model is expected.
93  //virtual BoundingBox getEstimator(double &R);
94 
95 
96 
97  // -----------------FUNCIONES DEGU
98 
99  bool shapeAnalysis(float &headX, float &headY, float &dirX, float &dirY, float &bodyX, float &bodyY,BoundingBox &ro);
100 
101 
102  SpHullModel deguShape;
103  QImage muestra;
104  bool todoListo;
105 
106 
107 
108  static bool movementFound(cv::Mat f, int wsize, int i0, int j0);
109  static bool movementFound(cv::Mat f, int wsize, int i0, int j0, cv::Rect roi);
110  static double histogramDistance(cv::MatND h1, cv::MatND h2);
111  static double distanceToSegment(int i1, int i2, std::vector<cv::Point> &contour);
112  static bool lineSegmentIntersection(cv::Point3f &line,
113  cv::Point2f &p1, cv::Point2f &p2, cv::Point2f &r);
114  static bool getGeneralLineForm(cv::Point2f p1, cv::Point2f p2,
115  cv::Point3f &rline);
116  static bool getGeneralLineForm(float x, float y, float dx, float dy,
117  cv::Point3f &rline);
118 
119 
120  //Get intersection points r1 and r2 between line 'rline' and contour 'hull' (oriented to
121  //convex hull). If non NULL n1 and n2 pointers, are used to store indexes of contour segments
122  //where intersections were found (to be used later on pixel distance function construction).
123  static int getContourToLineIntersection(std::vector<cv::Point> &hull,
124  cv::Point3f &rline,
125  cv::Point2f &r1, cv::Point2f &r2,
126  int *n1 = NULL, int *n2 = NULL);
127 
128  //Fills a segments vector with moving pixel bounds for each normal on the axis
129  void getNormalIntersections(cv::Mat &f, cv::Rect &roi, std::vector<cv::Point> &hull,
130  cv::Point2f &r1, cv::Point2f &r2, int n1, int n2,
131  float dx, float dy, std::vector< segment2D<float> > &segs,
132  std::vector< segment2D<float> > &hull_segs);
133 
134  //Sets the moving segment for one normal
135  void setForegroundSegment(cv::Mat &f, cv::Rect &roi, std::vector<cv::Point> &hull,
136  segment2D<float> &seg, segment2D<float> &hseg, float x, float y,
137  float dx, float dy, int &I1, int &I2);
138 
139 
140  //Gets the intersection betweel a line and a contour, in current or next contour
141  //segment.
142  static int getContourToLineIntersectionIndexed(std::vector<cv::Point> &polygon,
143  cv::Point3f &rline,
144  cv::Point2f &r1, cv::Point2f &r2,
145  int &n1, int &n2);
146 
147  //Counts foreground pixels on a window
148  static int movementCount(cv::Mat f, int wsize, int i0, int j0, cv::Rect roi);
149 
150  void findHead(SpHullModel hull);
151 
152 
153  cv::Point2f headLocation;
154 
155 
156  void displayShowHull(QPainter &painter, SpHullModel hull);
157  void displayShowAxis(QPainter &painter, SpHullModel hull);
158  void displayShowNormals(QPainter &painter, SpHullModel hull);
159  void displayBackBone(QPainter &painter, SpHullModel hull);
160 
161 
162  void backBoneAnalysis(SpHullModel hull);
163 
164  bool readyBackBone;
165  float ay, by, cy, ax, bx, cx;
166 
167  bool drawBackBoneCurve(QPainter &painter,SpHullModel hull);
168  bool drawHeadDirection(QPainter &painter,SpHullModel hull);
169 
170  bool drawHeadRealDirection(QPainter &painter,SpHullModel hull);
171 
172  float napeRatio;
173  float distance;
174 
175  std::vector< segment2D<float> > uncertaintyPoint;
176  std::vector< segment2D<float> > uncertaintyDirection;
177 
178  bool uncertainMode;
179  bool alreadyDirect;
180  int axisDirection;
181 
182  std::vector< cv::Point2f > headPoint;
183  std::vector< cv::Point2f > headDirection;
184 
185  int framesToBeUncertain;
186 
187 
188  bool analysesDirection(float &dirHeadX,float &dirHeadY,float &dirHipsX,float &dirHipsY,SpHullModel hull);
189 
190 
191  bool drawFlagHull;
192  bool drawFlagAxis;
193  bool drawFlagNormals;
194  bool drawFlagBackBone;
195  bool drawFlagBoneCurve;
196  bool drawFlagHeadDirection;
197  bool drawFlagHeadRealDirection;
198 
199  float speedThreshold;
200  int frameThreshold;
201 
202  bool findTail(SpHullModel hull);
203 
204  float massThreshold;
205 
206  void opticalFlow();
207  void stopOpticalFlow();
208 
209  cv::Mat lastImage;
210 
211  bool opticalFlowRunning;
212 
213  BoundingBox actualBlob;
214 
215  cv::Rect opticalFlowBox;
216 
217  //cv::OutputArray lastPoint;
218  //cv::OutputArray currentPoint;
219 
220  std::vector<cv::Point2f> lastPoint;
221  std::vector<cv::Point2f> currentPoint;
222 
223  void drawEntropy(QPainter &painter);
224 
225  cv::Point2f surf(std::vector<cv::Point2f> vectors);
226 
227  void quickSortAngle(std::vector<cv::Point2f> &vectors, std::vector<float> &angles, int init, int end);
228 
229 
230  void drawResultOpticalVector(QPainter &painter, SpHullModel hull);
231 
232  void drawHead(QPainter &painter, SpHullModel hull);
233 
234  cv::Point2f vectorSums(std::vector<cv::Point2f> vectors, std::vector<cv::Point2f> points,SpHullModel hull);
235 
236  cv::Point2f lastHeadPoint;
237  cv::Point2f actualHeadPoint;
238 
239  bool drawTail(QPainter &painter,SpHullModel hull);
240 
241  cv::Point2f vectorSumsPivote(std::vector<cv::Point2f> vectors, std::vector<cv::Point2f> points,SpHullModel hull, cv::Point2f pivote);
242 
243  cv::Point2f opticalRotation(std::vector<cv::Point2f> vectors, std::vector<cv::Point2f> points,SpHullModel hull);
244 
245 
246  std::vector<cv::Point2f> wannabeSurfResult;
247  std::vector<cv::Point2f> sumaResult;
248  std::vector<cv::Point2f> sumaPivoteResult;
249  std::vector<cv::Point2f> opticalRotationResult;
250 
251  cv::Point2f lastMiddlePoint;
252 
253  int findTailAlgorithm(SpHullModel hull);
254 
255 
256 };
257 
258 
259 #endif // SHAPEMODEL_H
Definition: geometric.h:103
cv::Point2f opticalRotation(std::vector< cv::Point2f > vectors, std::vector< cv::Point2f > points, SpHullModel hull)
ShapeModel::opticalRotation. Metodo que calcula la rotacion del objeto despues de aplicar un optical ...
Definition: shapeModel.cpp:3726
Definition: reliabilitysinglemodelinterface.h:96
bool shapeAnalysis(float &headX, float &headY, float &dirX, float &dirY, float &bodyX, float &bodyY, BoundingBox &ro)
Definition: shapeModel.cpp:464
Definition: shapeModel.h:19
virtual void setProbabilityAndReliability()
Definition: shapeModel.cpp:350
virtual void updateModelDynamics()
Definition: shapeModel.cpp:321
An object of this class is instantiated at main code, and this object is used by every class to push ...
Definition: Datapool.h:39
int findTailAlgorithm(SpHullModel hull)
ShapeModel::findTailAlgorithm Algoritmo de deteccion de cola.
Definition: shapeModel.cpp:3902
bool drawTail(QPainter &painter, SpHullModel hull)
ShapeModel::drawTail DEPRECATED.
Definition: shapeModel.cpp:2875