画出对应的极线

三维重建 - 摄像机标定和立体匹配中极线约束方法  http://blog.csdn.net/sevencolorfish/article/details/6840624
姿态估计和对极几何  http://blog.sina.com.cn/s/blog_4b9b714a0100c9f3.html
画出对应的极线 http://blog.csdn.net/yc461515457/article/details/50427082

//画出外极线,对应点已经经过了RANSAC优化
void DrawEpiLines(const Mat& img_1, const Mat& img_2, vectorpoints1, vectorpoints2){

	cv::Mat F = cv::findFundamentalMat(points1, points2, CV_FM_8POINT);
	//首先根据对应点计算出两视图的基础矩阵,基础矩阵包含了两个相机的外参数关系
	std::vector> epilines1, epilines2;
	cv::computeCorrespondEpilines(points1, 1, F2, epilines1);//计算对应点的外极线epilines是一个三元组(a,b,c),表示点在另一视图中对应的外极线ax+by+c=0;
	cv::computeCorrespondEpilines(points2, 2, F2, epilines2);
	//将图片转换为RGB图,画图的时候外极线用彩色绘制
	cv::Mat img1, img2;
	if (img_1.type() == CV_8UC3)
	{
		img_1.copyTo(img1);
		img_2.copyTo(img2);
	}
	else if (img_1.type() == CV_8UC1)
	{
		cvtColor(img_1, img1, COLOR_GRAY2BGR);
		cvtColor(img_2, img2, COLOR_GRAY2BGR);
	}
	else
	{
		cout << "unknow img type\n" << endl;
		exit(0);
	}

	cv::RNG& rng = theRNG();
	for (int i = 0; i < points2.size(); i++)
	{
		Scalar color = Scalar(rng(256), rng(256), rng(256));//随机产生颜色

		circle(img2, points2[i], 5, color);//在视图2中把关键点用圆圈画出来,然后再绘制在对应点处的外极线
		line(img2, Point(0, -epilines1[i][2] / epilines1[i][1]), Point(img2.cols, -(epilines1[i][2] + epilines1[i][0] * img2.cols) / epilines1[i][1]), color);
		//绘制外极线的时候,选择两个点,一个是x=0处的点,一个是x为图片宽度处
		circle(img1, points1[i], 4, color);
		line(img1, cv::Point(0, -epilines2[i][2] / epilines2[i][1]), cv::Point(img1.cols, -(epilines2[i][2] + epilines2[i][0] * img1.cols) / epilines2[i][1]), color);

	}
	//cout << " " << endl;
}

你可能感兴趣的:(画出对应的极线)