使用OpenCV进行摄像机标定,在OpenCV例程中有程序可以实现,
/samples/cpp/tutorial_code/calib3d/camera_calibration里的程序就可以进行单目相机标定。
在http://download.youkuaiyun.com/detail/chuhang_zhqr/9293665有我上传的,内含测试图片和文件,想直接用的就去下载吧。
接下来分析下摄像机标定的过程:
1:这个程序中把初始化参数放在了一个文件(in_VID5.xml)中,在程序的开始首先读入文件中的参数:
const string inputSettingsFile = argc > 1 ? argv[1] : "in_VID5.xml";
FileStorage fs(inputSettingsFile, FileStorage::READ); // Read the settings
if (!fs.isOpened())
{
cout << "Could not open the configuration file: \"" << inputSettingsFile << "\"" << endl;
return -1;
}
fs["Settings"] >> s;
fs.release(); // close Settings file
if (!s.goodInput)
{
cout << "Invalid input detected. Application stopping. " << endl;
return -1;
}
这个in_VID5.xml可以设置图像大小,棋盘格大小,还可以设置图像源输入:相机输入(“0”),视频输入,图像序列输入(“/home/zhu/program_c/opencv_study/test_down/camera_calibration/VID5.xml”),相机输入时,在运行程序时,按g开始采集图像并进行计算标定系数,期间可以移动棋盘格或相机,获得不同方位的棋盘格图像,使标定系数尽可能精确。
2:读入相机初始参数后,判断这些数据是否符合,就是验证数据的正确性。
void interprate()
{
goodInput = true;
if (boardSize.width <= 0 || boardSize.height <= 0)
{
cerr << "Invalid Board size: " << boardSize.width << " " << boardSize.height << endl;
goodInput = false;
}
if (squareSize <= 10e-6)
{
cerr << "Invalid square size " << squareSize << endl;
goodInput = false;
}
if (nrFrames <= 0)
{
cerr << "Invalid numb