www.pudn.com > OPENCV_SIFT_VC6.rar > KeyPoint.cpp
// KeyPoint.cpp: implementation of the CKeyPoint class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TestSIFT.h"
#include "KeyPoint.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CKeyPoint:: CKeyPoint (IplImage* gaussImg, double x, double y, double imgScale,
double kpScale, double orientation)
{
m_gaussImg = gaussImg;
m_x = x;
m_y = y;
m_imgScale = imgScale;
m_kpScale = kpScale;
m_orientation = orientation;
m_featureVec = NULL;
}
CKeyPoint::~CKeyPoint()
{
if (m_featureVec != NULL)
delete m_featureVec;
}
void CKeyPoint::CreateVector (int xDim, int yDim, int oDim)
{
m_xDim = xDim;
m_yDim = yDim;
m_oDim = oDim;
m_featureVec = new double[yDim * xDim * oDim];
memset (m_featureVec,0,sizeof(double)*yDim*xDim*oDim);
}
void CKeyPoint::FVSet(int xI, int yI, int oI, double value)
{
// row major
m_featureVec[(yI * m_xDim * m_oDim) + (xI * m_oDim) + oI] = value;
}
double CKeyPoint::FVGet(int xI, int yI, int oI)
{
// row major
return m_featureVec[(yI * m_xDim * m_oDim) + (xI * m_oDim) + oI];
}
// Threshhold and normalize feature vector.
// Note that the feature vector as a whole is normalized (Lowe's paper is
// a bit unclear at that point).
void CKeyPoint::CapAndNormalizeFV (double fvGradHicap)
{
// Straight normalization
int len = m_xDim * m_yDim * m_oDim;
double norm = 0.0;
for (int i = 0 ; i < len ; i++)
norm += m_featureVec[i]*m_featureVec[i];
norm = sqrt (norm);
if (norm == 0.0)
return;
for (i = 0 ; i < len; i++)
m_featureVec[i] /= norm;
// Hicap after normalization
for (i = 0 ; i < len; i++)
if (m_featureVec[i] > fvGradHicap)
m_featureVec[i] = fvGradHicap;
// Renormalize again
norm = 0;
for (i = 0 ; i < len ; i++)
norm += m_featureVec[i]*m_featureVec[i];
norm = sqrt (norm);
for (i = 0 ; i < len; i++)
m_featureVec[i] /= norm;
}