stereo-vision
All Data Structures Namespaces Functions Modules Pages
camera.h
1 /*
2  * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3  * Authors: Vadim Tikhanoff
4  * email: vadim.tikhanoff@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txtd
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
19 #include <iostream>
20 #include <string>
21 
22 #include <opencv2/opencv.hpp>
23 
24 using namespace std;
25 using cv::Mat;
26 using cv::Point2f;
27 using cv::Size;
28 using cv::Point3f;
29 using cv::FileStorage;
30 using cv::FileNodeIterator;
31 using cv::FileNode;
32 using cv::DescriptorExtractor;
40 class Camera
41 {
42 private:
43  Mat K; // Intrinsic Parameters 3x3
44  Mat P; // Camera Matrix 3x4
45  Mat Dist; // Distortion Coefficents Vector 4x1
46  bool readStringList( const string& filename, vector<string>& l );
47  bool prepareandRunCalibration(const vector<vector<Point2f> >& imagePoints,
48  Size imageSize, Size boardSize, float squareSize,
49  float aspectRatio, int flags, Mat& cameraMatrix,
50  Mat& distCoeffs);
51  bool runCalibration( vector<vector<Point2f> > imagePoints,
52  Size imageSize, Size boardSize,
53  float squareSize, float aspectRatio,
54  int flags, Mat& cameraMatrix, Mat& distCoeffs,
55  vector<Mat>& rvecs, vector<Mat>& tvecs,
56  vector<float>& reprojErrs,
57  double& totalAvgErr);
58  void calcChessboardCorners(Size boardSize, float squareSize, vector<Point3f>& corners);
59  double computeReprojectionErrors(
60  const vector<vector<Point3f> >& objectPoints,
61  const vector<vector<Point2f> >& imagePoints,
62  const vector<Mat>& rvecs, const vector<Mat>& tvecs,
63  const Mat& cameraMatrix, const Mat& distCoeffs,
64  vector<float>& perViewErrors );
65  void printMatrix(Mat &matrix);
66  void printCameraMatrix();
67  void printDistortionVector();
68  void calibrate(string imagesFilePath, int boardWidth, int boardHeight);
69 
70 public:
71 
76  Camera(string intrinsicFilePath);
77 
82  Camera() {};
83 
90  void calibrate(vector<string> imageList, int boardWidth, int boardHeight);
91 
96  bool saveCalibration(string intrinsicFilePath);
97 
103  Mat undistortImage(Mat image);
104 
105 
110  Mat getCameraMatrix();
111 
116  Mat getDistVector();
117 
122  void setCameraMatrix(Mat& K);
123 
128  void setDistCoefficients(Mat& Dist);
129 };
The base class defining a simple camera.
Definition: camera.h:41
Camera()
Default Constructor.
Definition: camera.h:82