SLAMflex SE  0.1.0
SLAMflex provides detection and tracking of dominant planes for smartphone devices. This plane can then be used to show AR content relative to the plane orientation. The detection of plane is performed in the field of view of the smartphone camera. In subsequent frames it is tracked. The interface returns the plane position and orientation.
fast_corner.cpp
Go to the documentation of this file.
1 #include "fast_corner.h"
2 #include "nonmax_suppression.h"
3 #include "prototypes.h"
4 
5 using namespace CVD;
6 using namespace std;
7 
8 namespace CVD
9 {
10 
12 {
13  ImageRef(0,3),
14  ImageRef(1,3),
15  ImageRef(2,2),
16  ImageRef(3,1),
17  ImageRef(3,0),
18  ImageRef(3,-1),
19  ImageRef(2,-2),
20  ImageRef(1,-3),
21  ImageRef(0,-3),
22  ImageRef(-1,-3),
23  ImageRef(-2,-2),
24  ImageRef(-3,-1),
25  ImageRef(-3,0),
26  ImageRef(-3,1),
27  ImageRef(-2,2),
28  ImageRef(-1,3),
29 };
30 
31 struct CornerPositive { inline static int sub(int a, int b) { return a-b; } };
32 struct CornerNegative { inline static int sub(int a, int b) { return b-a; } };
33 
34 
35 int old_style_corner_score(const BasicImage<byte>& im, ImageRef c, const int *pointer_dir, int barrier)
36 {
37  //The score for a positive feature is sum of the difference between the pixels
38  //and the barrier if the difference is positive. Negative is similar.
39  //The score is the max of those two.
40  //
41  // B = {x | x = points on the Bresenham circle around c}
42  // Sp = { I(x) - t | x E B , I(x) - t > 0 }
43  // Sn = { t - I(x) | x E B, t - I(x) > 0}
44  //
45  // Score = max sum(Sp), sum(Sn)
46 
47  const byte* imp = &im[c];
48 
49  int cb = *imp + barrier;
50  int c_b = *imp - barrier;
51  int sp=0, sn = 0;
52 
53  for(int i=0; i<16; i++)
54  {
55  int p = imp[pointer_dir[i]];
56 
57  if(p > cb)
58  sp += p-cb;
59  else if(p < c_b)
60  sn += c_b-p;
61  }
62 
63  if(sp > sn)
64  return sp;
65  else
66  return sn;
67 }
68 
69 void compute_fast_score_old(const BasicImage<byte>& im, const vector<ImageRef>& corners, int barrier, vector<int>& scores)
70 {
71  int pointer_dir[16];
72  for(int i=0; i < 16; i++)
73  pointer_dir[i] = fast_pixel_ring[i].x + fast_pixel_ring[i].y * im.size().x;
74 
75  scores.resize(corners.size());
76 
77  for(unsigned int i=0; i < corners.size(); i++)
78  scores[i] = old_style_corner_score(im, corners[i], pointer_dir, barrier);
79 }
80 
81 
82 
83 void fast_nonmax(const BasicImage<byte>& im, const vector<ImageRef>& corners, int barrier, vector<ImageRef>& max_corners)
84 {
85  vector<int> scores;
86  compute_fast_score_old(im, corners, barrier, scores);
87  nonmax_suppression(corners, scores, max_corners);
88 }
89 
90 void fast_nonmax_with_scores(const BasicImage<byte>& im, const vector<ImageRef>& corners, int barrier, vector<pair<ImageRef,int> >& max_corners)
91 {
92  vector<int> scores;
93  compute_fast_score_old(im, corners, barrier, scores);
94  nonmax_suppression_with_scores(corners, scores, max_corners);
95 }
96 
97 }
void nonmax_suppression_with_scores(const vector< ImageRef > &corners, const vector< int > &scores, vector< pair< ImageRef, int > > &nonmax_corners)
int x
The x co-ordinate.
Definition: image_ref.h:179
void fast_nonmax_with_scores(const BasicImage< byte > &im, const vector< ImageRef > &corners, int barrier, vector< pair< ImageRef, int > > &max_corners)
Definition: fast_corner.cpp:90
void compute_fast_score_old(const BasicImage< byte > &im, const vector< ImageRef > &corners, int barrier, vector< int > &scores)
Definition: fast_corner.cpp:69
Definition: abs.h:24
const ImageRef fast_pixel_ring[16]
Definition: fast_corner.cpp:11
void fast_nonmax(const BasicImage< byte > &im, const vector< ImageRef > &corners, int barrier, vector< ImageRef > &max_corners)
Definition: fast_corner.cpp:83
ImageRef size() const
What is the size of this image?
Definition: image.h:370
unsigned char byte
Definition: byte.h:28
static int sub(int a, int b)
Definition: fast_corner.cpp:31
void nonmax_suppression(const vector< ImageRef > &corners, const vector< int > &scores, vector< ImageRef > &nonmax_corners)
int old_style_corner_score(const BasicImage< byte > &im, ImageRef c, const int *pointer_dir, int barrier)
Definition: fast_corner.cpp:35
static int sub(int a, int b)
Definition: fast_corner.cpp:32