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

Function pick_best_window_size

examples/train_object_detector.cpp:88–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86// ----------------------------------------------------------------------------------------
87
88void pick_best_window_size (
89 const std::vector<std::vector<rectangle> >& boxes,
90 unsigned long& width,
91 unsigned long& height,
92 const unsigned long target_size
93)
94/*!
95 ensures
96 - Finds the average aspect ratio of the elements of boxes and outputs a width
97 and height such that the aspect ratio is equal to the average and also the
98 area is equal to target_size. That is, the following will be approximately true:
99 - #width*#height == target_size
100 - #width/#height == the average aspect ratio of the elements of boxes.
101!*/
102{
103 // find the average width and height
104 running_stats<double> avg_width, avg_height;
105 for (unsigned long i = 0; i < boxes.size(); ++i)
106 {
107 for (unsigned long j = 0; j < boxes[i].size(); ++j)
108 {
109 avg_width.add(boxes[i][j].width());
110 avg_height.add(boxes[i][j].height());
111 }
112 }
113
114 // now adjust the box size so that it is about target_pixels pixels in size
115 double size = avg_width.mean()*avg_height.mean();
116 double scale = std::sqrt(target_size/size);
117
118 width = (unsigned long)(avg_width.mean()*scale+0.5);
119 height = (unsigned long)(avg_height.mean()*scale+0.5);
120 // make sure the width and height never round to zero.
121 if (width == 0)
122 width = 1;
123 if (height == 0)
124 height = 1;
125}
126
127// ----------------------------------------------------------------------------------------
128

Callers 1

mainFunction · 0.70

Calls 6

sqrtFunction · 0.50
sizeMethod · 0.45
addMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected