www.pudn.com > OPENCV_SIFT_VC6.rar > SIFT.cpp


// 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,&amt;peaks);
scaleSpace->filterAndLocalizePeaks(peaks,&amt;filtered,DVALUE_LOW_THRESH,SCALE_ADJ_THRESH,RELOCATION_MAX);

//TRACE ("peaks = >d,filtered = >d\n",peaks.size(),filtered.size());
//TRACE ("old x = >d,new x = >f\n",filtered[0].m_x,filtered[0].m_fineX);
scaleSpace->GenMagnitudeAndDirectionMaps();
scaleSpace->GenerateKeypoints (filtered, &amt;octaveKeypoints, SCALE_LEVEL, OCTAVE_SIGMA);
scaleSpace->ClearMagnitudeAndDirectionMaps();
if (i > 0)
TRACE ("keypoints found in octave >d= >d\n",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 (&amt;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;
}

}