| 192 | // ---------------------------------------------------------------------------------------- |
| 193 | |
| 194 | int main() |
| 195 | { |
| 196 | try |
| 197 | { |
| 198 | // Get some data |
| 199 | dlib::array<array2d<unsigned char> > images; |
| 200 | std::vector<std::vector<rectangle> > object_locations; |
| 201 | make_simple_test_data(images, object_locations); |
| 202 | |
| 203 | |
| 204 | typedef scan_image_pyramid<pyramid_down<5>, very_simple_feature_extractor> image_scanner_type; |
| 205 | image_scanner_type scanner; |
| 206 | // Instead of using setup_grid_detection_templates() like in object_detector_ex.cpp, let's manually |
| 207 | // setup the sliding window box. We use a window with the same shape as the white boxes we |
| 208 | // are trying to detect. |
| 209 | const rectangle object_box = compute_box_dimensions(1, // width/height ratio |
| 210 | 70*70 // box area |
| 211 | ); |
| 212 | scanner.add_detection_template(object_box, create_grid_detection_template(object_box,2,2)); |
| 213 | |
| 214 | // Since our sliding window is already the right size to detect our objects we don't need |
| 215 | // to use an image pyramid. So setting this to 1 turns off the image pyramid. |
| 216 | scanner.set_max_pyramid_levels(1); |
| 217 | |
| 218 | |
| 219 | // While the very_simple_feature_extractor doesn't have any parameters, when you go solve |
| 220 | // real problems you might define a feature extractor which has some non-trivial parameters |
| 221 | // that need to be setup before it can be used. So you need to be able to pass these parameters |
| 222 | // to the scanner object somehow. You can do this using the copy_configuration() function as |
| 223 | // shown below. |
| 224 | very_simple_feature_extractor fe; |
| 225 | /* |
| 226 | setup the parameters in the fe object. |
| 227 | ... |
| 228 | */ |
| 229 | // The scanner will use very_simple_feature_extractor::copy_configuration() to copy the state |
| 230 | // of fe into its internal feature extractor. |
| 231 | scanner.copy_configuration(fe); |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | // Now that we have defined the kind of sliding window classifier system we want and stored |
| 237 | // the details into the scanner object we are ready to use the structural_object_detection_trainer |
| 238 | // to learn the weight vector and threshold needed to produce a complete object detector. |
| 239 | structural_object_detection_trainer<image_scanner_type> trainer(scanner); |
| 240 | trainer.set_num_threads(4); // Set this to the number of processing cores on your machine. |
| 241 | |
| 242 | |
| 243 | // The trainer will try and find the detector which minimizes the number of detection mistakes. |
| 244 | // This function controls how it decides if a detection output is a mistake or not. The bigger |
| 245 | // the input to this function the more strict it is in deciding if the detector is correctly |
| 246 | // hitting the targets. Try reducing the value to 0.001 and observing the results. You should |
| 247 | // see that the detections aren't exactly on top of the white squares anymore. See the documentation |
| 248 | // for the structural_object_detection_trainer and structural_svm_object_detection_problem objects |
| 249 | // for a more detailed discussion of this parameter. |
| 250 | trainer.set_match_eps(0.95); |
| 251 |
nothing calls this directly
no test coverage detected