资源简介
Mastering Opencv第二章的代码,是基于标识的AR的Opencv实现,对前辈代码中错误进行了修改
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
#endif
using namespace cv;
using namespace std;
//在运行程序前打印帮助信息
static void help()
{
cout << “This is a camera calibration sample.“ << endl
<< “Usage: calibration configurationFile“ << endl
<< “Near the sample file you‘ll find the configuration file which has detailed help of “
“how to edit it. It may be any OpenCV supported file format xml/YAML.“ << endl;
}
//定义一个类,这个类包括读写一个文件,读入一些定义
class Settings
{
public:
Settings() : goodInput(false) {}
enum Pattern { NOT_EXISTING CHESSBOARD CIRCLES_GRID ASYMMETRIC_CIRCLES_GRID };
enum InputType {INVALID CAMERA VIDEO_FILE IMAGE_LIST};
void write(FileStorage& fs) const//写初始化数据到文件//Write serialization for this class,
{
fs << “{“ << “BoardSize_Width“ << boardSize.width//图像宽度
<< “BoardSize_Height“ << boardSize.height//图像高度
<< “Square_Size“ << squareSize//棋盘格大小
<< “Calibrate_Pattern“ << patternToUse//使用的标识,是棋盘格还是圆点
<< “Calibrate_NrOfframeToUse“ << nrframes//若是摄像机输入,要读入25帧进行校正
<< “Calibrate_FixAspectRatio“ << aspectRatio//在输入相机矩阵时,当fy是一个变量时,fx/fy是一个固定的值,1
<< “Calibrate_AssumeZeroTangentialDistortion“ << calibZeroTangentDist//切向畸变参数是否设为0就是不考虑。
<< “Calibrate_FixPrincipalPointAtTheCenter“ << calibFixPrincipalPoint//当全局优化时,主要的点不变化
<< “Write_DetectedFeaturePoints“ << bwritePoints//是否输出特征点坐标
<< “Write_extrinsicParameters“ << bwriteExtrinsics//是否输出相机外参数
<< “Write_outputFileName“ << outputFileName//输出校正矩阵和失真向量的文件
<< “Show_UndistortedImage“ << showUndistorsed//是否显示校正和处理失真后的图像
<< “Input_FlipAroundHorizontalAxis“ << flipVertical
<< “Input_Delay“ << delay//摄像机读入每一帧的时间间隔
<< “Input“ << input//输入模式,相机,视频,图片。
<< “}“;
}
void read(const FileNode& node)//当读初始化参数时,执行interprate()函数。//Read serialization for this class
{
node[“BoardSize_Width“ ] >> boardSize.width;
node[“BoardSize_Height“] >> boardSize.height;
node[“Calibrate_Pattern“] >> patternToUse;
node[“Square_Size“] >> squareSize;
node[“Calibrate_NrOfframeToUse“] >> nrframes;
node[“Calibrate_FixAspectRatio“] >> aspectRatio;
node[“Write_DetectedFeaturePoints“] >> bwritePoints;
node[“Write_extrinsicParameters“] >> bwriteExtrinsics;
node[“Write_outputFileName“] >> outputFileName;
node[“Calibrate_AssumeZeroTangentialDistortion“] >> calibZeroTangentDist;
node[“Calibrate_FixPrincipalPointAtTheCenter“] >> calibFixPrincipalPoint;
node[“Input
评论
共有 条评论