OPENCV3的匹配
2017-06-12 18:29
99 查看
看了下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;
}
图片采用一个背景比较好,不同背景产生了大量的匹配错误,至于如何辨别是同一个物体以后解决。
一开始用的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;
}
图片采用一个背景比较好,不同背景产生了大量的匹配错误,至于如何辨别是同一个物体以后解决。
相关文章推荐
- OpenCV中提取SIFT特征点、图像匹配、图像配准
- OpenCV 双目匹配流程
- OpenCV学习笔记(十三)——模板匹配
- Android Jni OpenCV-基于ORB算法特征点匹配
- Opencv实现图像无缝拼接,Sift查找特征点,Flann进行匹配
- OpenCV 兴趣点匹配函数
- 梳理OpenCV各立体匹配算法的分类和理论基础(更新中)
- opencv做的ORB实现的目标匹配
- 尺度不变的模板匹配方法(opencv源码)
- opencv-模板匹配
- 9.4 【OpenCV】 基于 ransac 算法的 sift 特征匹配程序(开发环境为OpenCV2.3.1+VS2010)
- 【opencv实践】人脸识别匹配——数据收集和预处理
- 【opencv实践】人脸识别匹配——识别自己的脸
- opencv学习篇(8)轮廓的查找、表达、绘制、特性及匹配
- OpenCV图像匹配 (image retrieval)理论篇
- OpenCV中特征点提取和匹配的通用方法
- OpenCV中特征点提取和匹配的通用方法
- OpenCV中特征点提取和匹配的通用方法
- OpenCV在jni中使用混合高斯背景模型出现的通道匹配错误