extract_features [--VAR VAL] [--exec FILE] IMAGE1 [IMAGE2 ...]
The program accpets standard GVars3 commandline arguments, and the default parameters are contained in extract_features.cfg
:
offsets.min_radius=2.0 //This must be the same as the value used in training offsets.max_radius=4.2 //This must be the same as the value used in training detector=best_faster.tree //File containing the learned FAST-ER tree threshold=30 //Threshold at which to detect corners skip=2 //Skip this many pixels in the X and Y direction when extracting non-corners debug.verify_detections=0
The images from which features should be extracted are specified on the commandline.
Definition in file extract_features.cc.
#include <gvars3/instances.h>
#include <cvd/image_io.h>
#include <stdint.h>
#include <map>
#include <iterator>
#include <string>
#include "offsets.h"
#include "faster_tree.h"
Go to the source code of this file.
Functions | |
void | extract_feature (string &s, const BasicImage< byte > &im, const ImageRef &pos, int barrier, int o, bool invert_sense) |
int | main (int argc, char **argv) |
Variables | |
static const char | BrighterFlag = 'b' |
static const char | DarkerFlag = 'd' |
static const char | SimilarFlag = 's' |
void extract_feature | ( | string & | s, | |
const BasicImage< byte > & | im, | |||
const ImageRef & | pos, | |||
int | barrier, | |||
int | o, | |||
bool | invert_sense | |||
) |
Extracts a feature from an image.
s | String to extract feature in to | |
im | Image to extract feature from | |
pos | Location to extract feature from | |
barrier | Threshold used to compute feature | |
o | Index in to offsets (i.e. feature orientation) to use | |
invert_sense | Whether or not to invert the extracted feature |
Definition at line 67 of file extract_features.cc.
References BrighterFlag, DarkerFlag, num_offsets, offsets, and SimilarFlag.
Referenced by main().
00068 { 00069 int cb = im[pos] + barrier; 00070 int c_b = im[pos] - barrier; 00071 00072 for(int i=0; i < num_offsets; i++) 00073 { 00074 int pix = im[pos + offsets[o][i]]; 00075 00076 if(pix > cb) 00077 if(invert_sense == false) 00078 s[i] = BrighterFlag; 00079 else 00080 s[i] = DarkerFlag; 00081 else if(pix < c_b) 00082 if(invert_sense == false) 00083 s[i] = DarkerFlag; 00084 else 00085 s[i] = BrighterFlag; 00086 else 00087 s[i] = SimilarFlag; 00088 } 00089 }
int main | ( | int | argc, | |
char ** | argv | |||
) |
Driving program.
argc | Number of commandline arguments | |
argv | List of commandline arguments. Contains GVars3 arguments, and images to process. |
Definition at line 94 of file extract_features.cc.
References create_offsets(), extract_feature(), is_corner(), load_a_tree(), num_offsets, offsets, and offsets_bbox.
00095 { 00096 //The usual initialization. 00097 GUI.LoadFile("extract_features.cfg"); 00098 int lastarg = GUI.parseArguments(argc, argv); 00099 00100 create_offsets(); 00101 00102 //Store corners and noncorners by the string representing the feature. 00103 map<string, uint64_t> corners, non_corners; 00104 00105 //Scratch string of the correct length for extracting features in to. 00106 string scratch(num_offsets, '.'); 00107 00108 //Don't bother examining points outside this border. 00109 int border = max(max(offsets_bbox.first.x, offsets_bbox.first.y), max(offsets_bbox.second.x, offsets_bbox.second.y)); 00110 00111 int threshold = GV3::get<int>("threshold", 30); 00112 string fname=GV3::get<string>("detector", "best_faster.tree"); 00113 00114 //Load a detector from a tree file 00115 tree_element* faster_detector; 00116 00117 ifstream i; 00118 i.open(fname.c_str()); 00119 00120 if(!i.good()) 00121 { 00122 cerr << "Error: " << fname << ": " << strerror(errno) << endl; 00123 exit(1); 00124 } 00125 00126 try{ 00127 faster_detector = load_a_tree(i); 00128 } 00129 catch(ParseError p) 00130 { 00131 cerr << "Parse error in " << fname << endl; 00132 exit(1); 00133 } 00134 00135 //Iterate over all images, extracting features 00136 for(int i=lastarg; i < argc; i++) 00137 { 00138 try{ 00139 Image<byte> im = img_load(argv[i]); 00140 for(int r=border; r < im.size().y - border; r++) 00141 for(int c=border; c < im.size().x - border; c++) 00142 { 00143 ImageRef pos(c,r); 00144 //Test for cornerness 00145 bool is_corner = faster_detector->detect_corner(im, pos, threshold); 00146 00147 //Iterate over all feature orientations and inversions, 00148 //extracting the reatures, and inserting them in to the 00149 //correct bin 00150 for(unsigned int k=0; k < offsets.size(); k++) 00151 for(int l=0; l < 2; l++) 00152 { 00153 extract_feature(scratch, im, pos, threshold, k, l); 00154 00155 if(is_corner) 00156 { 00157 corners[scratch]++; 00158 00159 if(non_corners.count(scratch)) 00160 { 00161 cerr << "Fatal error! extracted corner has an identical non-corner!\n"; 00162 cerr << "Are your offsets correct?\n"; 00163 exit(1); 00164 } 00165 } 00166 else 00167 { 00168 non_corners[scratch]++; 00169 if(corners.count(scratch)) 00170 { 00171 cerr << "Fatal error! extracted non-corner has an identical corner!\n"; 00172 cerr << "Are your offsets correct?\n"; 00173 exit(1); 00174 } 00175 } 00176 } 00177 } 00178 cerr << "Processed " << argv[i] << endl; 00179 } 00180 catch(Exceptions::All e) 00181 { 00182 cerr << "Failed to load " << argv[i] << ": " << e.what << endl; 00183 } 00184 } 00185 00186 cout << num_offsets << endl; 00187 copy(offsets[0].begin(), offsets[0].end(), ostream_iterator<ImageRef>(cout, " ")); 00188 cout << endl; 00189 00190 for(map<string, uint64_t>::iterator i=corners.begin(); i != corners.end(); i++) 00191 cout << i->first << " " << i->second << " 1" << endl; 00192 for(map<string, uint64_t>::iterator i=non_corners.begin(); i != non_corners.end(); i++) 00193 cout << i->first << " " << i->second << " 0" << endl; 00194 }
const char BrighterFlag = 'b' [static] |
Character code for pixels significantly brighter than the centre.
Definition at line 56 of file extract_features.cc.
Referenced by extract_feature().
const char DarkerFlag = 'd' [static] |
Character code for pixels significantly darker than the centre.
Definition at line 57 of file extract_features.cc.
Referenced by extract_feature().
const char SimilarFlag = 's' [static] |
Character code for pixels similar to the centre.
Definition at line 58 of file extract_features.cc.
Referenced by extract_feature().