在于双目测距接触几个月之后,逐渐对双目测距熟悉起来(OpenCV实现),尤其是在写程序的时候,不会像以前那么毛毛躁躁,在CSDN上看过很多大神的博客,也慢慢的开始尝试着依据大神的东西按照自己的想法写一些简单的程序。对于双目测距的原理我就不做过多的叙述,很多大神有些的很详细的博客。我把今天的程序分享出来只是为了能让刚接触双目的小可爱们快速了解双目标定的实现过程,有什么问题的话可以留言交流哦。
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
VideoCapture cap;
Mat frame;
Mat Roil;
Mat Roir;
char key;
bool camera;
const int imageWidth = 320; //摄像头的分辨率
const int imageHeight = 240;
const int boardWidth = 7; //横向的角点数目
const int boardHeight = 5; //纵向的角点数据
const int frameNumber = 13; //相机标定时需要采用的图像帧数
const int squareSize = 25;
const Size boardSize = Size(boardWidth, boardHeight);
Size imageSize = Size(imageWidth, imageHeight);
vector<vector<Point2f> > imagePoints;
vector<int> usefulImgIndeces;
vector<Mat> images_L;
vector<Mat> images_R;
vector<vector<Point2f>> imagePointL; //左边摄像机所有照片角点的坐标集合
vector<vector<Point2f>> imagePointR;
vector<vector<Point3f>> objRealPoint;
vector<Point2f> cornerL; //左边摄像机某一照片角点坐标集合
vector<Point2f> cornerR; //右边摄像机某一照片角点坐标集合
vector<Point2f> corner;
Mat imageL, imageR;
Mat cameraMatrix_L ;
Mat distCoeffs_L;
Mat cameraMatrix_R;
Mat distCoeffs_R ;
Mat image_l;
Mat image_r;
Mat undistort_l;
Mat undistort_r;
Mat grayimagesl;
Mat grayimagesr;
Mat rectifyImageL, rectifyImageR;
Mat R, T, E, F;
Mat Rl, Rr, Pl, Pr, Q;
Mat mapLx, mapLy, mapRx, mapRy;