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

Function main

examples/object_detector_ex.cpp:102–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100// ----------------------------------------------------------------------------------------
101
102int main()
103{
104 try
105 {
106 // The first thing we do is create the set of 3 images discussed above.
107 dlib::array<array2d<unsigned char> > images;
108 std::vector<std::vector<rectangle> > object_locations;
109 make_simple_test_data(images, object_locations);
110
111
112 /*
113 This next block of code specifies the type of sliding window classifier we will
114 be using to detect the white squares. The most important thing here is the
115 scan_image_pyramid template. Instances of this template represent the core
116 of a sliding window classifier. To go into more detail, the sliding window
117 classifiers used by this object have three parts:
118 1. The underlying feature extraction. See the dlib documentation for a detailed
119 discussion of how the hashed_feature_image and hog_image feature extractors
120 work. However, to understand this example, all you need to know is that the
121 feature extractor associates a vector with each location in an image. This
122 vector is supposed to capture information which describes how parts of the
123 image look. Importantly, it should do this in a way that is relevant to the
124 problem you are trying to solve.
125
126 2. A detection template. This is a rectangle which defines the shape of a
127 sliding window (i.e. the object_box), as well as a set of rectangular feature
128 extraction regions inside it. This set of regions defines the spatial
129 structure of the overall feature extraction within a sliding window. In
130 particular, each location of a sliding window has a feature vector
131 associated with it. This feature vector is defined as follows:
132 - Let N denote the number of feature extraction zones.
133 - Let M denote the dimensionality of the vectors output by Feature_extractor_type
134 objects.
135 - Let F(i) == the M dimensional vector which is the sum of all vectors
136 given by our Feature_extractor_type object inside the ith feature extraction
137 zone.
138 - Then the feature vector for a sliding window is an M*N dimensional vector
139 [F(1) F(2) F(3) ... F(N)] (i.e. it is a concatenation of the N vectors).
140 This feature vector can be thought of as a collection of N "bags of features",
141 each bag coming from a spatial location determined by one of the rectangular
142 feature extraction zones.
143
144 3. A weight vector and a threshold value. The dot product between the weight
145 vector and the feature vector for a sliding window location gives the score
146 of the window. If this score is greater than the threshold value then the
147 window location is output as a detection. You don't need to determine these
148 parameters yourself. They are automatically populated by the
149 structural_object_detection_trainer.
150
151 The sliding window classifiers described above are applied to every level of an
152 image pyramid. So you need to tell scan_image_pyramid what kind of pyramid you want
153 to use. In this case we are using pyramid_down<2> which downsamples each pyramid
154 layer by half (if you want to use a finer image pyramid then just change the
155 template argument to a larger value. For example, using pyramid_down<5> would
156 downsample each layer by a ratio of 5 to 4).
157
158 Finally, some of the feature extraction zones are allowed to move freely within the
159 object box. This means that when we are sliding the classifier over an image, some

Callers

nothing calls this directly

Calls 15

setup_hashed_featuresFunction · 0.85
rgb_pixelClass · 0.85
clear_overlayMethod · 0.80
make_simple_test_dataFunction · 0.70
serializeFunction · 0.70
deserializeFunction · 0.70
set_num_threadsMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected