Codes:

// BasisMatrixCalculate.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include  <iostream>#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
//引用cv::KeyPoint 特征检测器通用接口
#include <opencv2/features2d/features2d.hpp>
# include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/nonfree/nonfree.hpp> //引用features2d.hpp中 SurfFeatureDetector
#include <opencv2/legacy/legacy.hpp>
int main()
{//读取2张图像cv::Mat image1 = cv::imread("../../aTestImage/church01.jpg", 0);cv::Mat image2 = cv::imread("../../aTestImage/church03.jpg", 0);if (!image1.data || !image2.data)return 0;//使用SURF特征 获取图像特征点std::vector<cv::KeyPoint> keyPoints1;std::vector<cv::KeyPoint> keyPoints2;cv::SurfFeatureDetector surf(3000);surf.detect(image1, keyPoints1);surf.detect(image2, keyPoints2); //获取两幅图像的特征点// //展示图像中的keyPoints//cv::Mat imagekeyPt;//cv::drawKeypoints(image1, keyPoints1, imagekeyPt, cv::Scalar(255, 255, 255), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);//cv::namedWindow("image1SURFkeyPt");//cv::imshow("image1SURFkeyPt", imagekeyPt);//cv::drawKeypoints(image2, keyPoints2, imagekeyPt, cv::Scalar(255, 255, 255), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);//cv::namedWindow("image2SURFkeyPt");//cv::imshow("image2SURFkeyPt", imagekeyPt);//通过特征点获取描述子cv::SurfDescriptorExtractor  surfDesc;  // 构造描述子提取器cv::Mat descriptors1, descriptors2;  //描述子记录局部强度差值/梯度变化/位置等信息surfDesc.compute(image1, keyPoints1, descriptors1);surfDesc.compute(image2, keyPoints2, descriptors2);//匹配图像的描述子 descriptorscv::BruteForceMatcher< cv::L2<float> > matcher; //构造匹配器std::vector<cv::DMatch> matches; //匹配描述子matcher.match(descriptors1, descriptors2, matches);std::cout << "matches size= " << matches.size() << std::endl;//选择部分描述子 使用 一对图像的基础矩阵 进行匹配观测std::vector<cv::DMatch> partmatches; //部分匹配描述子 | 特征点对 的对应 索引结构体partmatches.push_back(matches[14]);  //选择第n个匹配描述子partmatches.push_back(matches[16]);partmatches.push_back(matches[141]);partmatches.push_back(matches[242]);partmatches.push_back(matches[236]);partmatches.push_back(matches[238]);//partmatches.push_back(matches[100]);partmatches.push_back(matches[200]);//画出选择的匹配描述子 两幅图像连线cv::Mat imagePartMatches;cv::drawMatches(image1, keyPoints1, image2, keyPoints2,partmatches, imagePartMatches, cv::Scalar(255, 255, 255));cv::namedWindow("imagePartMatches");cv::imshow("imagePartMatches", imagePartMatches);//将一维向量的keyPoints点转换成二维的Point2f点std::vector <int> pointIndexes1;//记录选择的匹配特征点的索引向量std::vector <int> pointIndexes2;for (std::vector<cv::DMatch>::const_iterator it = partmatches.begin();it != partmatches.end(); ++it){pointIndexes1.push_back(it->queryIdx); //查询图像1特征点索引pointIndexes2.push_back(it->trainIdx);  //训练图像2特征点索引}std::vector <cv::Point2f>  selPoints1, selPoints2;cv::KeyPoint::convert(keyPoints1, selPoints1, pointIndexes1);//将索引指定的 特征点 转换成2D点cv::KeyPoint::convert(keyPoints2, selPoints2, pointIndexes2);画出转换后的点二维点到原图像std::vector<cv::Point2f>::const_iterator  it = selPoints1.begin();//while (it != selPoints1.end())//{//    cv::circle(image1, *it, 3, cv::Scalar(255, 255, 255), 5);// ++it;//}it = selPoints2.begin();while (it != selPoints2.end()){cv::circle(image2, *it, 3, cv::Scalar(255, 255, 255), 2);++it;}//cv::namedWindow("image1");//cv::imshow("image1", image1);//cv::namedWindow("image2");//cv::imshow("image2", image2);// 获取该对图像的基础矩阵 (使用7个匹配描述子matches) CV_FM_7POINTcv::Mat fundemental = cv::findFundamentalMat(cv::Mat(selPoints1), cv::Mat(selPoints2),CV_FM_8POINT);//CV_FM_LMEDSstd::cout << "F-Matrix size= " << fundemental.rows << "," << fundemental.cols << std::endl;//使用基础矩阵 在对应图像上绘制外极线std::vector<cv::Vec3f> lines1; //存储外极线cv::computeCorrespondEpilines(cv::Mat(selPoints1), 1, fundemental, lines1);//获取图像1中的二维特征点 在图像2中对应的外极线for (std::vector<cv::Vec3f>::const_iterator it = lines1.begin(); it != lines1.end(); ++it){cv::line(image2, cv::Point(0, -(*it)[2] / (*it)[1] ),cv::Point(image2.cols ,  -( (*it)[2] + (*it)[0] * image2.cols )/(*it)[1] ),cv::Scalar(255,255,255));}cv::namedWindow("Image2 Epilines");cv::imshow("Image2 Epilines", image2);cv::waitKey(0);return 0;
}

