OpenCV学习笔记[5]FLANN特征匹配

这篇博客介绍了如何使用OpenCV的FLANN模块在Java中进行特征匹配。内容涉及特征匹配的概念,测试用例,以及测试结果显示了匹配点的数量和质量,通过控制台视图和GEiv视图展示了匹配效果。
摘要由CSDN通过智能技术生成

OpenCV学习笔记:FLANN特征匹配


        本次给出FLANN特征匹配的Java实现。

[简介]

        特征匹配记录下目标图像与待匹配图像的特征点(KeyPoint),并根据特征点集合构造特征量(descriptor),对这个特征量进行比较、筛选,最终得到一个匹配点的映射集合。我们也可以根据这个集合的大小来衡量两幅图片的匹配程度。

        特征匹配与模板匹配不同,由于是计算特征点集合的相关度,转置操作对匹配影响不大,但它容易受到失真、缩放的影响。

[特征匹配]

FeatureMatching.java:

import org.opencv.core.Mat;
import org.opencv.core.MatOfDMatch;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.features2d.DescriptorExtractor;
import org.opencv.features2d.DescriptorMatcher;
import org.opencv.features2d.FeatureDetector;
import org.opencv.highgui.Highgui;

import com.thrblock.opencv.fm.view.ConsoleView;
import com.thrblock.opencv.fm.view.MatchingView;

public class FeatureMatching {
	private Mat src;
	private MatOfKeyPoint srcKeyPoints;
	private Mat srcDes;
	
	private FeatureDetector detector;
	private DescriptorExtractor extractor;
	private DescriptorMatcher matcher;

	private MatchingView view;
	public FeatureMatching(MatchingView view) {
		this.view = view;
		srcKeyPoints = new MatOfKeyPoint();
		srcDes = new Mat();
		detector = FeatureDetector.create(FeatureDetector.SURF);
		extractor = DescriptorExtractor.create(DescriptorExtractor.SURF);
		matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);
	}

	public int doMaping(String dstPath) {
		view.setDstPic(dstPath);
		// 读入待测图像
		Mat dst = Highgui.imread(dstPath);
		System.out.println("DST W:"+dst.cols()+" H:" + dst.rows());
		// 待测图像的关键点
		MatOfKeyPoint dstKeyPoints = new MatOfKeyPoint();
		detector.detect(dst, dstKeyPoints);
		// 待测图像的特征矩阵
		Mat dstDes = new Mat();
		extractor.compute(dst, dstKeyPoints, ds
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值