Blame view

tsl_aiplatform/ai_engine_module/common.h 1.64 KB
85cc8cb9   Hu Chunming   ๅŽŸ็‰ˆไปฃ็ 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  /*
   * @Author: yangzilong
   * @Date: 2021-12-01 15:14:02
   * @Last Modified by: yangzilong
   * @Last Modified time: Do not edit
   * @Email: yangzilong@objecteye.com
   * @Description:
   */
  
  #pragma once
  
  #include <cmath>
  #include <type_traits>
  
  namespace ai_engine_module {
  template <typename T> T clip(const T &val, const T &min, const T &max) {
    if (std::is_integral<T>::value)
      return std::min(std::max(val, min), max);
    return val;
  }
  
  using obj_id_t = long;
  using task_id_t = std::string;
  
  struct unique_obj_id_t {
    obj_id_t obj_id;
    task_id_t task_id;
  
    bool operator<(const unique_obj_id_t &obj) const {
      return obj_id < obj.obj_id || (task_id < obj.task_id);
    }
  };
  
  struct obj_key_t {
    obj_id_t obj_id;
    task_id_t task_id;
    algorithm_type_t algor_type;
  
    bool operator<(const obj_key_t &obj) const {
      if (obj_id < obj.obj_id)
        return true;
  
      else if (obj_id == obj.obj_id) {
        if (strcmp(task_id.c_str(), obj.task_id.c_str()) < 0)
          return true;
  
        else if (strcmp(task_id.c_str(), obj.task_id.c_str()) == 0) {
          if (static_cast<int>(algor_type) < static_cast<int>(obj.algor_type))
            return true;
          else
            return false;
        }
      }
      return false;
    }
  };
  
  struct point_t {
    int x, y;
  };
  
  struct box_t {
    long id; // -1: placeholder.
    float score;
    int top, left, right, bottom, cls;
  
    int width() const {
      return std::max(0, right - left);
    }
  
    int height() const {
      return std::max(0, bottom - top);
    }
  
    int cx() const {
      return std::max(0, int((left + right) * 0.5f));
    }
  
    int cy() const {
      return std::max(0, int((top + bottom) * 0.5f));
    }
  };
  
  } // namespace ai_engine_module