Subversion Repositories OpenCV2-Cookbook

Rev

Rev 3 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 5
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
Line 39... Line 40...
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