#include <faster_tree.h>
Definition at line 39 of file faster_tree.h.
Public Member Functions | |
std::pair < CVD::ImageRef, CVD::ImageRef > | bbox () const |
int | num_nodes () const |
bool | is_leaf () const |
std::pair < tree_element *, bool > | nth_element (int t) |
block_bytecode | make_fast_detector (int xsize) const |
int | detect_corner (const CVD::Image< CVD::byte > &im, CVD::ImageRef pos, int b) const |
tree_element * | copy () |
void | print (std::ostream &o, std::string ind=" ") const |
~tree_element () | |
tree_element (bool b) | |
tree_element (tree_element *a, tree_element *b, tree_element *c, int i) | |
Public Attributes | |
tree_element * | lt |
tree_element * | eq |
tree_element * | gt |
bool | is_corner |
int | offset_index |
Private Member Functions | |
void | make_fast_detector_o (std::vector< block_bytecode::fast_detector_bit > &v, int n, int xsize, int N, bool invert) const |
std::pair < tree_element *, bool > | nth_element (int target, int &n, bool eq_branch) |
int | detect_corner_oriented (const CVD::Image< CVD::byte > &im, CVD::ImageRef pos, int b, int n, bool invert) const |
tree_element::~tree_element | ( | ) | [inline] |
tree_element::tree_element | ( | bool | b | ) | [inline] |
Construct a leaf-node.
b | Class of the node |
Definition at line 375 of file faster_tree.h.
00376 :lt(0),eq(0),gt(0),is_corner(b),offset_index(0) 00377 {}
tree_element::tree_element | ( | tree_element * | a, | |
tree_element * | b, | |||
tree_element * | c, | |||
int | i | |||
) | [inline] |
std::pair<CVD::ImageRef, CVD::ImageRef> tree_element::bbox | ( | ) | const [inline] |
This returns the bounding box of the detector.
Definition at line 50 of file faster_tree.h.
References offsets_bbox.
Referenced by tree_detect_corners(), and tree_detect_corners_all().
00051 { 00052 return offsets_bbox; 00053 }
int tree_element::num_nodes | ( | ) | const [inline] |
This returns the number of nodes in the tree.
Definition at line 56 of file faster_tree.h.
References eq, gt, lt, and num_nodes().
Referenced by learn_detector(), and num_nodes().
00057 { 00058 if(eq == NULL) 00059 return 1; 00060 else 00061 return 1 + lt->num_nodes() + eq->num_nodes() + gt->num_nodes(); 00062 }
bool tree_element::is_leaf | ( | ) | const [inline] |
Is the node a leaf?
Definition at line 66 of file faster_tree.h.
References eq.
Referenced by learn_detector(), and make_fast_detector_o().
00067 { 00068 return eq == NULL; 00069 }
std::pair<tree_element*,bool> tree_element::nth_element | ( | int | t | ) | [inline] |
Return a given numbered element of the tree.
Elements are numbered by depth-first traversal.
t | Element number to return |
Definition at line 76 of file faster_tree.h.
Referenced by learn_detector().
00077 { 00078 //The root node can not be a corner. 00079 //Otherwise the strength would be inf. 00080 int n=0; 00081 return nth_element(t, n, true); 00082 }
std::pair<tree_element*, bool> tree_element::nth_element | ( | int | target, | |
int & | n, | |||
bool | eq_branch | |||
) | [inline, private] |
Select the n'th elment of the tree.
Definition at line 232 of file faster_tree.h.
00233 { 00234 using tag::operator<<; 00235 #ifndef NDEBUG 00236 if(!( (eq==0 && lt == 0 && gt == 0) || (eq!=0 && lt!=0 &> != 0))) 00237 { 00238 std::clog << "Error: corrupted tree\n"; 00239 std::clog << tag::print << "lt" << lt; 00240 std::clog << tag::print << "eq" << eq; 00241 std::clog << tag::print << "gt" << gt; 00242 00243 abort(); 00244 } 00245 #endif 00246 00247 if(target == n) 00248 return std::make_pair(this, eq_branch); 00249 else 00250 { 00251 n++; 00252 00253 tree_element * r; 00254 bool e; 00255 00256 if(eq == 0) 00257 return std::make_pair(r=0,eq_branch); 00258 else 00259 { 00260 tag::rpair(r, e) = lt->nth_element(target, n, false); 00261 if(r != NULL) 00262 return std::make_pair(r, e); 00263 00264 tag::rpair(r, e) = eq->nth_element(target, n, true); 00265 if(r != NULL) 00266 return std::make_pair(r, e); 00267 00268 return gt->nth_element(target, n, false); 00269 } 00270 } 00271 }
int tree_element::detect_corner_oriented | ( | const CVD::Image< CVD::byte > & | im, | |
CVD::ImageRef | pos, | |||
int | b, | |||
int | n, | |||
bool | invert | |||
) | const [inline, private] |
Apply the tree to detect a corner in a single form.
im | Image in which to detect corners | |
pos | position at which to perform detection | |
b | Threshold | |
n | tree orientation to use (index in to offsets) | |
invert | Whether to perform an intensity inversion |
Definition at line 282 of file faster_tree.h.
References detect_corner_oriented(), is_corner(), and offsets.
Referenced by detect_corner_oriented().
00283 { 00284 //Return number that threshold would have to be increased to in 00285 //order to change the outcome 00286 00287 00288 if(eq== NULL) 00289 return is_corner * INT_MAX; 00290 else 00291 { 00292 int c = im[pos]; 00293 int p = im[pos + offsets[n][offset_index]]; 00294 00295 const tree_element* llt = lt; 00296 const tree_element* lgt = gt; 00297 00298 if(invert) 00299 std::swap(llt, lgt); 00300 00301 00302 if(p > c+b) 00303 return std::min(p-(c+b), lgt->detect_corner_oriented(im, pos, b, n, invert)); 00304 else if(p < c-b) 00305 return std::min((c-b)-p, llt->detect_corner_oriented(im, pos, b, n, invert)); 00306 else 00307 return eq->detect_corner_oriented(im, pos, b, n, invert); 00308 } 00309 }
int tree_element::detect_corner | ( | const CVD::Image< CVD::byte > & | im, | |
CVD::ImageRef | pos, | |||
int | b | |||
) | const [inline] |
Apply the tree in all forms to detect a corner.
im | CVD::Image in which to detecto corners | |
pos | position at which to perform detection | |
b | Threshold |
Definition at line 318 of file faster_tree.h.
References invert(), and offsets.
Referenced by tree_detect_corners(), and tree_detect_corners_all().
00319 { 00320 for(int invert=0; invert <2; invert++) 00321 for(unsigned int i=0; i < offsets.size(); i++) 00322 { 00323 int n = detect_corner_oriented(im, pos, b, i, invert); 00324 if(n) 00325 return n; 00326 } 00327 return 0; 00328 }
tree_element* tree_element::copy | ( | ) | [inline] |
Deep copy the tree.
Definition at line 331 of file faster_tree.h.
References copy(), eq, gt, and lt.
Referenced by copy(), and learn_detector().
00332 { 00333 tree_element* t = new tree_element(*this); 00334 if(eq != NULL) 00335 { 00336 t->lt = lt->copy(); 00337 t->gt = gt->copy(); 00338 t->eq = eq->copy(); 00339 } 00340 00341 return t; 00342 }
void tree_element::print | ( | std::ostream & | o, | |
std::string | ind = " " | |||
) | const [inline] |
Serialize the tree.
o | Stream to serialize to. | |
ind | The indent level to use for the current branch. |
Definition at line 348 of file faster_tree.h.
References is_corner().
Referenced by learn_detector(), and run_learn_detector().
00349 { 00350 using tag::operator<<; 00351 00352 00353 if(eq == NULL) 00354 o << ind << tag::print << "Is corner: " << is_corner << this << lt << eq << gt; 00355 else 00356 { 00357 o << ind << tag::print << offset_index << this << lt << eq << gt; 00358 lt->print(o, ind + " "); 00359 eq->print(o, ind + " "); 00360 gt->print(o, ind + " "); 00361 } 00362 }
Branch of the tree to take if the offset pixel is much darker than the centre.
Definition at line 42 of file faster_tree.h.
Referenced by copy(), learn_detector(), make_fast_detector(), make_fast_detector_o(), and num_nodes().
Branch of the tree to take if the offset pixel is much brighter than the centre.
Definition at line 43 of file faster_tree.h.
Referenced by copy(), is_leaf(), learn_detector(), make_fast_detector_o(), and num_nodes().
Branch of the tree to take otherwise.
Definition at line 44 of file faster_tree.h.
Referenced by copy(), learn_detector(), make_fast_detector(), make_fast_detector_o(), and num_nodes().
If the node is a leaf, then this is its attribute.
Definition at line 45 of file faster_tree.h.
Referenced by learn_detector(), and make_fast_detector_o().
Offset number of the pixel to examine. This indexes offsets[x].
Definition at line 46 of file faster_tree.h.
Referenced by learn_detector(), and make_fast_detector_o().