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

Function pick_best_window_size

tools/python/src/simple_object_detector.h:74–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72 namespace impl
73 {
74 inline void pick_best_window_size (
75 const std::vector<std::vector<rectangle> >& boxes,
76 unsigned long& width,
77 unsigned long& height,
78 const unsigned long target_size
79 )
80 {
81 // find the average width and height
82 running_stats<double> avg_width, avg_height;
83 for (unsigned long i = 0; i < boxes.size(); ++i)
84 {
85 for (unsigned long j = 0; j < boxes[i].size(); ++j)
86 {
87 avg_width.add(boxes[i][j].width());
88 avg_height.add(boxes[i][j].height());
89 }
90 }
91
92 // now adjust the box size so that it is about target_pixels pixels in size
93 double size = avg_width.mean()*avg_height.mean();
94 double scale = std::sqrt(target_size/size);
95
96 width = (unsigned long)(avg_width.mean()*scale+0.5);
97 height = (unsigned long)(avg_height.mean()*scale+0.5);
98 // make sure the width and height never round to zero.
99 if (width == 0)
100 width = 1;
101 if (height == 0)
102 height = 1;
103 }
104
105 inline bool contains_any_boxes (
106 const std::vector<std::vector<rectangle> >& boxes

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