在实际中提取图像的sift特征点,再对特征点做匹配,形成特征点对,最后计算图像变换的矩阵,一般为单应矩阵,再利用单应矩阵进行图像的配准,现在基于OpenCV实现相关的算法和步骤,具体代码和主要的函数讲解如下。
一、代码如下:
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include "opencv2/calib3d/calib3d.hpp"
#include <highgui.h>
#include <cv.h>
#include<vector>
#include<cmath>
#define PI 3.14159265358979323846264338327950288419716939937510582097
using namespace std;
using namespace cv;
void main()
{
//读取原始基准图和待匹配图
Mat srcImg1 = imread("1.JPG"); //待配准图
Mat srcImg2 = imread("2.JPG"); //基准图
//显示基准和待配准图
imshow("待配准图", srcImg1);
imshow("基准图", srcImg2);
//定义SIFT特征检测类对象
SiftFeatureDetector siftDetector1;
SiftFeatureDetector siftDetector2;
//定义KeyPoint变量
vector<KeyPoint>keyPoints1;