本文目的在于记录如何使用MATLAB作摄像机标定,并经过opencv进行校订后的显示。ios
首先关于校订的基本知识经过OpenCV官网的介绍便可简单了解:ide
对于摄像机咱们所关心的主要参数为摄像机内参,以及几个畸变系数。上面的链接中后半部分也给了如何标定,然而OpenCV自带的标定程序稍显繁琐。于是在本文中我主推使用MATLAB的工具箱。下面让咱们开始标定过程。spa
标定板
方法二:逼格满满(MATLAB)3d
J = (checkerboard(300,4,5)>0.5);
figure, imshow(J);
采集数据
那么有了棋盘格以后天然是须要进行照片了。很少说,直接上程序。按q键便可保存图像,尽可能把镜头的各个角度都覆盖好。code
#include "opencv2/opencv.hpp"
#include
#include
using namespace cv;
using namespace std;
int main()
{
VideoCapture inputVideo(0);
//inputVideo.set(CV_CAP_PROP_FRAME_WIDTH, 320);
//inputVideo.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
if (!inputVideo.isOpened())
{
cout << "Could not open the input video " << endl;
return -1;
}
Mat frame;
string imgname;
int f = 1;
while (1) //Show the image captured in the window and repeat
{
inputVideo >> frame; // read
if (frame.empty()) break; // check if at end
imshow("Camera", frame);
char key = waitKey(1);
if (key == 27)br