Result:

OpenCV_Find Basis F-Matrix and computeCorrespondEpilines(获取一对图像的基础矩阵及对应极线)相关推荐

  1. H(单应矩阵homography),本质矩阵(Essential Matrix)和F(基础矩阵fundamental)

    文章目录 A x = 0 Ax=0 Ax=0 问题的求解 H(单应矩阵homography),本质矩阵(Essential Matrix)和F(基础矩阵fundamental) 单应矩阵 求解H步骤 ...

  2. Problem F: Matrix Problem (III) : Array Practice Time Limit: 1 Sec Memory Limit: 4 MB Submit: 8787

    Problem F: Matrix Problem (III) : Array Practice Time Limit: 1 Sec  Memory Limit: 4 MB Submit: 8787  ...

  3. ORB_SLAM2中基础矩阵F求解的原理及源码分析

    1. 基础矩阵的定义 如图所示是对极几何约束关系图,图中 O 1 , O 2 O_{1},O_{2} O1​,O2​分别表示相机的两个位姿,平面 I 1 , I 2 I_{1},I_{2} I1​,I ...

  4. 特征检测与匹配,测试8点法求取基础矩阵F(三维重建task1-3)

    特征检测与匹配(三维重建task1-3) #include <math/matrix_svd.h> #include "math/matrix.h" #include ...

  5. Halcon学习之六:获取Image图像中Region区域的特征参数

    area_center_gray ( Regions, Image : : : Area, Row, Column )    计算Image图像中Region区域的面积Area和重心(Row,Colu ...

  6. 前端js获取图片大小 扩展名_前端 JS 获取 Image 图像 宽高 尺寸

    前端 JS 获取 Image 图像 宽高 尺寸 简介 项目中用到获取图片的原始尺寸,然后适配宽高:网上的大部分前端解决方案,都是new Image()后,在onload事件中获取image的尺寸. 在 ...

  7. Opencv学习(3)——基础矩阵F、本质矩阵E、单应矩阵H 函数解析

    官网:https://docs.opencv.org/3.4.0/d9/d0c/group__calib3d.html#ga4abc2ece9fab9398f2e560d53c8c9780 基础矩阵F ...

  8. MVG(second)学习笔记- 对极几何和基础矩阵F,本质矩阵E

    本部分总结一下对极几何,对极几何是两幅视图之间的内在的射影几何,它独立于场景结构,只依赖于摄像机的内参和相对姿态. 下图简单画出示意图. 1.图中基本术语: X-X'为一对匹配点,对应空间点P CC' ...

  9. 为什么基础矩阵F的自由度是7

    一.基础矩阵的定义? 基础矩阵是对极几何中,将左图中的一个点的像素坐标,映射到右图中对应极线坐标的矩阵. 二.为什么基础矩阵的自由度是7? 首先,对极几何中,基础矩阵的维度是3×3,也就是有9个元素. ...

  10. Qt 中获取摄像头图像数据的方法

    Qt 中获取摄像头图像数据的方法 在 Qt 中提供了 QCamera 类用来操作摄像头.(这里的摄像头指的是电脑上常用的那种 USB 摄像头或网络摄像头,暂时还不支持工业相机.)摄像头获取的实时图像可 ...

最新文章

  1. SQL SERVER全面优化-------索引有多重要?
  2. ABC Perl Programing - 回 2gua 短消息
  3. jquery Syntax error, unrecognized expression:的解决方法
  4. 不是之所以不是,所以不是
  5. 为何excel中数据无法计算机,excel表格内数据为何无法计算机-为什么EXCEL单元格内的数字不能运算...
  6. springCloud学习1(集中式配置管理)
  7. js对象数组计算总计_如何计算数组中的对象
  8. mysql主从架构搭建_技术 | 手把手教你搭建MySQL主从架构
  9. 《Cocos2D权威指南》——1.6 本章小结
  10. 【转载】Java NIO学习
  11. adventureworks mysql_AdventureWorks2012
  12. 数学建模国赛latex写作模板
  13. US Domain Center 域名抢注服务
  14. Windows下的虚拟桌面软件——Virgo
  15. 为什么神经网络有偏置? 神经网络中的偏置(bias)究竟有这么用
  16. 数据基础---《利用Python进行数据分析·第2版》第12章 pandas高级应用
  17. opencv 摄像头捕获的图像保存为avi视频 代码解析
  18. batchsize、iteration、epoch之间的关系
  19. 漫反射实现 - UnityShader
  20. BeyondCompare使用

热门文章

  1. c++ STL之unordered_map
  2. iOS中Lua脚本应用笔记一:脚本概念相关
  3. [小结] flexbox
  4. 微信小程序——诉讼费计算
  5. BigDecimal 加减乘除 | 比较大小 | 取最大最小值 | 保留小数位 |转String
  6. Tomcat结合nginx使用案例
  7. iframe页面使用Js实现父页面和子页面通信
  8. Redis 禁止使用耗时命令和时间复杂度为O(n)的命令
  9. 用于保存计算机输入输出数据的材料及其,与房地产,电子,金融,汽车并称五大产业的是()...
  10. websocket.onmessage回调没反应_Java笔记:反应器模式的简单运用