[1b4a52]: src / hugin_base / algorithms / control_points / KDTreeKeypointMatcher.h  Maximize  Restore  History

Download this file

132 lines (107 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* @file KDTreeKeypointMatcher.h
* gsoc2008_feature_matching
*
* This class is a generic k-d tree wrapper
*
* @author Onur Kucuktunc <onurcc@gmail.com>
*/
#ifndef _CTRLPNTSALGORITHMS_FEATURE_MATCHING_KDTREE_H
#define _CTRLPNTSALGORITHMS_FEATURE_MATCHING_KDTREE_H
#include <ANN/ANN.h>
#include <panodata/Panorama.h>
#include <limits>
namespace HuginBase {
struct ImageKeypoint
{
ImageKeypoint(unsigned int image, unsigned int keyNr, const HuginBase::Keypoint& key)
{
imageNr = image;
keypointNr = keyNr;
keypoint = key;
}
unsigned int imageNr;
unsigned int keypointNr;
HuginBase::Keypoint keypoint;
};
class KDTreeKeypointMatcher {
public:
// constructors
KDTreeKeypointMatcher()
: m_KDTree(0), m_allPoints(0), m_k(2)
{
m_nnIdx = new ANNidx[m_k];
m_dists = new ANNdist[m_k];
};
KDTreeKeypointMatcher(int k)
: m_KDTree(0), m_allPoints(0)
{
assert(k>0);
m_k = k;
m_nnIdx = new ANNidx[m_k];
m_dists = new ANNdist[m_k];
};
// destructor
~KDTreeKeypointMatcher()
{
printf("Destructor of KDTreeKeypointMatcher called\n");
if (m_KDTree)
delete m_KDTree;
if (m_allPoints)
delete[] m_allPoints;
delete[] m_nnIdx;
delete[] m_dists;
}
// initialization methods
void create(const PanoramaData & pano);
void create(const PanoramaData & pano, const UIntSet & imgs);
// search methods
ImageKeypoint* match(const HuginBase::Keypoint& key, unsigned int imageOfKeypoint);
// helper methods
int getKeypointIdxOfMatch(unsigned int matchNr) const;
// Euclidean distance calculation for two keypoints
virtual float fm_eucdist(const HuginBase::Keypoint& p1, const HuginBase::Keypoint& p2)
{
float sum = 0;
std::vector<float>::const_iterator it2 = p2.descriptor.begin();
for(std::vector<float>::const_iterator it1 = p1.descriptor.begin();
it1 != p1.descriptor.end(); ++it1, ++it2)
{
float d = *it1 - *it2;
d *= d;
sum += d;
}
return pow(sum,0.5f);
}
// Euclidean distance calculation for two keypoints with an upper bound given
virtual float fm_eucdist_ub(const HuginBase::Keypoint& p1, const HuginBase::Keypoint& p2, float ub)
{
float sum = 0;
std::vector<float>::const_iterator it2 = p2.descriptor.begin();
float ub2 = ub * ub;
for(std::vector<float>::const_iterator it1 = p1.descriptor.begin();
it1 != p1.descriptor.end(); ++it1, ++it2)
{
float d = *it1 - *it2;
d *= d;
sum += d;
// check if the distance exceeds upper bound
if (sum > ub2)
return std::numeric_limits<float>::infinity();
}
return pow(sum,0.5f);
}
private:
ANNkd_tree * m_KDTree;
/// vector to hold all descriptors
std::vector<ImageKeypoint> m_keypoints;
/// array with pointers to all keypoint descriptors
ANNpointArray m_allPoints;
// query results
ANNidxArray m_nnIdx;
ANNdistArray m_dists;
/// number of nearest neighbours
unsigned int m_k;
};
}
#endif

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks