Classes | |
struct | block_bytecode |
This struct contains a byte code compiled version of the detector. More... | |
struct | block_bytecode::fast_detector_bit |
This is a bytecode element for the bytecode-compiled detector. More... | |
Functions | |
block_bytecode | tree_element::make_fast_detector (int xsize) const |
void | tree_element::make_fast_detector_o (std::vector< block_bytecode::fast_detector_bit > &v, int n, int xsize, int N, bool invert) const |
block_bytecode tree_element::make_fast_detector | ( | int | xsize | ) | const [inline, inherited] |
Compile the detector to bytecode.
The bytecode is not a tree, but a graph. This is because the detector is applied in all orientations: offsets are integers which are indices in to a list of (x,y) offsets and there are multiple lists of offsets. The tree is also applied with intensity inversion.
xsize | The width of the image. |
Definition at line 92 of file faster_tree.h.
References tree_element::gt, invert(), tree_element::lt, tree_element::make_fast_detector_o(), and offsets.
Referenced by run_learn_detector(), tree_detect_corners(), and tree_detect_corners_all().
00093 { 00094 std::vector<block_bytecode::fast_detector_bit> f; 00095 00096 for(int invert=0; invert < 2; invert++) 00097 for(unsigned int i=0; i < offsets.size(); i++) 00098 { 00099 //Make a FAST detector at a certain orientation 00100 std::vector<block_bytecode::fast_detector_bit> tmp(1); 00101 make_fast_detector_o(tmp, 0, xsize, i, invert); 00102 00103 int endpos = f.size() + tmp.size(); 00104 int startpos = f.size(); 00105 00106 //Append tmp on to f, filling in the non-corners (jumps to endpos) 00107 //and correcting the intermediate jumps destinations 00108 for(unsigned int i=0 ; i < tmp.size(); i++) 00109 { 00110 f.push_back(tmp[i]); 00111 00112 if(f.back().eq == -1) 00113 f.back().eq = endpos; 00114 else if(f.back().eq > 0) 00115 f.back().eq += startpos; 00116 00117 if(f.back().gt == -1) 00118 f.back().gt = endpos; 00119 else if(f.back().gt > 0) 00120 f.back().gt += startpos; 00121 00122 if(f.back().lt == -1) 00123 f.back().lt = endpos; 00124 else if(f.back().lt > 0) 00125 f.back().lt += startpos; 00126 00127 } 00128 } 00129 00130 //We need a final endpoint for non-corners 00131 f.resize(f.size() + 1); 00132 f.back().offset = 0; 00133 f.back().lt = 0; 00134 f.back().gt = 0; 00135 f.back().eq = 0; 00136 00137 //Now we need an extra endpoint for corners 00138 for(unsigned int i=0; i < f.size(); i++) 00139 { 00140 //EQ is always non-corner 00141 if(f[i].lt == -2) 00142 f[i].lt = f.size(); 00143 if(f[i].gt == -2) 00144 f[i].gt = f.size(); 00145 } 00146 00147 f.resize(f.size() + 1); 00148 f.back().offset = 0; 00149 f.back().lt = 0; 00150 f.back().gt = 1; 00151 f.back().eq = 0; 00152 00153 block_bytecode r = {f}; 00154 00155 return r; 00156 }
void tree_element::make_fast_detector_o | ( | std::vector< block_bytecode::fast_detector_bit > & | v, | |
int | n, | |||
int | xsize, | |||
int | N, | |||
bool | invert | |||
) | const [inline, private, inherited] |
This compiles the tree in a single orientation and form to bytecode.
This is called repeatedly by make_fast_detector. A jump destination of -1 refers to a non corner and a destination of -2 refers to a corner.
v | Bytecode storage | |
n | Position in v to compile the bytecode to | |
xsize | Width of the image | |
N | orientation of the tree | |
invert | whether or not to perform and intensity inversion. |
Definition at line 175 of file faster_tree.h.
References tree_element::eq, tree_element::gt, tree_element::is_corner, tree_element::is_leaf(), tree_element::lt, tree_element::make_fast_detector_o(), tree_element::offset_index, and offsets.
Referenced by tree_element::make_fast_detector(), and tree_element::make_fast_detector_o().
00176 { 00177 //-1 for non-corner 00178 //-2 for corner 00179 00180 if(eq == NULL) 00181 { 00182 //If the tree is a single leaf, then we end up here. In this case, it must be 00183 //a non-corner, otherwise the strength would be inf. 00184 v[n].offset = 0; 00185 v[n].lt = -1; 00186 v[n].gt = -1; 00187 v[n].eq = -1; 00188 } 00189 else 00190 { 00191 v[n].offset = offsets[N][offset_index].x + offsets[N][offset_index].y * xsize; 00192 00193 if(eq->is_leaf()) 00194 v[n].eq = -1; //Can only be non-corner! 00195 else 00196 { 00197 v[n].eq = v.size(); 00198 v.resize(v.size() + 1); 00199 eq->make_fast_detector_o(v, v[n].eq, xsize, N, invert); 00200 } 00201 00202 const tree_element* llt = lt; 00203 const tree_element* lgt = gt; 00204 00205 if(invert) 00206 std::swap(llt, lgt); 00207 00208 if(llt->is_leaf()) 00209 { 00210 v[n].lt = -1 - llt->is_corner; 00211 } 00212 else 00213 { 00214 v[n].lt = v.size(); 00215 v.resize(v.size() + 1); 00216 llt->make_fast_detector_o(v, v[n].lt, xsize, N, invert); 00217 } 00218 00219 00220 if(lgt->is_leaf()) 00221 v[n].gt = -1 - lgt->is_corner; 00222 else 00223 { 00224 v[n].gt = v.size(); 00225 v.resize(v.size() + 1); 00226 lgt->make_fast_detector_o(v, v[n].gt, xsize, N, invert); 00227 } 00228 } 00229 }