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