MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/fhog_object_detector_ex.cpp:41–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39// ----------------------------------------------------------------------------------------
40
41int main(int argc, char** argv)
42{
43
44 try
45 {
46 // In this example we are going to train a face detector based on the
47 // small faces dataset in the examples/faces directory. So the first
48 // thing we do is load that dataset. This means you need to supply the
49 // path to this faces folder as a command line argument so we will know
50 // where it is.
51 if (argc != 2)
52 {
53 cout << "Give the path to the examples/faces directory as the argument to this" << endl;
54 cout << "program. For example, if you are in the examples folder then execute " << endl;
55 cout << "this program by running: " << endl;
56 cout << " ./fhog_object_detector_ex faces" << endl;
57 cout << endl;
58 return 0;
59 }
60 const std::string faces_directory = argv[1];
61 // The faces directory contains a training dataset and a separate
62 // testing dataset. The training data consists of 4 images, each
63 // annotated with rectangles that bound each human face. The idea is
64 // to use this training data to learn to identify human faces in new
65 // images.
66 //
67 // Once you have trained an object detector it is always important to
68 // test it on data it wasn't trained on. Therefore, we will also load
69 // a separate testing set of 5 images. Once we have a face detector
70 // created from the training data we will see how well it works by
71 // running it on the testing images.
72 //
73 // So here we create the variables that will hold our dataset.
74 // images_train will hold the 4 training images and face_boxes_train
75 // holds the locations of the faces in the training images. So for
76 // example, the image images_train[0] has the faces given by the
77 // rectangles in face_boxes_train[0].
78 dlib::array<array2d<unsigned char> > images_train, images_test;
79 std::vector<std::vector<rectangle> > face_boxes_train, face_boxes_test;
80
81 // Now we load the data. These XML files list the images in each
82 // dataset and also contain the positions of the face boxes. Obviously
83 // you can use any kind of input format you like so long as you store
84 // the data into images_train and face_boxes_train. But for convenience
85 // dlib comes with tools for creating and loading XML image dataset
86 // files. Here you see how to load the data. To create the XML files
87 // you can use the imglab tool which can be found in the tools/imglab
88 // folder. It is a simple graphical tool for labeling objects in images
89 // with boxes. To see how to use it read the tools/imglab/README.txt
90 // file.
91 load_image_dataset(images_train, face_boxes_train, faces_directory+"/training.xml");
92 load_image_dataset(images_test, face_boxes_test, faces_directory+"/testing.xml");
93
94 // Now we do a little bit of pre-processing. The first thing we do is
95 // increase the size of the images by a factor of two. We do this
96 // because it will allow us to detect smaller faces than otherwise would
97 // be practical (since the faces are all now twice as big). Note that,
98 // in addition to resizing the images, these functions also make the

Callers

nothing calls this directly

Calls 15

load_image_datasetFunction · 0.85
rgb_pixelClass · 0.85
evaluate_detectorsFunction · 0.85
num_separable_filtersFunction · 0.85
clear_overlayMethod · 0.80
serializeFunction · 0.70
deserializeFunction · 0.70
draw_fhogFunction · 0.50

Tested by

no test coverage detected