calibfilter.h
Go to the documentation of this file.
1 #ifndef CALIBFILTER_H
2 #define CALIBFILTER_H
3 
4 // This has been copied from the OpenCV 2 source since the calibration filter
5 // is no longer part of OpenCV 3.
6 
7 #include <opencv2/opencv.hpp>
8 //#include <OpenCVLegacy.h>
9 
10 /************ Epiline functions *******************/
11 
12 
13 
14 //typedef struct CvStereoLineCoeff
15 //{
16 // double Xcoef;
17 // double XcoefA;
18 // double XcoefB;
19 // double XcoefAB;
20 //
21 // double Ycoef;
22 // double YcoefA;
23 // double YcoefB;
24 // double YcoefAB;
25 //
26 // double Zcoef;
27 // double ZcoefA;
28 // double ZcoefB;
29 // double ZcoefAB;
30 //} CvStereoLineCoeff;
31 //
32 //
33 //typedef struct CvCamera
34 //{
35 // float imgSize[2]; /* size of the camera view, used during calibration */
36 // float matrix[9]; /* intinsic camera parameters: [ fx 0 cx; 0 fy cy; 0 0 1 ] */
37 // float distortion[4]; /* distortion coefficients - two coefficients for radial distortion
38 // and another two for tangential: [ k1 k2 p1 p2 ] */
39 // float rotMatr[9];
40 // float transVect[3]; /* rotation matrix and transition vector relatively
41 // to some reference point in the space. */
42 //} CvCamera;
43 //
44 //typedef struct CvStereoCamera
45 //{
46 // CvCamera* camera[2]; /* two individual camera parameters */
47 // float fundMatr[9]; /* fundamental matrix */
48 //
49 // /* New part for stereo */
50 // CvPoint3D32f epipole[2];
51 // CvPoint2D32f quad[2][4]; /* coordinates of destination quadrangle after
52 // epipolar geometry rectification */
53 // double coeffs[2][3][3];/* coefficients for transformation */
54 // CvPoint2D32f border[2][4];
55 // CvSize warpSize;
56 // CvStereoLineCoeff* lineCoeffs;
57 // int needSwapCameras;/* flag set to 1 if need to swap cameras for good reconstruction */
58 // float rotMatrix[9];
59 // float transVector[3];
60 //} CvStereoCamera;
61 
62 #define CV_CAMERA_TO_WARP 1
63 #define CV_WARP_TO_CAMERA 2
64 
65 
66 /****************************************************************************************\
67 * Calibration engine *
68 \****************************************************************************************/
69 
70 typedef enum CvCalibEtalonType
71 {
75 }
77 
78 class CV_EXPORTS CvCalibFilter
79 {
80 public:
81  /* Constructor & destructor */
82  CvCalibFilter();
83  virtual ~CvCalibFilter();
84 
85  /* Sets etalon type - one for all cameras.
86  etalonParams is used in case of pre-defined etalons (such as chessboard).
87  Number of elements in etalonParams is determined by etalonType.
88  E.g., if etalon type is CV_ETALON_TYPE_CHESSBOARD then:
89  etalonParams[0] is number of squares per one side of etalon
90  etalonParams[1] is number of squares per another side of etalon
91  etalonParams[2] is linear size of squares in the board in arbitrary units.
92  pointCount & points are used in case of
93  CV_CALIB_ETALON_USER (user-defined) etalon. */
94  virtual bool
95  SetEtalon(CvCalibEtalonType etalonType, double* etalonParams,
96  int pointCount = 0, CvPoint2D32f* points = 0);
97 
98  /* Retrieves etalon parameters/or and points */
99  virtual CvCalibEtalonType
100  GetEtalon(int* paramCount = 0, const double** etalonParams = 0,
101  int* pointCount = 0, const CvPoint2D32f** etalonPoints = 0) const;
102 
103  /* Sets number of cameras calibrated simultaneously. It is equal to 1 initially */
104  virtual void SetCameraCount(int cameraCount);
105 
106  /* Retrieves number of cameras */
107  int GetCameraCount() const
108  {
109  return cameraCount;
110  }
111 
112  /* Starts cameras calibration */
113  virtual bool SetFrames(int totalFrames);
114 
115  /* Stops cameras calibration */
116  virtual void Stop(bool calibrate = false);
117 
118  /* Retrieves number of cameras */
119  bool IsCalibrated() const
120  {
121  return isCalibrated;
122  }
123 
124  /* Feeds another serie of snapshots (one per each camera) to filter.
125  Etalon points on these images are found automatically.
126  If the function can't locate points, it returns false */
127  virtual bool FindEtalon(IplImage** imgs);
128 
129  /* The same but takes matrices */
130  virtual bool FindEtalon(CvMat** imgs);
131 
132  /* Lower-level function for feeding filter with already found etalon points.
133  Array of point arrays for each camera is passed. */
134  virtual bool Push(const CvPoint2D32f** points = 0);
135 
136  /* Returns total number of accepted frames and, optionally,
137  total number of frames to collect */
138  virtual int GetFrameCount(int* framesTotal = 0) const;
139 
140  /* Retrieves camera parameters for specified camera.
141  If camera is not calibrated the function returns 0 */
142  virtual const CvCamera* GetCameraParams(int idx = 0) const;
143 
144  virtual const CvStereoCamera* GetStereoParams() const;
145 
146  /* Sets camera parameters for all cameras */
147  virtual bool SetCameraParams(CvCamera* params);
148 
149  /* Saves all camera parameters to file */
150  virtual bool SaveCameraParams(const char* filename);
151 
152  /* Loads all camera parameters from file */
153  virtual bool LoadCameraParams(const char* filename);
154 
155  /* Undistorts images using camera parameters. Some of src pointers can be NULL. */
156  virtual bool Undistort(IplImage** src, IplImage** dst);
157 
158  /* Undistorts images using camera parameters. Some of src pointers can be NULL. */
159  virtual bool Undistort(CvMat** src, CvMat** dst);
160 
161  /* Returns array of etalon points detected/partally detected
162  on the latest frame for idx-th camera */
163  virtual bool GetLatestPoints(int idx, CvPoint2D32f** pts,
164  int* count, bool* found);
165 
166  /* Draw the latest detected/partially detected etalon */
167  virtual void DrawPoints(IplImage** dst);
168 
169  /* Draw the latest detected/partially detected etalon */
170  virtual void DrawPoints(CvMat** dst);
171 
172  virtual bool Rectify(IplImage** srcarr, IplImage** dstarr);
173  virtual bool Rectify(CvMat** srcarr, CvMat** dstarr);
174 
175 protected:
176 
177  enum { MAX_CAMERAS = 3 };
178 
179  /* etalon data */
182  double* etalonParams;
184  CvPoint2D32f* etalonPoints;
185  CvSize imgSize;
186  CvMat* grayImg;
187  CvMat* tempImg;
188  CvMemStorage* storage;
189 
190  /* camera data */
192  CvCamera cameraParams[MAX_CAMERAS];
193  CvStereoCamera stereo;
194  CvPoint2D32f* points[MAX_CAMERAS];
195  CvMat* undistMap[MAX_CAMERAS][2];
196  CvMat* undistImg;
197  int latestCounts[MAX_CAMERAS];
198  CvPoint2D32f* latestPoints[MAX_CAMERAS];
199  CvMat* rectMap[MAX_CAMERAS][2];
200 
201  /* Added by Valery */
202  //CvStereoCamera stereoParams;
203 
208 };
209 
210 #endif // CALIBFILTER_H
CV_CALIB_ETALON_CHECKERBOARD
@ CV_CALIB_ETALON_CHECKERBOARD
Definition: calibfilter.h:74
CvCalibFilter::imgSize
CvSize imgSize
Definition: calibfilter.h:185
CvCalibFilter::etalonParams
double * etalonParams
Definition: calibfilter.h:182
CvCalibFilter::tempImg
CvMat * tempImg
Definition: calibfilter.h:187
CvCalibFilter::isCalibrated
bool isCalibrated
Definition: calibfilter.h:207
CvCalibFilter::stereo
CvStereoCamera stereo
Definition: calibfilter.h:193
CvCalibFilter::undistImg
CvMat * undistImg
Definition: calibfilter.h:196
CvCalibFilter::cameraCount
int cameraCount
Definition: calibfilter.h:191
CvCalibFilter::framesAccepted
int framesAccepted
Definition: calibfilter.h:206
CvCalibFilter::etalonPoints
CvPoint2D32f * etalonPoints
Definition: calibfilter.h:184
CvCalibFilter::IsCalibrated
bool IsCalibrated() const
Definition: calibfilter.h:119
CvCalibFilter::grayImg
CvMat * grayImg
Definition: calibfilter.h:186
CvCalibFilter::framesTotal
int framesTotal
Definition: calibfilter.h:205
filename
std::string filename
Definition: VisualizationRobot.cpp:83
CvCalibFilter::etalonPointCount
int etalonPointCount
Definition: calibfilter.h:183
CV_CALIB_ETALON_CHESSBOARD
@ CV_CALIB_ETALON_CHESSBOARD
Definition: calibfilter.h:73
CvCalibEtalonType
CvCalibEtalonType
Definition: calibfilter.h:70
CvCalibFilter::storage
CvMemStorage * storage
Definition: calibfilter.h:188
CvCalibFilter::maxPoints
int maxPoints
Definition: calibfilter.h:204
CV_CALIB_ETALON_USER
@ CV_CALIB_ETALON_USER
Definition: calibfilter.h:72
CvCalibFilter::etalonParamCount
int etalonParamCount
Definition: calibfilter.h:181
CvCalibFilter::etalonType
CvCalibEtalonType etalonType
Definition: calibfilter.h:180
CvCalibFilter::GetCameraCount
int GetCameraCount() const
Definition: calibfilter.h:107
CvCalibFilter
Definition: calibfilter.h:78