资源简介

本程序只是一个简单的demo,里面包含了Opencv对HARRIS,SHI_TOMASI,FAST,SURF,SIFT算法的实现,初学着可以看看。

资源截图

代码片段和文件信息

// Harriscornerdetect.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h“
#include “harris.h“
#include “opencv2/nonfree/features2d.hpp“
#include “opencv2/legacy/legacy.hpp“

int typevalue;
int maxtype=4;
char *winname=“cornerdetect“;
Mat image1image2image;
void typeCallback(intvoid*);
void harrisDetect();
void goodFeaturesDetect();
void fastDetect();
void surfDetect();
void siftDetect();
int main(int argc char *argv[])
{
    image1 = imread (“tower320.jpg“);
image2 = imread (“tower256.jpg“0);
if (!image1.data||!image2.data)
{
printf(“please input the right picture.“);
return -1;
}
namedWindow(winname);
createTrackbar(“CornerDetectType“winname&typevaluemaxtypetypeCallback);
typeCallback(00);
    waitKey (0);
    return 0;
}

void typeCallback(intvoid*)
{
//灰度变换
    cvtColor (image1imageCV_BGR2GRAY);
switch (typevalue)
{
case 0:
harrisDetect();
break;
case 1:
goodFeaturesDetect();
break;
case 2:
fastDetect();
break;
case 3:
surfDetect();
break;
case 4:
siftDetect();
break;
}
}
void harrisDetect()
{
// 经典的harris角点方法
harris Harris;
// 计算角点
Harris.detect(image);
//获得角点
vector pts;
Harris.getCorners(pts0.01);
// 标记角点
Harris.drawOnImage(imagepts);
imshow (winnameimage);
}
void goodFeaturesDetect()
{
// 改进的harris角点检测方法
vector corners;
goodFeaturesToTrack(imagecorners
200
//角点最大数目
0.01
// 质量等级,这里是0.01*max(min(e1,e2)),e1,e2是harris矩阵的特征值
10);
// 两个角点之间的距离容忍度
harris().drawOnImage(imagecorners);//标记角点
imshow (winnameimage);

}
void fastDetect()
{
    //快速角点检测
    vector keypoints;
    FastFeatureDetector fast(40true);
    fast.detect (imagekeypoints);
    drawKeypoints (imagekeypointsimageScalar::all(255)DrawMatchesFlags::DRAW_OVER_OUTIMG);
imshow (winnameimage);
}
void surfDetect()
{
vector keypoints_1 keypoints_2;
 Mat descriptors_1 descriptors_2;
 //-- Step 1: Detect the keypoints using SURF Detector
SurfFeatureDetector surf(2500);
surf.detect(imagekeypoints_1);
surf.detect(image2keypoints_2);
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
extractor.compute( image keypoints_1 descriptors_1 );
extractor.compute( image2 keypoints_2 descriptors_2 );
//-- Step 3: Matching descriptor vectors with a brute force matcher
BruteForceMatcher< L2 > matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_1 descriptors_2 matches );
nth_element(matches.begin()matches.begin()+24matches.end());
matches.erase(matches.begin()+25matches.end());
//-- Draw matches
Mat img_matches;
drawMatches( image keypoints_1 image2 keypoints_2 matches img_matchesScalar(255255255) );
drawKeypoints(imagekeypoints_1imageScalar(255255255)DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
//-- Show detected matches
imshow(“Matches“ img_matches );
imshow (winna

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     112128  2014-04-01 12:04  Harriscornerdetect\Debug\Harriscornerdetect.exe

     文件    1101100  2014-04-01 12:04  Harriscornerdetect\Debug\Harriscornerdetect.ilk

     文件    2075648  2014-04-01 12:04  Harriscornerdetect\Debug\Harriscornerdetect.pdb

     文件       1802  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\cl.command.1.tlog

     文件      13450  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\CL.read.1.tlog

     文件       1044  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\CL.write.1.tlog

     文件        406  2014-03-30 17:08  Harriscornerdetect\Harriscornerdetect\Debug\Harriscornerdetect.exe.embed.manifest

     文件        472  2014-03-30 17:08  Harriscornerdetect\Harriscornerdetect\Debug\Harriscornerdetect.exe.embed.manifest.res

     文件        381  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\Harriscornerdetect.exe.intermediate.manifest

     文件         61  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\Harriscornerdetect.lastbuildstate

     文件       3327  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\Harriscornerdetect.log

     文件     434917  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\Harriscornerdetect.obj

     文件    1179648  2014-03-30 16:31  Harriscornerdetect\Harriscornerdetect\Debug\Harriscornerdetect.pch

     文件        226  2014-03-30 17:08  Harriscornerdetect\Harriscornerdetect\Debug\Harriscornerdetect_manifest.rc

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link-cvtres.read.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link-cvtres.write.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.5224-cvtres.read.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.5224-cvtres.write.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.5224.read.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.5224.write.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.5624-cvtres.read.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.5624-cvtres.write.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.5624.read.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.5624.write.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.6768-cvtres.read.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.6768-cvtres.write.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.6768.read.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.6768.write.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.7056-cvtres.read.1.tlog

     文件          2  2014-04-01 12:04  Harriscornerdetect\Harriscornerdetect\Debug\link.7056-cvtres.write.1.tlog

............此处省略58个文件信息

评论

共有 条评论