fast算法学习

fast算法是由 ed Rosten,tom drummond 等提出的。算法的主页:

http://www.edwardrosten.com/work/fast.html

论文下载地址:

http://www.edwardrosten.com/work/papers.html  (2006年部分)

比较好的中文介绍的博客:

http://blog.csdn.net/yang_xian521/article/details/7411438 

下面介绍一下我对fast算法的理解:

fast是 Features from accelerated segment Test的缩写,它对feature的定义是:如果在以r为半径,以像素p为圆心的Bresenham圆上有连续的>=N个像素大于(或者小于)像素p+-设定的阈值t,那么这个p像素所在的位置就有一个feature。在opencv函数中FastFeatureDetector(t)中的t就是这里所说的阈值。

紧接着它讨论了直接计算的劣势,包括对N的讨论,计算量大,

它又借助ID3算法对算法进行改进,但是我对id3算法不是很了解,所以null。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

结果证明当N= 9,r=3时仅仅需要2.26个question当N=9时是效率最高的,也就是fast-9算法。。

下面贴一下我从上面的博客地址上出现的代码,在我的机器上跑了一下,完全可以。:

#include<windows.h>
#include<opencv\cv.h>
#include<opencv\highgui.h>
using namespace std;
using namespace cv;
int  main()
{
	cv::Mat img;
	img = cv::imread("hello.jpg");
	vector<cv::KeyPoint> keyPoints;
	cv::FastFeatureDetector fast(40);
	double freq =1;// ::getTickFrequency();
	double start = GetTickCount();  
	fast.detect(img,keyPoints);
	double end = GetTickCount();
	double time = (end-start);
	std::cout<<time<<std::endl;
	drawKeypoints(img,keyPoints,img,Scalar::all(255),1);
	imshow("fast",img);
	waitKey();
	return 0;
}

运行后图片发现时间为16ms。

2.程序直接读取摄像头,并让fast算法运行灰度图像像代码:

#include<windows.h>
#include<opencv\cv.h>
#include<opencv\highgui.h>
using namespace std;
using namespace cv;
int  main()
{
	cv::VideoCapture cap(0);
	if(!cap.isOpened()){
		return -1;
	}
	Mat frame;
	Mat gray;
	vector<cv::KeyPoint> keyPoints;
	cv::FastFeatureDetector fast(40);
	while(1)
	{
		cap>>frame;
		cvtColor(frame,gray,CV_BGR2GRAY);
		double start = GetTickCount();
		fast.detect(gray,keyPoints);
		double end = GetTickCount();
		std::cout<<end-start<<std::endl;
		drawKeypoints(gray,keyPoints,gray,Scalar::all(255));
		imshow("hello",gray);
		imshow("original",frame);
		if(waitKey(2)>=0)
		{
			break;
		}
	}
}

时间大部分出现“0”,说明速度的确很快,第一个程序主要费时在把rgb图像转换成灰度图像上了。

代码:使用surf算法实现匹配

#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include<opencv/cv.h>
#include <vector>
#include <iostream>
using namespace cv;
using namespace std;

char img_filename1[]="hello.jpg";
char img_filename2[]="hello.jpg";

void main()
{
	Mat img=imread("hello.jpg");
	Mat imgCopy= img;
	Mat imgGray;
	cvtColor(img,imgGray,CV_BGR2GRAY);

	Mat frame;
	cv::VideoCapture cap(0) ;
	if(!cap.isOpened())
	{
		exit(1);
	}
	vector<KeyPoint> keysImg;
	vector<KeyPoint> keysFrame;
	FastFeatureDetector fast(45);
	fast.detect(img,keysImg);
	
	SurfDescriptorExtractor extractor;
	Mat descriptorsImg;
	Mat descriptorsFrame;
	extractor.compute(img,keysImg,descriptorsImg);
	
	FlannBasedMatcher matcher;
	vector<DMatch> matches ;

	Mat imgMatch;
	while(1)
	{
		cap>>frame;
		fast.detect(frame,keysFrame);
		if( keysFrame.empty()) //避免出现cv::exception ();
			continue;
		extractor.compute(frame,keysFrame,descriptorsFrame);
		matcher.match(descriptorsImg,descriptorsFrame,matches);
		drawMatches(img,keysImg,frame,keysFrame,matches,imgMatch,Scalar::all(-1),
			Scalar::all(-1)
			,vector<char>()
			,DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS
			);
		imshow("match",imgMatch);
		if( waitKey(2)>=0)
			break;
	}//while(1);endl;

}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值