File size: 64,185 Bytes
9375c9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - load_image_dataset.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2012  Davis E. King ([email protected])
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_LOAD_IMAGE_DaTASET_Hh_
<font color='#0000FF'>#define</font> DLIB_LOAD_IMAGE_DaTASET_Hh_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='load_image_dataset_abstract.h.html'>load_image_dataset_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../misc_api.h.html'>../misc_api.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../dir_nav.h.html'>../dir_nav.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../image_io.h.html'>../image_io.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../array.h.html'>../array.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>vector<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../geometry.h.html'>../geometry.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='image_dataset_metadata.h.html'>image_dataset_metadata.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>string<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>set<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../image_processing/full_object_detection.h.html'>../image_processing/full_object_detection.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>utility<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>limits<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../image_transforms/image_pyramid.h.html'>../image_transforms/image_pyramid.h</a>"


<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='image_dataset_file'></a>image_dataset_file</b>
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <b><a name='image_dataset_file'></a>image_dataset_file</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> filename<font face='Lucida Console'>)</font>
        <b>{</b>
            _skip_empty_images <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            _have_parts <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            _filename <font color='#5555FF'>=</font> filename;
            _box_area_thresh <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        image_dataset_file <b><a name='boxes_match_label'></a>boxes_match_label</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> label
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            image_dataset_file <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
            temp._labels.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>label<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> temp;
        <b>}</b>

        image_dataset_file <b><a name='skip_empty_images'></a>skip_empty_images</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            image_dataset_file <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
            temp._skip_empty_images <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>return</font> temp;
        <b>}</b>

        image_dataset_file <b><a name='boxes_have_parts'></a>boxes_have_parts</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            image_dataset_file <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
            temp._have_parts <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>return</font> temp;
        <b>}</b>

        image_dataset_file <b><a name='shrink_big_images'></a>shrink_big_images</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>double</u></font> new_box_area_thresh <font color='#5555FF'>=</font> <font color='#979000'>150</font><font color='#5555FF'>*</font><font color='#979000'>150</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            image_dataset_file <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
            temp._box_area_thresh <font color='#5555FF'>=</font> new_box_area_thresh;
            <font color='#0000FF'>return</font> temp;
        <b>}</b>

        <font color='#0000FF'><u>bool</u></font> <b><a name='should_load_box'></a>should_load_box</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_dataset_metadata::box<font color='#5555FF'>&amp;</font> box
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>_have_parts <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> box.parts.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>_labels.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>_labels.<font color='#BB00BB'>count</font><font face='Lucida Console'>(</font>box.label<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>

        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> <b><a name='get_filename'></a>get_filename</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> _filename; <b>}</b>
        <font color='#0000FF'><u>bool</u></font> <b><a name='should_skip_empty_images'></a>should_skip_empty_images</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> _skip_empty_images; <b>}</b>
        <font color='#0000FF'><u>bool</u></font> <b><a name='should_boxes_have_parts'></a>should_boxes_have_parts</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> _have_parts; <b>}</b>
        <font color='#0000FF'><u>double</u></font> <b><a name='box_area_thresh'></a>box_area_thresh</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> _box_area_thresh; <b>}</b>
        <font color='#0000FF'>const</font> std::set<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> <b><a name='get_selected_box_labels'></a>get_selected_box_labels</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> _labels; <b>}</b>

    <font color='#0000FF'>private</font>:
        std::string _filename;
        std::set<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font> _labels;
        <font color='#0000FF'><u>bool</u></font> _skip_empty_images;
        <font color='#0000FF'><u>bool</u></font> _have_parts;
        <font color='#0000FF'><u>double</u></font> _box_area_thresh;

    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> array_type
        <font color='#5555FF'>&gt;</font>
    std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <b><a name='load_image_dataset'></a>load_image_dataset</b> <font face='Lucida Console'>(</font>
        array_type<font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> object_locations,
        <font color='#0000FF'>const</font> image_dataset_file<font color='#5555FF'>&amp;</font> source
    <font face='Lucida Console'>)</font>
    <b>{</b>
        images.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        object_locations.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> ignored_rects;

        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> dlib::image_dataset_metadata;
        dataset data;
        <font color='#BB00BB'>load_image_dataset_metadata</font><font face='Lucida Console'>(</font>data, source.<font color='#BB00BB'>get_filename</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// Set the current directory to be the one that contains the
</font>        <font color='#009900'>// metadata file. We do this because the file might contain
</font>        <font color='#009900'>// file paths which are relative to this folder.
</font>        locally_change_current_dir <font color='#BB00BB'>chdir</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_parent_directory</font><font face='Lucida Console'>(</font><font color='#BB00BB'>file</font><font face='Lucida Console'>(</font>source.<font color='#BB00BB'>get_filename</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> array_type::value_type image_type;


        image_type img;
        std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> rects, ignored;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> data.images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>double</u></font> min_rect_size <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            rects.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            ignored.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> data.images[i].boxes.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>source.<font color='#BB00BB'>should_load_box</font><font face='Lucida Console'>(</font>data.images[i].boxes[j]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data.images[i].boxes[j].ignore<font face='Lucida Console'>)</font>
                    <b>{</b>
                        ignored.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>data.images[i].boxes[j].rect<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        rects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>data.images[i].boxes[j].rect<font face='Lucida Console'>)</font>;
                        min_rect_size <font color='#5555FF'>=</font> std::min<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>min_rect_size, rects.<font color='#BB00BB'>back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>source.<font color='#BB00BB'>should_skip_empty_images</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>load_image</font><font face='Lucida Console'>(</font>img, data.images[i].filename<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>  
                <b>{</b>
                    <font color='#009900'>// if shrinking the image would still result in the smallest box being
</font>                    <font color='#009900'>// bigger than the box area threshold then shrink the image.
</font>                    <font color='#0000FF'>while</font><font face='Lucida Console'>(</font>min_rect_size<font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>/</font><font color='#979000'>2</font> <font color='#5555FF'>&gt;</font> source.<font color='#BB00BB'>box_area_thresh</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        pyramid_down<font color='#5555FF'>&lt;</font><font color='#979000'>2</font><font color='#5555FF'>&gt;</font> pyr;
                        <font color='#BB00BB'>pyr</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
                        min_rect_size <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>1.0</font><font color='#5555FF'>/</font><font color='#979000'>2.0</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>1.0</font><font color='#5555FF'>/</font><font color='#979000'>2.0</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : rects<font face='Lucida Console'>)</font>
                            r <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : ignored<font face='Lucida Console'>)</font>
                            r <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>while</font><font face='Lucida Console'>(</font>min_rect_size<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> source.<font color='#BB00BB'>box_area_thresh</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        pyramid_down<font color='#5555FF'>&lt;</font><font color='#979000'>3</font><font color='#5555FF'>&gt;</font> pyr;
                        <font color='#BB00BB'>pyr</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
                        min_rect_size <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : rects<font face='Lucida Console'>)</font>
                            r <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : ignored<font face='Lucida Console'>)</font>
                            r <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
                images.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
                object_locations.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>rects<font face='Lucida Console'>)</font>;
                ignored_rects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>ignored<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>return</font> ignored_rects;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> impl
    <b>{</b>
        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>size_t</u></font> <b><a name='num_non_ignored_boxes'></a>num_non_ignored_boxes</b> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>mmod_rect<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> rects<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>size_t</u></font> cnt <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font> b : rects<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>b.ignore<font face='Lucida Console'>)</font>
                    cnt<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
            <b>}</b>
            <font color='#0000FF'>return</font> cnt;
        <b>}</b>
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> array_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='load_image_dataset'></a>load_image_dataset</b> <font face='Lucida Console'>(</font>
        array_type<font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>mmod_rect<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> object_locations,
        <font color='#0000FF'>const</font> image_dataset_file<font color='#5555FF'>&amp;</font> source
    <font face='Lucida Console'>)</font>
    <b>{</b>
        images.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        object_locations.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> dlib::image_dataset_metadata;
        dataset data;
        <font color='#BB00BB'>load_image_dataset_metadata</font><font face='Lucida Console'>(</font>data, source.<font color='#BB00BB'>get_filename</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// Set the current directory to be the one that contains the
</font>        <font color='#009900'>// metadata file. We do this because the file might contain
</font>        <font color='#009900'>// file paths which are relative to this folder.
</font>        locally_change_current_dir <font color='#BB00BB'>chdir</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_parent_directory</font><font face='Lucida Console'>(</font><font color='#BB00BB'>file</font><font face='Lucida Console'>(</font>source.<font color='#BB00BB'>get_filename</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> array_type::value_type image_type;

        image_type img;
        std::vector<font color='#5555FF'>&lt;</font>mmod_rect<font color='#5555FF'>&gt;</font> rects;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> data.images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>double</u></font> min_rect_size <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            rects.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> data.images[i].boxes.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>source.<font color='#BB00BB'>should_load_box</font><font face='Lucida Console'>(</font>data.images[i].boxes[j]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data.images[i].boxes[j].ignore<font face='Lucida Console'>)</font>
                    <b>{</b>
                        rects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>ignored_mmod_rect</font><font face='Lucida Console'>(</font>data.images[i].boxes[j].rect<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        rects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>mmod_rect</font><font face='Lucida Console'>(</font>data.images[i].boxes[j].rect<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        min_rect_size <font color='#5555FF'>=</font> std::min<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>min_rect_size, rects.<font color='#BB00BB'>back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.rect.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    rects.<font color='#BB00BB'>back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.label <font color='#5555FF'>=</font> data.images[i].boxes[j].label;

                <b>}</b>
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>source.<font color='#BB00BB'>should_skip_empty_images</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> impl::<font color='#BB00BB'>num_non_ignored_boxes</font><font face='Lucida Console'>(</font>rects<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>load_image</font><font face='Lucida Console'>(</font>img, data.images[i].filename<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>  
                <b>{</b>
                    <font color='#009900'>// if shrinking the image would still result in the smallest box being
</font>                    <font color='#009900'>// bigger than the box area threshold then shrink the image.
</font>                    <font color='#0000FF'>while</font><font face='Lucida Console'>(</font>min_rect_size<font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>/</font><font color='#979000'>2</font> <font color='#5555FF'>&gt;</font> source.<font color='#BB00BB'>box_area_thresh</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        pyramid_down<font color='#5555FF'>&lt;</font><font color='#979000'>2</font><font color='#5555FF'>&gt;</font> pyr;
                        <font color='#BB00BB'>pyr</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
                        min_rect_size <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>1.0</font><font color='#5555FF'>/</font><font color='#979000'>2.0</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>1.0</font><font color='#5555FF'>/</font><font color='#979000'>2.0</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : rects<font face='Lucida Console'>)</font>
                            r.rect <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r.rect<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>while</font><font face='Lucida Console'>(</font>min_rect_size<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> source.<font color='#BB00BB'>box_area_thresh</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        pyramid_down<font color='#5555FF'>&lt;</font><font color='#979000'>3</font><font color='#5555FF'>&gt;</font> pyr;
                        <font color='#BB00BB'>pyr</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
                        min_rect_size <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : rects<font face='Lucida Console'>)</font>
                            r.rect <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r.rect<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
                images.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                object_locations.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>move</font><font face='Lucida Console'>(</font>rects<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#009900'>// ******* THIS FUNCTION IS DEPRECATED, you should use another version of load_image_dataset() *******
</font>    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type, 
        <font color='#0000FF'>typename</font> MM
        <font color='#5555FF'>&gt;</font>
    std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <b><a name='load_image_dataset'></a>load_image_dataset</b> <font face='Lucida Console'>(</font>
        array<font color='#5555FF'>&lt;</font>image_type,MM<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> object_locations,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> filename,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> label,
        <font color='#0000FF'><u>bool</u></font> skip_empty_images <font color='#5555FF'>=</font> <font color='#979000'>false</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        image_dataset_file <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font>filename<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>label.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            f <font color='#5555FF'>=</font> f.<font color='#BB00BB'>boxes_match_label</font><font face='Lucida Console'>(</font>label<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>skip_empty_images<font face='Lucida Console'>)</font>
            f <font color='#5555FF'>=</font> f.<font color='#BB00BB'>skip_empty_images</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> <font color='#BB00BB'>load_image_dataset</font><font face='Lucida Console'>(</font>images, object_locations, f<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> array_type
        <font color='#5555FF'>&gt;</font>
    std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <b><a name='load_image_dataset'></a>load_image_dataset</b> <font face='Lucida Console'>(</font>
        array_type<font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> object_locations,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> filename
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>load_image_dataset</font><font face='Lucida Console'>(</font>images, object_locations, <font color='#BB00BB'>image_dataset_file</font><font face='Lucida Console'>(</font>filename<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> array_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='load_image_dataset'></a>load_image_dataset</b> <font face='Lucida Console'>(</font>
        array_type<font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>mmod_rect<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> object_locations,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> filename
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>load_image_dataset</font><font face='Lucida Console'>(</font>images, object_locations, <font color='#BB00BB'>image_dataset_file</font><font face='Lucida Console'>(</font>filename<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> array_type
        <font color='#5555FF'>&gt;</font>
    std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <b><a name='load_image_dataset'></a>load_image_dataset</b> <font face='Lucida Console'>(</font>
        array_type<font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>full_object_detection<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> object_locations,
        <font color='#0000FF'>const</font> image_dataset_file<font color='#5555FF'>&amp;</font> source,
        std::vector<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> parts_list
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> array_type::value_type image_type;
        parts_list.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        images.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        object_locations.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> dlib::image_dataset_metadata;
        dataset data;
        <font color='#BB00BB'>load_image_dataset_metadata</font><font face='Lucida Console'>(</font>data, source.<font color='#BB00BB'>get_filename</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// Set the current directory to be the one that contains the
</font>        <font color='#009900'>// metadata file. We do this because the file might contain
</font>        <font color='#009900'>// file paths which are relative to this folder.
</font>        locally_change_current_dir <font color='#BB00BB'>chdir</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_parent_directory</font><font face='Lucida Console'>(</font><font color='#BB00BB'>file</font><font face='Lucida Console'>(</font>source.<font color='#BB00BB'>get_filename</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


        std::set<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font> all_parts;

        <font color='#009900'>// find out what parts are being used in the dataset.  Store results in all_parts.
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> data.images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> data.images[i].boxes.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>source.<font color='#BB00BB'>should_load_box</font><font face='Lucida Console'>(</font>data.images[i].boxes[j]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>const</font> std::map<font color='#5555FF'>&lt;</font>std::string,point<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> parts <font color='#5555FF'>=</font> data.images[i].boxes[j].parts;
                    std::map<font color='#5555FF'>&lt;</font>std::string,point<font color='#5555FF'>&gt;</font>::const_iterator itr;

                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>itr <font color='#5555FF'>=</font> parts.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; itr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> parts.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>itr<font face='Lucida Console'>)</font>
                    <b>{</b>
                        all_parts.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// make a mapping between part names and the integers [0, all_parts.size())
</font>        std::map<font color='#5555FF'>&lt;</font>std::string,<font color='#0000FF'><u>int</u></font><font color='#5555FF'>&gt;</font> parts_idx;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>std::set<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font>::iterator i <font color='#5555FF'>=</font> all_parts.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; i <font color='#5555FF'>!</font><font color='#5555FF'>=</font> all_parts.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            parts_idx[<font color='#5555FF'>*</font>i] <font color='#5555FF'>=</font> parts_list.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            parts_list.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>i<font face='Lucida Console'>)</font>;
        <b>}</b>

        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> ignored_rects;
        std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> ignored;
        image_type img;
        std::vector<font color='#5555FF'>&lt;</font>full_object_detection<font color='#5555FF'>&gt;</font> object_dets;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> data.images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>double</u></font> min_rect_size <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            object_dets.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            ignored.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> data.images[i].boxes.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>source.<font color='#BB00BB'>should_load_box</font><font face='Lucida Console'>(</font>data.images[i].boxes[j]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data.images[i].boxes[j].ignore<font face='Lucida Console'>)</font>
                    <b>{</b>
                        ignored.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>data.images[i].boxes[j].rect<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        std::vector<font color='#5555FF'>&lt;</font>point<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>partlist</font><font face='Lucida Console'>(</font>parts_idx.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, OBJECT_PART_NOT_PRESENT<font face='Lucida Console'>)</font>;

                        <font color='#009900'>// populate partlist with all the parts present in this box.
</font>                        <font color='#0000FF'>const</font> std::map<font color='#5555FF'>&lt;</font>std::string,point<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> parts <font color='#5555FF'>=</font> data.images[i].boxes[j].parts;
                        std::map<font color='#5555FF'>&lt;</font>std::string,point<font color='#5555FF'>&gt;</font>::const_iterator itr;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>itr <font color='#5555FF'>=</font> parts.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; itr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> parts.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>itr<font face='Lucida Console'>)</font>
                        <b>{</b>
                            partlist[parts_idx[itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first]] <font color='#5555FF'>=</font> itr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>second;
                        <b>}</b>

                        object_dets.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>full_object_detection</font><font face='Lucida Console'>(</font>data.images[i].boxes[j].rect, partlist<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        min_rect_size <font color='#5555FF'>=</font> std::min<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>min_rect_size, object_dets.<font color='#BB00BB'>back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>source.<font color='#BB00BB'>should_skip_empty_images</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> object_dets.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>load_image</font><font face='Lucida Console'>(</font>img, data.images[i].filename<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>object_dets.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>  
                <b>{</b>
                    <font color='#009900'>// if shrinking the image would still result in the smallest box being
</font>                    <font color='#009900'>// bigger than the box area threshold then shrink the image.
</font>                    <font color='#0000FF'>while</font><font face='Lucida Console'>(</font>min_rect_size<font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>/</font><font color='#979000'>2</font> <font color='#5555FF'>&gt;</font> source.<font color='#BB00BB'>box_area_thresh</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        pyramid_down<font color='#5555FF'>&lt;</font><font color='#979000'>2</font><font color='#5555FF'>&gt;</font> pyr;
                        <font color='#BB00BB'>pyr</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
                        min_rect_size <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>1.0</font><font color='#5555FF'>/</font><font color='#979000'>2.0</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>1.0</font><font color='#5555FF'>/</font><font color='#979000'>2.0</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : object_dets<font face='Lucida Console'>)</font>
                        <b>{</b>
                            r.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> k <font color='#5555FF'>=</font> <font color='#979000'>0</font>; k <font color='#5555FF'>&lt;</font> r.<font color='#BB00BB'>num_parts</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font>
                                r.<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>k<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>point_down</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>k<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <b>}</b>
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : ignored<font face='Lucida Console'>)</font>
                        <b>{</b>
                            r <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r<font face='Lucida Console'>)</font>;
                        <b>}</b>
                    <b>}</b>
                    <font color='#0000FF'>while</font><font face='Lucida Console'>(</font>min_rect_size<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> source.<font color='#BB00BB'>box_area_thresh</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        pyramid_down<font color='#5555FF'>&lt;</font><font color='#979000'>3</font><font color='#5555FF'>&gt;</font> pyr;
                        <font color='#BB00BB'>pyr</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
                        min_rect_size <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#979000'>2.0</font><font color='#5555FF'>/</font><font color='#979000'>3.0</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : object_dets<font face='Lucida Console'>)</font>
                        <b>{</b>
                            r.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> k <font color='#5555FF'>=</font> <font color='#979000'>0</font>; k <font color='#5555FF'>&lt;</font> r.<font color='#BB00BB'>num_parts</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font>
                                r.<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>k<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>point_down</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>k<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <b>}</b>
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> r : ignored<font face='Lucida Console'>)</font>
                        <b>{</b>
                            r <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>r<font face='Lucida Console'>)</font>;
                        <b>}</b>
                    <b>}</b>
                <b>}</b>
                images.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
                object_locations.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>object_dets<font face='Lucida Console'>)</font>;
                ignored_rects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>ignored<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>


        <font color='#0000FF'>return</font> ignored_rects;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> array_type
        <font color='#5555FF'>&gt;</font>
    std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <b><a name='load_image_dataset'></a>load_image_dataset</b> <font face='Lucida Console'>(</font>
        array_type<font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>full_object_detection<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> object_locations,
        <font color='#0000FF'>const</font> image_dataset_file<font color='#5555FF'>&amp;</font> source 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::vector<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font> parts_list;
        <font color='#0000FF'>return</font> <font color='#BB00BB'>load_image_dataset</font><font face='Lucida Console'>(</font>images, object_locations, source, parts_list<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> array_type 
        <font color='#5555FF'>&gt;</font>
    std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <b><a name='load_image_dataset'></a>load_image_dataset</b> <font face='Lucida Console'>(</font>
        array_type<font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>full_object_detection<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> object_locations,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> filename
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::vector<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font> parts_list;
        <font color='#0000FF'>return</font> <font color='#BB00BB'>load_image_dataset</font><font face='Lucida Console'>(</font>images, object_locations, <font color='#BB00BB'>image_dataset_file</font><font face='Lucida Console'>(</font>filename<font face='Lucida Console'>)</font>, parts_list<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_LOAD_IMAGE_DaTASET_Hh_
</font>

</pre></body></html>