Blame view

tsl_aiplatform/ai_engine_module/pedestrian_vehicle_trespass.hpp 3.04 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  /*
   * File: pedestrian_vehicle_trespass.hpp
   * Created Date: Tuesday February 22nd 2022
   * Author: yangzilong (yangzilong@objecteye.com)
   * Description:
   * -----
   * Last Modified: Tuesday, 22nd February 2022 4:35:04 pm
   * Modified By: yangzilong (yangzilong@objecteye.com>)
   * -----
   * Copyright 2022
   */
  
  #pragma once
  #include "include.h"
  #include "opencv.hpp"
  #include <deque>
  #include <map>
  #include <vector>
  
  namespace ai_engine_module {
  namespace pedestrian_vehicle_trespass {
  
  using obj_id_t = long;
  using task_id_t = std::string;
  
  enum class direction_t {
    NEGATIVE = 0,
    POSITIVE = 1,
  };
  
  struct trace_t {
    box_t box;
    point_t point;
  };
  
  // 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 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);
    // }
    // 221012-------------------------------------------------
    bool operator<(const unique_obj_id_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;
      }
      return false;
    }
    //----------------------------------------------------------
  };
  
  typedef struct result_data_t {
    box_t box;
    sy_img ori_img;
    sy_img roi_img;
    bool ori_img_is_in_gpu{false};
    bool roi_img_is_in_gpu{false};
  } result_data_t;
  
  using results_data_t = std::vector<result_data_t>;
  using multi_obj_key_t = std::vector<obj_key_t>;
  
  class PedestrianVehicleTrespass {
    /**
     * @brief
     *  1. move able
     */
  public:
    PedestrianVehicleTrespass();
  
    ~PedestrianVehicleTrespass();
  
    void pedestrianvehicletrespass_init_region(const string &task_id, const algorithm_type_t algor_type, const int width,
                                               const int height);
  
    bool update_mstreams(const std::set<task_id_t> &tasks_id, const sy_img *det_input_images,
                         const std::vector<onelevel_det_result> &det_result, const vector<vector<int>> &delete_objs);
  
    std::shared_ptr<results_data_t> get_results_by_id(const obj_key_t &id, bool do_erase = true);
  
    PedestrianVehicleTrespass(const PedestrianVehicleTrespass &) = delete;
    PedestrianVehicleTrespass &operator=(const PedestrianVehicleTrespass &) = delete;
  
    PedestrianVehicleTrespass(PedestrianVehicleTrespass &&) = default;
    PedestrianVehicleTrespass &operator=(PedestrianVehicleTrespass &&) = default;
  
  private:
    bool in_rect_analysis(const obj_key_t &id, const box_t &cur_bos);
  
    task_param_manager *task_param_manager_;
    std::map<obj_key_t, results_data_t> obj_to_alarm_boxes_;
    std::map<obj_key_t, box_t>
        obj_to_position_; // 保存物体上一帧的位置,基于非法闯入判断逻辑,上一帧在框外,下一帧闯入禁区
    std::map<obj_key_t, cv::Mat> trespass_regions;
  };
  } // namespace pedestrian_vehicle_trespass
  } // namespace ai_engine_module