| 166 | } |
| 167 | |
| 168 | static void nms_sorted_bboxes( |
| 169 | const std::vector<OutputInfo>& faceoutput_infos, |
| 170 | std::vector<int>& picked_output, float nms_threshold) { |
| 171 | picked_output.clear(); |
| 172 | |
| 173 | const int n = faceoutput_infos.size(); |
| 174 | |
| 175 | std::vector<float> areas(n); |
| 176 | for (int i = 0; i < n; i++) { |
| 177 | areas[i] = faceoutput_infos[i].rect.area(); |
| 178 | } |
| 179 | |
| 180 | for (int i = 0; i < n; i++) { |
| 181 | const OutputInfo& a = faceoutput_infos[i]; |
| 182 | |
| 183 | int keep = 1; |
| 184 | for (int j = 0; j < (int)picked_output.size(); j++) { |
| 185 | const OutputInfo& b = faceoutput_infos[picked_output[j]]; |
| 186 | |
| 187 | // intersection over union |
| 188 | float inter_area = intersection_area(a, b); |
| 189 | float union_area = areas[i] + areas[picked_output[j]] - inter_area; |
| 190 | // float IoU = inter_area / union_area |
| 191 | if (inter_area / union_area > nms_threshold) |
| 192 | keep = 0; |
| 193 | } |
| 194 | |
| 195 | if (keep) |
| 196 | picked_output.push_back(i); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | static void postpreprocess( |
| 201 | const float* output_ptr, std::vector<OutputInfo>& output_infos, float scale, |
no test coverage detected