OpenCV中的SURF特征匹配
来源:互联网 发布:php类get set 编辑:程序博客网 时间:2024/05/05 02:40
刚开始自学OpenCV不久,也是第一次写博客,所以请各位大神多多指点!
最近初涉OpenCV的仿射变换、SURF特征描述子、鼠标回调、进度条回调等功能,于是写了这个可以观察SURF的特征匹配效果的小程序,其实也是for fun,希望能搏君一玩^_^
PS:由于非CS科班出身,不足之处请各位多指教!
先上程序效果截图:
程序功能简介:
程序退出:在图像窗口敲击回车键即可;
旋转图像:鼠标拖动Video窗口的Angle轴即可;
缩放图像:鼠标拖动Video窗口的Scale轴即可;
平移图像:在Video窗口,鼠标左键拖拽图像即可;
平移图像复原:在Video窗口,单击鼠标右键即可;
调整特征匹配量:鼠标拖动Macher窗口的Hessian阈值即可。程序实现环境:VS2010 + OpenCV 2.4.11
#include <time.h>#include <stdio.h>#include <vector>#include <iostream>#include <opencv.hpp>#include <nonfree/nonfree.hpp>#include <legacy/legacy.hpp>using namespace cv;using namespace std;static Mat onAffine(Mat* im, Point2f dif);static Mat onRot(int pos, int rat, Mat* im);static Mat onSurf(int hes, Mat& im1, Mat& im2);static void onMouse(int Event, int x, int y, int drag, Mat* im);void main(int argc, char* argv[]){ Mat Cam = imread("Girl.jpg"), dst; int pos = 36, rat = 10, hes = 40; //initial value namedWindow("Video"); namedWindow("Matcher"); createTrackbar("Angle","Video", &pos,72); //rotate the image createTrackbar("Scale","Video", &rat,20); //scale the image createTrackbar("Hessian","Matcher", &hes,80); //minHessian threshold setMouseCallback("Video", (MouseCallback)onMouse, &Cam); //drag image while((waitKey(50)&255)!=13) {//press the Enter key to exit the programe dst = onRot(pos, rat, &Cam); imshow("Video", dst); dst = onSurf(hes, Cam, dst); imshow("Matcher", dst); }//end while}//end mainstatic Mat onSurf(int hes, Mat& im1, Mat& im2){ SURF Extractor, Detector(20*hes); //HessianThreshold //SURF = SurfDescriptorExtractor & SurfFeatureDetector vector<KeyPoint> kp1, kp2; Mat descriptor1, descriptor2, dst; Detector.detect(im1, kp1); Detector.detect(im2, kp2); //drawKeypoints(im1, kp1, dst); return dst; //no match Extractor.compute(im1, kp1, descriptor1); Extractor.compute(im2, kp2, descriptor2); vector< DMatch > matches; //DMatch: distance match BruteForceMatcher< L2<float> > Matcher; //L2-Distance Matcher.match(descriptor1, descriptor2, matches); drawMatches(im1, kp1, im2, kp2, matches, dst); return dst;}//end onSurfstatic void onMouse(int Event, int x, int y, int drag, Mat* im){ static Mat res = im->clone(); static const Point ini(0,0); static Point seed(ini), tdf(ini); Point now(x,y); switch(Event) { case CV_EVENT_LBUTTONDOWN: seed = now; break; case CV_EVENT_LBUTTONUP: tdf += (now-seed); break; case CV_EVENT_RBUTTONUP: res.copyTo(*im); tdf = ini; break; }//end switch if(drag==CV_EVENT_FLAG_LBUTTON) //drag the mouse to move the image *im = onAffine(&res, tdf+(now-seed)); //use Affine transformation}//end onMousestatic Mat onAffine(Mat* im, Point2f dif){ Point2f org[3],tri[3]; org[1] = Point2f(im->cols/2, 0); org[0] = Point2f(0,0); org[2] = Point2f(0, im->rows/2); for(int i=0; i<3; ++i) tri[i] = org[i] + dif; Mat warp = getAffineTransform(org, tri), dst; warpAffine(*im, dst, warp, im->size()); return dst;}//end onAffinestatic Mat onRot(int pos, int rat, Mat* im){ Point center(im->cols/2, im->rows/2); double angle = 5*pos-180, scale = 0.1*rat; Mat rot = getRotationMatrix2D(center, angle, scale), dst; warpAffine(*im, dst, rot, im->size()); return dst;}//end onRot
调整旋转角度后的效果图:
旋转+缩放后的效果图:
鼠标拖动图像后的效果图:
1 0
- OpenCV中的SURF特征匹配
- OpenCV Surf特征匹配
- 【OpenCV】OpenCV3中的SURF特征点的寻找和匹配
- opencv surf特征点匹配拼接源码
- opencv surf特征点匹配拼接源码
- Java基于OpenCV的Surf特征检测与匹配
- Opencv Surf算子特征提取与最优匹配
- opencv之SURF特征点提取及匹配
- 【OpenCV】SURF算法之视频图像实时特征点匹配
- Opencv Surf算子特征提取与最优匹配
- OpenCV-Python sift/surf特征匹配与显示
- SURF特征匹配算法
- opencv-SURF特征描述
- Opencv SURF 图像匹配
- opencv surf匹配
- OpenCV3中的SURF特征点的寻找和匹配
- opencv上gpu版surf特征点与orb特征点提取及匹配实例
- opencv上gpu版surf特征点与orb特征点提取及匹配实例
- Android第五课;跑马灯
- HTTP学习笔记:HTTP协议基础
- 使用Windbg查看CrashDump
- Spring 事务的配置和使用详解(包括手动对事务的控制部分)
- 三个数最大值(if)
- OpenCV中的SURF特征匹配
- 遍历Map的四种方法
- Cocos2dx:cocos2d-x-3.2版本学习过程中所遇到的一些问题
- 李航—统计学习方法第一章课后答案
- springMVC+FTP上传下载文件夹及文件
- redis在Linux的安装(Centos6.4)
- 操作系统读写方式
- 软件需求工程--KAOS建模
- HTML5 Form Data 对象的使用(转)