opencv双目标定+立体校正+立体匹配(源码&讲解)

//双目标定无非就是重复两次单目标定的流程,单目标定参考我上一篇博客。
//在学习双目视觉之前,建议大家补充下,双目视觉模型,对极几何的知识,今天只讲源码的流程,以后出一篇对极几何的讲解。
在这里插入图片描述
//老规矩先来一段源码

#include "opencv2/core.hpp"
#include <opencv2/core/utility.hpp>
#include <opencv2/imgproc.hpp>
#include "opencv2/calib3d.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include <cctype>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <iostream>

using namespace std;
using namespace cv;
static double computeReprojectionErrors(
	const vector<vector<Point3f> >& objectPoints,
	const vector<vector<Point2f> >& imagePoints,
	const vector<Mat>& rvecs, const vector<Mat>& tvecs,
	const Mat& cameraMatrix, const Mat& distCoeffs
)
{
   
	vector<Point2f> imagePoints2;
	int i, totalPoints = 0;
	double totalErr = 0, err;
	for (i = 0; i < (int)objectPoints.size(); i++)
	{
   
		projectPoints(Mat(objectPoints[i]), rvecs[i], tvecs[i],
			cameraMatrix, distCoeffs, imagePoints2);
		err = norm(Mat(imagePoints[i]), Mat(imagePoints2), NORM_L2);
		int n = (int)objectPoints[i].size();

		totalErr += err*err;
		totalPoints += n;
	}
	return std::sqrt(totalErr / totalPoints);
}

int main(int argc, char** argv)
{
   
	vector<string> files_left;
	vector<string> files_right;
	glob("E:\\mul_cam_images\\left1", files_left);
	glob("E:\\mul_cam_images\\right1", files_right);
	// 定义变量
	vector<vector<Point2f>> image_leftPoints,image_rightPoints;//像点
	vector<vector<Point3f>> objectPoints;//物点
	TermCriteria criteria = TermCriteria(TermCriteria::EPS + TermCriteria::MAX_ITER, 30, 0.001);//进行亚像素精度的调整,获得亚像素级别的角点坐标
	int numCornersHor = 8;//heigh
	int numCornersVer = 11;//width
	int numSquares = 15;//单位mm
	Mat gray_l, gray_r;
	Mat image_l, image_r;
	vector<Point3f> obj;
	for (int i = 0; i < numCornersHor; i++)
		for (int j = 0; j < numCornersVer; j++)
			obj.push_back(Point3f((float)j * numSquares, (float)i * numSquares, 0));
	//存放每张图的角点坐标,并存入obj中(物点)	
	Size s1,s2;
	//像点
	for (int i = 0; i < 16; i++) {
   
		printf("image file : %s \n", files_left
  • 17
    点赞
  • 123
    收藏
    觉得还不错? 一键收藏
  • 17
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值