SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
ma_nms.h
Go to the documentation of this file.
1 #ifndef _MA_NMS_H_
2 #define _MA_NMS_H_
3 
4 #include <algorithm>
5 #include <cmath>
6 #include <forward_list>
7 #include <iterator>
8 #include <type_traits>
9 
10 #include "../ma_types.h"
11 
12 namespace ma::utils {
13 
14 // skip use of template since it is not allowed
15 
16 template <typename T, std::enable_if_t<std::is_base_of<ma_bbox_t, T>::value, bool> = true>
17 inline float compute_iou(const T& box1, const T& box2) {
18  const float x1 = std::max(box1.x, box2.x);
19  const float y1 = std::max(box1.y, box2.y);
20  const float x2 = std::min(box1.x + box1.w, box2.x + box2.w);
21  const float y2 = std::min(box1.y + box1.h, box2.y + box2.h);
22  const float w = std::max(0.0f, x2 - x1);
23  const float h = std::max(0.0f, y2 - y1);
24  const float inter = w * h;
25  const float d = box1.w * box1.h + box2.w * box2.h - inter;
26  if (std::abs(d) < std::numeric_limits<float>::epsilon()) [[unlikely]] {
27  return 0;
28  }
29  return inter / d;
30 }
31 
32 void nms(std::forward_list<ma_bbox_t>& bboxes, float threshold_iou, float threshold_score, bool soft_nms, bool multi_target);
33 
34 void nms(std::forward_list<ma_bbox_ext_t>& bboxes, float threshold_iou, float threshold_score, bool soft_nms, bool multi_target);
35 
36 void nms(std::forward_list<ma_keypoint3f_t>& decodings, const float iou_thr, bool should_nms_cross_classes);
37 
38 } // namespace ma::utils
39 
40 #endif // _MA_NMS_H_
Definition: ma_anchors.cpp:3
float compute_iou(const T &box1, const T &box2)
Definition: ma_nms.h:17
void nms(std::forward_list< ma_bbox_t > &bboxes, float threshold_iou, float threshold_score, bool soft_nms, bool multi_target)
Definition: ma_nms.cpp:48