图像暴力匹配(DMatch)

本文演示了如何使用OpenCV库进行图像匹配和配准。通过SURF特征检测器和暴力匹配器BFMatcher匹配两个图像的特征点,然后使用findHomography找到匹配的图像之间的变换矩阵。最后,通过透视变换实现图像融合,优化重叠区域以达到自然的拼接效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ConsoleApplication40.cpp : 定义控制台应用程序的入口点。

//
//#include "stdafx.h"
//#include <iostream>
//#include <stdio.h>
//#include "opencv2/core.hpp"
//#include "opencv2/core/utility.hpp"
//#include "opencv2/core/ocl.hpp"
//#include "opencv2/imgcodecs.hpp"
//#include "opencv2/highgui.hpp"
//#include "opencv2/features2d.hpp"
//#include "opencv2/calib3d.hpp"
//#include "opencv2/imgproc.hpp"
//#include"opencv2/flann.hpp"
//#include"opencv2/xfeatures2d.hpp"
//#include"opencv2/ml.hpp"
//
//using namespace cv;
//using namespace std;
//using namespace cv::xfeatures2d;
//using namespace cv::ml;
//
//int main()
//{
//    Mat a = imread("1.bmp", IMREAD_GRAYSCALE);    //读取灰度图像
//    Mat b = imread("2.bmp", IMREAD_GRAYSCALE);
//
//    Ptr<SURF> surf;      //创建方式和2中的不一样
//    surf = SURF::create(800);
//
//    BFMatcher matcher;
//    Mat c, d;
//    vector<KeyPoint>key1, key2;
//    vector<DMatch> matches;
//
//    surf->detectAndCompute(a, Mat(), key1, c);
//    surf->detectAndCompute(b, Mat(), key2, d);
//
//    matcher.match(c, d, matches);       //匹配
//
//    sort(matches.begin(), matches.end());  //筛选匹配点
//    vector< DMatch > good_matches;
//    int ptsPairs = std::min(50, (int)(matches.size() * 0.15));
//    cout << ptsPairs << endl;
//    for (int i = 0; i < ptsPairs; i++)
//    {
//        good_matches.push_back(matches[i]);
//    }
//    Mat outimg;
//    drawMatches(a, key1, b, key2, good_matches, outimg, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);  //绘制匹配点
//
//    std::vector<Point2f> obj;
//    std::vector<Point2f> scene;
//
//    for (size_t i = 0; i < good_matches.size(); i++)
//    {
//        obj.push_back(key1[good_matches[i].queryIdx].pt);
//        scene.push_back(key2[good_matches[i].trainIdx].pt);
//    }
//
//    std::vector<Point2f> obj_corners(4);
//    obj_corners[0] = Point(0, 0);
//    obj_corners[1] = Point(a.cols, 0);
//    obj_corners[2] = Point(a.cols, a.rows);
//    obj_corners[3] = Point(0, a.rows);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值