SIFT.cpp
上传用户:yli86818
上传日期:2014-07-15
资源大小:273k
文件大小:2k
- // SIFT.cpp: implementation of the CSIFT class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "TestSIFT.h"
- #include "SIFT.h"
- #include "highgui.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CSIFT::CSIFT()
- : SCALE_LEVEL(2),
- OCTAVE_SIGMA(1.6),
- PRESMOOTH_SIGMA(1.5),
- EDGE_RATIO(10.0), // Lowe use 10.0
- RELOCATION_MAX(4),
- DOG_THRESH(0.0075),
- DVALUE_LOW_THRESH(0.008), //
- SCALE_ADJ_THRESH(0.50),
- OCTAVE_COUNT(1)
- {
- }
- CSIFT::~CSIFT()
- {
- }
- void CSIFT::detect(IplImage *img,std::vector <CKeyPoint*>* keypoints)
- {
- IplImage *smoothedImg = cvCreateImage (cvGetSize(img),IPL_DEPTH_8U,1);
- cvSmooth (img,smoothedImg,CV_GAUSSIAN,0,0,PRESMOOTH_SIGMA);
- for (int i = 0; i < OCTAVE_COUNT; i++)
- {
- CScaleSpace *scaleSpace = new CScaleSpace(SCALE_LEVEL,exp(i*log(2)));
- scaleSpace->buildDoG(smoothedImg,OCTAVE_SIGMA,1.0);
- std::vector <CScalePoint> peaks;
- std::vector <CScalePoint> filtered;
- std::vector <CKeyPoint*> octaveKeypoints;
- scaleSpace->findPeak (EDGE_RATIO,DOG_THRESH,&peaks);
- scaleSpace->filterAndLocalizePeaks(peaks,&filtered,DVALUE_LOW_THRESH,SCALE_ADJ_THRESH,RELOCATION_MAX);
- //TRACE ("peaks = %d,filtered = %dn",peaks.size(),filtered.size());
- //TRACE ("old x = %d,new x = %fn",filtered[0].m_x,filtered[0].m_fineX);
- scaleSpace->GenMagnitudeAndDirectionMaps();
- scaleSpace->GenerateKeypoints (filtered, &octaveKeypoints, SCALE_LEVEL, OCTAVE_SIGMA);
- scaleSpace->ClearMagnitudeAndDirectionMaps();
- if (i > 0)
- TRACE ("keypoints found in octave %d= %dn",i,octaveKeypoints.size());
- for (int j = 0; j < octaveKeypoints.size(); j++)
- keypoints->push_back(octaveKeypoints[j]);
- CvSize size = cvGetSize(smoothedImg);
- size.width /= 2;
- size.height /= 2;
- cvReleaseImage (&smoothedImg);
- if (i < OCTAVE_COUNT-1)
- {
- smoothedImg = cvCreateImage (size,IPL_DEPTH_32F,1);
- cvResize(scaleSpace->getDoG(SCALE_LEVEL+1),smoothedImg,CV_INTER_NN);
- }
- delete scaleSpace;
- }
- }