VAT  3.0
Video Analysis Tool
calibration.h
1 #ifndef CALIBRATION_H
2 #define CALIBRATION_H
3 
4 #include "QtXml/QDomDocument"
5 #include <QtXml/QDomElement>
6 #include <QtXml/QDomText>
7 #include <QSharedPointer>
8 #include <QTransform>
9 #include <string>
10 #include "world_def.h"
11 
12 #define SM_CALIB_MATRIX(model) (model->p_matrix)
13 #define SM_HOMOGRAPHY(model) (model->h_matrix)
14 
15 #define SM_CAMERA_X_FOC_POINT(sm) ((sm)->camera_focal_point->x)
16 #define SM_CAMERA_Y_FOC_POINT(sm) ((sm)->camera_focal_point->y)
17 #define SM_CAMERA_Z_FOC_POINT(sm) ((sm)->camera_focal_point->z)
18 
19 #define SM_CAMERA_X2D_FOC_POINT(sm) ((sm)->camera_focal_point2D->x)
20 #define SM_CAMERA_Y2D_FOC_POINT(sm) ((sm)->camera_focal_point2D->y)
21 
22 template<typename T>
23 class point2D;
24 
25 template<typename T>
26 class point3D;
27 
28 //Position relative to blob or other inner model
29 enum position {
30  MiddleCenter = 0x0000, //0000000000000000 : Position at center-middle of blob
31  Left = 0x0001, //0000000000000001 : Position at left-middle of blob
32  Right = 0x0002, //0000000000000010 : Position at right-middle of blob
33  Top = 0x0004, //0000000000000100 : Position at center-top of blob
34  Bottom = 0x0008, //0000000000001000 : Position at center-bottom of blob
35  TopLeft = 0x0005, //0000000000000101 : Position at left-top of blob
36  BottomLeft = 0x0009, //0000000000001001 : Position at left-bottom of blob
37  TopRight = 0x0006, //0000000000000110 : Position at left-top of blob
38  BottomRight = 0x000a, //0000000000001010 : Position at left-bottom of blob
39 };
40 
41 //enum for characterising which kind of zone is being used
42 enum zoneType {
43  Z_NONE,
44  Z_2D,
45  Z_3D,
46  Z_H,
47 };
48 
49 typedef enum zoneType zoneType;
50 
51 class SceneModel {
52  public:
53  QSharedPointer<point3D<double> > camera_focal_point;
54  QSharedPointer<point2D<double> > camera_focal_point2D;
55  perspective_matrix p_matrix;
56  homography_matrix h_matrix;
57  QTransform h_trans, h_trans_i;
58  bool pmatrix_filled;
59  bool hmatrix_filled;
60  bool badFocal;
61 
62  //Perspective transform context
63  std::vector< QSharedPointer<world::ContextObject> > contextObjects;
64  //Area of Interest defined with a set of zones
65  std::vector< QSharedPointer<world::AOI> > AOIs;
66  std::vector< QSharedPointer<world::Area> > Areas;
67  std::vector< QSharedPointer<world::Zone> > Zones;
68  std::vector< QSharedPointer<world::Wall> > walls;
69  std::vector< QSharedPointer<world::Wall2D> > wall2Ds;
70 
71  //Homography Zones
72  std::vector< QSharedPointer<world::ZoneH> > ZonesH;
73 
74  std::vector< QSharedPointer<world::Zone2D> > Zones2D;
75 
76  QDomDocument *xmlScene;
77 
78  double m_OneMeterRepresentation;
79  double m_MaximalObjectSpeed;
80 
81  SceneModel();
82  ~SceneModel();
83 
84  bool readScene(QString fileName);
85  bool readParameters(QString fileName);
86  bool readObjectModels(QString fileName);
87 
88  static position setPosition(std::string pos);
89  static void getXY(position pos, double &X, double &Y, Blob b);
90 
91  //Compute the image coordinates of a point from its world coordinates. The
92  //image coordinates arguments are pointers to double to indicate where to
93  //store results. If some of these pointers are NULL, the corresponding
94  //results are not computed.
95  static int worldToImgCoords(perspective_matrix persp_mat,
96  double x, double y, double z,
97  double *X, double *Y);
98 
99  //Compute the image coordinates of a point from its homography coordinates.
100  //The image coordinates arguments are pointers to double to indicate where to
101  //store results. If some of these pointers are NULL, the corresponding
102  //results are not computed.
103  static int homographyToImgCoords(homography_matrix H,
104  double X2, double Y2,
105  double *X, double *Y);
106 
107 
108 
109  // Compute the world coordinates of a point from its image coordinates and
110  // a given height. The world coordinate arguments are pointers to double
111  // to indicate where to store results. If some of these pointers are NULL,
112  // the corresponding results are not computed.
113  static int imgToWorldCoordsGivenHeight(perspective_matrix persp_mat,
114  double X, double Y, double z,
115  double *x, double *y);
116 
117  // Compute the homography coordinates of a point from its image coordinates.
118  // The world coordinate arguments are pointers to double
119  // to indicate where to store results. If some of these pointers are NULL,
120  // the corresponding results are not computed.
121  static int imgToHomographyCoords(homography_matrix H,
122  double X, double Y,
123  double *X2, double *Y2);
124 
125 
126  bool computeFocalPoint(perspective_matrix pp, int img_width, int img_height,
127  double *camx, double *camy, double *camz);
128 
129  double getLimitHeightForProjectionLine(double x, double y);
130  double getLowestImageIntersectingHeight(int W, int H, double x, double y);
131 
132 };
133 
134 
135 #endif // CALIBRATION_H
Definition: calibration.h:51
Definition: calibration.h:26
Definition: calibration.h:23
Definition: blob.h:79