OPENCV3的匹配

看了下sift的原理,实践时发现opencv3已经开始版权保护了,也就是要用sift和surf,必须下个contrib的附加模块。

一开始用的python,很愉快,不过发现官方文档中的fast,orb算法都是donot find the module。

网上一查,才知道3.0的文档实际是2.4的,官网怎么就不更新呢。

所以用c++,啃一下源代码吧,好在只要看个函数头,大概能猜出做什么,再说网上例子很多。

sift要安装新模块,就懒得用了,大致看了下fast,orb,觉得orb不错。以下为代码:

#include <iostream>  
#include <opencv2/core/core.hpp>  
#include <opencv2/imgproc/imgproc.hpp>  
#include "opencv2/features2d/features2d.hpp"  
#include "opencv2/highgui/highgui.hpp"  
#include <iostream>  
#include <vector>  
using namespace cv;
using namespace std;

int main()
{
	Mat img_1 = imread("C:\\Users\\acer\\Pictures\\algo\\book3.jpg");
	Mat img_2 = imread("C:\\Users\\acer\\Pictures\\algo\\book5.jpg");
	resize(img_1, img_1, Size(360, 640));
	resize(img_2, img_2, Size(360,640));
	if (!img_1.data || !img_2.data)
	{
		cout << "error reading images " << endl;
		return -1;
	}
	
	Ptr<ORB> orb=ORB::create();
	vector<KeyPoint> keyPoints_1, keyPoints_2;
	Mat descriptors_1, descriptors_2;

	orb->detect(img_1, keyPoints_1);
	orb->detect(img_2, keyPoints_2);

	orb->compute(img_1, keyPoints_1, descriptors_1);
	orb->compute(img_2, keyPoints_2, descriptors_2);
	BFMatcher matcher(NORM_HAMMING);
	vector<DMatch> matches;
	matcher.match(descriptors_1, descriptors_2, matches);

	Mat img_mathes;
	drawMatches(img_1, keyPoints_1, img_2, keyPoints_2, matches, img_mathes);
	// -- show 
	namedWindow("Test");
	imshow("Test", img_mathes);

	waitKey(0);
	return 0;
}


图片采用一个背景比较好,不同背景产生了大量的匹配错误,至于如何辨别是同一个物体以后解决。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值