Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | PointedEar | 1 | /*------------------------------------------------------------------------------------------*\ |
2 | This file contains material supporting chapter 9 of the cookbook: |
||
5 | PointedEar | 3 | Computer Vision Programming using the OpenCV Library. |
4 | by Robert Laganiere, Packt Publishing, 2011. |
||
3 | PointedEar | 5 | |
5 | PointedEar | 6 | This program is free software; permission is hereby granted to use, copy, modify, |
7 | and distribute this source code, or portions thereof, for any purpose, without fee, |
||
8 | subject to the restriction that the copyright notice may not be removed |
||
9 | or altered from any source or altered source distribution. |
||
10 | The software is released on an as-is basis and without any warranties of any kind. |
||
11 | In particular, the software is not guaranteed to be fault-tolerant or free from failure. |
||
12 | The author disclaims all warranties with regard to this software, any use, |
||
13 | and any consequent failure, is purely the responsibility of the user. |
||
3 | PointedEar | 14 | |
5 | PointedEar | 15 | Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
16 | \*------------------------------------------------------------------------------------------*/ |
||
3 | PointedEar | 17 | |
18 | #ifndef CAMERACALIBRATOR_H |
||
19 | #define CAMERACALIBRATOR_H |
||
20 | |||
21 | #include <vector> |
||
22 | #include <iostream> |
||
23 | |||
24 | #include <opencv2/core/core.hpp> |
||
25 | #include "opencv2/imgproc/imgproc.hpp" |
||
26 | #include "opencv2/calib3d/calib3d.hpp" |
||
27 | #include <opencv2/highgui/highgui.hpp> |
||
28 | |||
5 | PointedEar | 29 | class CameraCalibrator |
30 | { |
||
3 | PointedEar | 31 | |
5 | PointedEar | 32 | // input points |
33 | std::vector<std::vector<cv::Point3f> > objectPoints; |
||
34 | std::vector<std::vector<cv::Point2f> > imagePoints; |
||
35 | // output Matrices |
||
36 | cv::Mat cameraMatrix; |
||
37 | cv::Mat distCoeffs; |
||
38 | // flag to specify how calibration is done |
||
39 | int flag; |
||
40 | // used in image undistortion |
||
41 | cv::Mat map1, map2; |
||
42 | bool mustInitUndistort; |
||
3 | PointedEar | 43 | |
5 | PointedEar | 44 | public: |
45 | CameraCalibrator() : |
||
46 | flag(0), mustInitUndistort(true) |
||
47 | { |
||
48 | } |
||
49 | ; |
||
3 | PointedEar | 50 | |
5 | PointedEar | 51 | // Open the chessboard images and extract corner points |
52 | int |
||
53 | addChessboardPoints(const std::vector<std::string>& filelist, |
||
54 | cv::Size & boardSize); |
||
55 | // Add scene points and corresponding image points |
||
56 | void |
||
57 | addPoints(const std::vector<cv::Point2f>& imageCorners, |
||
58 | const std::vector<cv::Point3f>& objectCorners); |
||
59 | // Calibrate the camera |
||
60 | double |
||
61 | calibrate(cv::Size imageSize); |
||
62 | // Set the calibration flag |
||
63 | void |
||
64 | setCalibrationFlag(bool radial8CoeffEnabled = false, |
||
65 | bool tangentialParamEnabled = false); |
||
66 | // Remove distortion in an image (after calibration) |
||
67 | cv::Mat |
||
68 | remap(const cv::Mat &image); |
||
3 | PointedEar | 69 | |
5 | PointedEar | 70 | // Getters |
71 | cv::Mat |
||
72 | getCameraMatrix() |
||
73 | { |
||
74 | return cameraMatrix; |
||
75 | } |
||
76 | cv::Mat |
||
77 | getDistCoeffs() |
||
78 | { |
||
79 | return distCoeffs; |
||
80 | } |
||
3 | PointedEar | 81 | }; |
82 | |||
83 | #endif // CAMERACALIBRATOR_H |