主要是参照opencv2那本书,注视写的都很详细,方便以后查找!
CameraCalibrator.h头文件
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/calib3d/calib3d.hpp>
class CameraCalibrator
{
private:
// 输入点
//位于世界坐标的点
std::vector<std::vector<cv::Point3f>> objectPoints;
//像素坐标的点
std::vector<std::vector<cv::Point2f>> imagePoints;
std::vector<cv::Mat> rvecs, tvecs;
// 输出矩阵,内参数阵和畸变系数真
cv::Mat cameraMatrix;
cv::Mat distCoeffs;
cv::Mat cameraRotation ;//保存外参数矩阵
cv::Mat cameraTranslation ;//保存平移量
// 标定的方式
int flag;
// 用于图像去畸变
cv::Mat map1,map2;
bool mustInitUndistort;
public:
CameraCalibrator() : flag(0), mustInitUndistort(true) {};
// 打开棋盘图像并提取角点
int addChessboardPoints(const std::vector<std::string>& filelist, cv::Size & boardSize);
void addPoints(const std::vector<cv::Point2f>& imageCorners, const std::vector<cv::Point3f>& objectCorners);
double calibrate(cv::Size &imageSize);
void setCalibrationFlag(bool radial8CoeffEnabled=false, bool tangentialParamEnabled=false);
cv::Mat CameraCalibrator::remap(const cv::Mat &image);
//获取指定棋盘格的外方位矩阵
void CalExtrinx(int i) ;
//获得相机的内参数矩阵
cv::Mat getCameraExtrinsic(){
return cameraRotation ;}
void saveRotation(std::string str) ;
//获取相机的内参数矩阵
cv::Mat getCameraMatrix() { return cameraMatrix; }
//保存相机的内参数矩阵
void saveCameraMatrix(std::string str) ;
//获得指定棋盘格的平移量
cv::Mat getTranslations(){ return cameraTranslation ;}
//保存平移量
void saveTranslations(std::string str) ;
//获取相机的畸变系数
cv::Mat getDistCoeffs() { return distCoeffs; }
void printMatrix(const cv::Mat matrix) ;
//读取棋盘格列表
void readImagelist(const