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