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

Function main

examples/random_cropper_ex.cpp:22–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20// ----------------------------------------------------------------------------------------
21
22int main(int argc, char** argv) try
23{
24 if (argc != 2)
25 {
26 cout << "Give an image dataset XML file to run this program." << endl;
27 cout << "For example, if you are running from the examples folder then run this program by typing" << endl;
28 cout << " ./random_cropper_ex faces/training.xml" << endl;
29 cout << endl;
30 return 0;
31 }
32
33 // First lets load a dataset
34 std::vector<matrix<rgb_pixel>> images;
35 std::vector<std::vector<mmod_rect>> boxes;
36 load_image_dataset(images, boxes, argv[1]);
37
38 // Here we make our random_cropper. It has a number of options.
39 random_cropper cropper;
40 // We can tell it how big we want the cropped images to be.
41 cropper.set_chip_dims(400,400);
42 // Also, when doing cropping, it will map the object annotations from the
43 // dataset to the cropped image as well as perform random scale jittering.
44 // You can tell it how much scale jittering you would like by saying "please
45 // make the objects in the crops have a min and max size of such and such".
46 // You do that by calling these two functions. Here we are saying we want the
47 // objects in our crops to be no more than 0.8*400 pixels in height and width.
48 cropper.set_max_object_size(0.8);
49 // And also that they shouldn't be too small. Specifically, each object's smallest
50 // dimension (i.e. height or width) should be at least 60 pixels and at least one of
51 // the dimensions must be at least 80 pixels. So the smallest objects the cropper will
52 // output will be either 80x60 or 60x80.
53 cropper.set_min_object_size(80,60);
54 // The cropper can also randomly mirror and rotate crops, which we ask it to
55 // perform as well.
56 cropper.set_randomly_flip(true);
57 cropper.set_max_rotation_degrees(50);
58 // This fraction of crops are from random parts of images, rather than being centered
59 // on some object.
60 cropper.set_background_crops_fraction(0.2);
61
62 // Now ask the cropper to generate a bunch of crops. The output is stored in
63 // crops and crop_boxes.
64 std::vector<matrix<rgb_pixel>> crops;
65 std::vector<std::vector<mmod_rect>> crop_boxes;
66 // Make 1000 crops.
67 cropper(1000, images, boxes, crops, crop_boxes);
68
69 // Finally, lets look at the results
70 image_window win;
71 for (size_t i = 0; i < crops.size(); ++i)
72 {
73 win.clear_overlay();
74 win.set_image(crops[i]);
75 for (auto b : crop_boxes[i])
76 {
77 // Note that mmod_rect has an ignore field. If an object was labeled
78 // ignore in boxes then it will still be labeled as ignore in
79 // crop_boxes. Moreover, objects that are not well contained within

Callers

nothing calls this directly

Calls 14

load_image_datasetFunction · 0.85
rgb_pixelClass · 0.85
set_chip_dimsMethod · 0.80
set_max_object_sizeMethod · 0.80
set_min_object_sizeMethod · 0.80
set_randomly_flipMethod · 0.80
clear_overlayMethod · 0.80
sizeMethod · 0.45
set_imageMethod · 0.45
add_overlayMethod · 0.45

Tested by

no test coverage detected