Subversion Repositories OpenCV2-Cookbook

Rev

Go to most recent revision | Details | 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:  
3
   Computer Vision Programming using the OpenCV Library.
4
   by Robert Laganiere, Packt Publishing, 2011.
5
 
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.
14
 
15
   Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
16
\*------------------------------------------------------------------------------------------*/
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
 
29
class CameraCalibrator {
30
 
31
        // input points
32
    std::vector<std::vector<cv::Point3f>> objectPoints;
33
    std::vector<std::vector<cv::Point2f>> imagePoints;
34
    // output Matrices
35
    cv::Mat cameraMatrix;
36
    cv::Mat distCoeffs;
37
        // flag to specify how calibration is done
38
        int flag;
39
        // used in image undistortion 
40
    cv::Mat map1,map2;
41
        bool mustInitUndistort;
42
 
43
  public:
44
        CameraCalibrator() : flag(0), mustInitUndistort(true) {};
45
 
46
        // Open the chessboard images and extract corner points
47
        int addChessboardPoints(const std::vector<std::string>& filelist, cv::Size & boardSize);
48
        // Add scene points and corresponding image points
49
    void addPoints(const std::vector<cv::Point2f>& imageCorners, const std::vector<cv::Point3f>& objectCorners);
50
        // Calibrate the camera
51
        double calibrate(cv::Size &imageSize);
52
    // Set the calibration flag
53
    void setCalibrationFlag(bool radial8CoeffEnabled=false, bool tangentialParamEnabled=false);
54
        // Remove distortion in an image (after calibration)
55
        cv::Mat CameraCalibrator::remap(const cv::Mat &image);
56
 
57
    // Getters
58
    cv::Mat getCameraMatrix() { return cameraMatrix; }
59
    cv::Mat getDistCoeffs()   { return distCoeffs; }
60
};
61
 
62
#endif // CAMERACALIBRATOR_H