版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mengxiang2425/article/details/82559609
打算直接使用Matlab来标定,毕竟opencv自带的标定不太准确,数学工具还是要利用起来的。
标定很重要,后面的双目测距,三维重构等都必须要用,所以必须要学会使用Matlab进行双目标定。
首先要下载一个工具包放在D:\MATLAB\R2016a\toolbox\matlab这个路径(具体看自己的安装路径),工具包可以在matlab官网下载,名称为toolbox_calib.zip,网址为http://www.vision.caltech.edu/bouguetj/calib_doc/。
设置好路径之后就可以测试了。
1、单目标定参考http://blog.csdn.net/Loser__Wang/article/details/51811347
已完成单目标定。具体的内外畸变参数博客写的很详细了。
程序运行示例:
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
VideoCapture inputVideo(0);
if (!inputVideo.isOpened())
{
cout << "Could not open the input video: " << endl;
return -1;
}
Mat frame;
Mat frameCalibration;
inputVideo >> frame;
Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
cameraMatrix.at<double>(0, 0) = 8.020452698431196e+02;
cameraMatrix.at<double>(0, 1) = 0;
cameraMatrix.at<double>(0, 2) = 3.477773258387357e+02;
cameraMatrix.at<double>(1, 1) = 7.986372500898794e+02;
cameraMatrix.at<double>(1, 2) = 2.607218924683198e+02;
Mat distCoeffs = Mat::zeros(5, 1, CV_64F);
distCoeffs.at<double>(0, 0) = -0.174672717467200;
distCoeffs.at<double>(1, 0) = 0.214495208306129;
distCoeffs.at<double>(2, 0) = 0;
distCoeffs.at<double>(3, 0) = 0;
distCoeffs.at<double>(4, 0) = 0;
Mat view, rview, map1, map2;
Size imageSize;
imageSize = frame.size();
initUndistortRectifyMap(cameraMatrix, distCoeffs, Mat(),
getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize, 0),
imageSize, CV_16SC2, map1, map2);
while (1) //Show the image captured in the window and repeat
{
inputVideo >> frame; // read
if (frame.empty()) break; // check if at end
remap(frame, frameCalibration, map1, map2, INTER_LINEAR);
imshow("Origianl", frame);
imshow("Calibration", frameCalibration);
char key = waitKey(1);
if (key == 27 || key == 'q' || key == 'Q')break;
}
return 0;
}
可以看到标定过后的图比原来的好多了。
2、双目标定参考http://www.mamicode.com/info-detail-1111815.html
要使用两个摄像头一起打开来照相,注意两个摄像头之间的距离,然后使用matlab标定完成之后,得到了我们所需要的参数
Stereo calibration parameters after loading the individual calibration files:
Intrinsic parameters of left camera:
Focal Length: fc_left = [ 780.17175 777.71912 ] � [ 18.51103 17.77195 ]
Principal point: cc_left = [ 341.09426 259.67745 ] � [ 18.38629 13.32784 ]
Skew: alpha_c_left = [ 0.00000 ] � [ 0.00000 ] => angle of pixel axes = 90.00000 � 0.00000 degrees
Distortion: kc_left = [ -0.12758 -0.14219 0.00102 -0.00229 0.00000 ] � [ 0.06322 0.40645 0.00392 0.00556 0.00000 ]
Intrinsic parameters of right camera:
Focal Length: fc_right = [ 804.25246 798.53096 ] � [ 26.86921 25.78932 ]
Principal point: cc_right = [ 313.31520 266.26038 ] � [ 21.46775 18.09631 ]
Skew: alpha_c_right = [ 0.00000 ] � [ 0.00000 ] => angle of pixel axes = 90.00000 � 0.00000 degrees
Distortion: kc_right = [ -0.06840 -1.01339 0.00618 -0.00825 0.00000 ] � [ 0.10903 0.96165 0.00489 0.00631 0.00000 ]
Extrinsic parameters (position of right camera wrt left camera):
Rotation vector: om = [ 0.00866 0.02203 -0.03950 ]
Translation vector: T = [ -337.30574 5.34897 65.73400 ]