20 template<
class Score,
class ReturnType,
class Collector,
class Test>
21 inline void nonmax_suppression_t(
const vector<ImageRef>& corners,
const vector<Score>& scores, vector<ReturnType>& nonmax_corners)
23 nonmax_corners.clear();
24 nonmax_corners.reserve(corners.size());
26 if(corners.size() < 1)
33 int last_row = corners.back().y;
34 vector<int> row_start(last_row + 1, -1);
37 for(
unsigned int i=0; i< corners.size(); i++)
38 if(corners[i].y != prev_row)
40 row_start[corners[i].y] = i;
41 prev_row = corners[i].y;
50 const int sz = (int)corners.size();
52 for(
int i=0; i < sz; i++)
54 Score score = scores[i];
59 if(corners[i-1] == pos-
ImageRef(1,0) && Test::Compare(scores[i-1], score))
64 if(corners[i+1] == pos+
ImageRef(1,0) && Test::Compare(scores[i+1], score))
68 if(pos.
y != 0 && row_start[pos.
y - 1] != -1)
72 if(corners[point_above].y < pos.
y - 1)
73 point_above = row_start[pos.
y-1];
77 for(; corners[point_above].y < pos.
y && corners[point_above].x < pos.
x - 1; point_above++)
81 for(
int i=point_above; corners[i].y < pos.
y && corners[i].x <= pos.
x + 1; i++)
84 if( (x == pos.
x - 1 || x ==pos.
x || x == pos.
x+1) && Test::Compare(scores[i], score))
91 if(pos.
y != last_row && row_start[pos.
y + 1] != -1 && point_below < sz)
93 if(corners[point_below].y < pos.
y + 1)
94 point_below = row_start[pos.
y+1];
98 for(; point_below < sz && corners[point_below].y == pos.
y+1 && corners[point_below].x < pos.
x - 1; point_below++)
101 for(
int i=point_below; i < sz && corners[i].y == pos.
y+1 && corners[i].x <= pos.
x + 1; i++)
103 int x = corners[i].x;
104 if( (x == pos.
x - 1 || x ==pos.
x || x == pos.
x+1) && Test::Compare(scores[i],score))
109 nonmax_corners.push_back(Collector::collect(corners[i],scores[i]));
141 static inline pair<ImageRef, int>
collect(
const ImageRef& pos,
int score){
return make_pair(pos,score);}
147 nonmax_suppression_t<int, ImageRef, collect_pos, GreaterEqual>(corners, scores, nonmax_corners);
150 void nonmax_suppression(
const vector<ImageRef>& corners,
const vector<int>& scores, vector<ImageRef>& nonmax_corners)
152 nonmax_suppression_t<int, ImageRef, collect_pos, Greater>(corners, scores, nonmax_corners);
157 nonmax_suppression_t<int, pair<ImageRef,int> ,
collect_score,
Greater>(corners, scores, nonmax_corners);
void nonmax_suppression_with_scores(const vector< ImageRef > &corners, const vector< int > &scores, vector< pair< ImageRef, int > > &nonmax_corners)
static pair< ImageRef, int > collect(const ImageRef &pos, int score)
void nonmax_suppression_t(const vector< ImageRef > &corners, const vector< Score > &scores, vector< ReturnType > &nonmax_corners)
static bool Compare(int a, int b)
void nonmax_suppression(const vector< ImageRef > &corners, const vector< int > &scores, vector< ImageRef > &nonmax_corners)
static bool Compare(int a, int b)
void nonmax_suppression_strict(const vector< ImageRef > &corners, const vector< int > &scores, vector< ImageRef > &nonmax_corners)
static ImageRef collect(const ImageRef &pos, int)