MTF
objUtils.h
1 #ifndef MTF_OBJ_UTILS_H
2 #define MTF_OBJ_UTILS_H
3 
4 #include<sstream>
5 #include<memory>
6 #include <map>
7 
8 #include "opencv2/core/core.hpp"
9 #include "mtf/Utilities/inputUtils.h"
10 #ifndef DISABLE_VISP
11 #include <visp3/core/vpColor.h>
12 #endif
13 
14 using namespace std;
15 
16 _MTF_BEGIN_NAMESPACE
17 namespace utils{
22  struct ObjStruct {
23  cv::Point2d min_point;
24  cv::Point2d max_point;
25 
26  double size_x;
27  double size_y;
28  double pos_x;
29  double pos_y;
30 
31  cv::Mat corners;
32 
33  ObjStruct();
34  void updateCornerMat();
35  void updateCornerPoints();
36  void operator*=(double resize_factor);
37  };
38 
39  typedef std::shared_ptr<ObjStruct> ObjStructPtr;
40 
41  /* callback function for mouse clicks */
42  inline void getClickedPoint(int mouse_event, int x, int y, int flags, void* param);
43 
48  class ObjUtils {
49  public:
50  ObjUtils(const vector_s &_obj_cols = vector_s(),
51  double _resize_factor = 1.0);
52  ~ObjUtils();
53  const cv::Scalar &getCol(int col_id){
54  return obj_cols[col_id % no_of_cols];
55  }
56  const cv::Scalar &getCol(const std::string &col_name){
57  return col_rgb.at(col_name);
58  }
59  void getCols(vector<cv::Scalar> &cols) {
60  cols = obj_cols;
61  }
62 #ifndef DISABLE_VISP
63  const vpColor &getColVp(int col_id){
64  return obj_cols_vp[col_id % no_of_cols_vp];
65  }
66  const vpColor &getColVp(const std::string &col_name){
67  return col_rgb_vp.at(col_name);
68  }
69  void getCols(vector<vpColor> &cols) {
70  cols = obj_cols_vp;
71  }
72 #endif
73 
76  bool addRectObject(InputBase *input, string selection_window,
77  int line_thickness = 2, int patch_size = 0);
81  bool addQuadObject(InputBase *input, string selection_window,
82  int line_thickness = 2);
84  bool selectObjects(const cv::Mat &img, int no_of_objs,
85  int patch_size = 0, int line_thickness = 1, int write_objs = 0, bool sel_quad_obj = false,
86  const char* filename = "selected_objects.txt");
87  bool selectObjects(InputBase *input, int no_of_objs, int patch_size = 0,
88  int line_thickness = 1, int write_objs = 0, bool sel_quad_obj = false,
89  const char* filename = "selected_objects.txt");
90 #ifndef DISABLE_VISP
91  bool addRectObjectVP(InputBase *input, string selection_window,
92  int line_thickness = 2, int patch_size = 0);
93  bool addQuadObjectVP(InputBase *input, string selection_window,
94  int line_thickness = 2);
96  bool selectObjectsVP(const cv::Mat &img, int no_of_objs,
97  int patch_size = 0, int line_thickness = 1, int write_objs = 0, bool sel_quad_obj = false,
98  const char* filename = "selected_objects.txt");
99  bool selectObjectsVP(InputBase *input, int no_of_objs, int patch_size = 0,
100  int line_thickness = 1, int write_objs = 0, bool sel_quad_obj = false,
101  const char* filename = "selected_objects.txt");
102 #endif
103  void writeObjectsToFile(int no_of_objs,
104  const char* filename = "sel_objs/selected_objects.txt");
105  bool readObjectFromGT(string source_name, string source_path, int n_frames,
106  int _init_frame_id = 0, bool use_opt_gt = false, string opt_gt_ssm = "2",
107  bool _use_reinit_gt = false, bool _invert_seq = false, int debug_mode = 0);
108  bool getObjStatus() const{ return !init_objects.empty(); }
109  const ObjStruct &getObj(int obj_id = 0) const{
110  return init_objects.size() == 1 ? init_objects[0] : init_objects[obj_id];
111  }
112  const cv::Mat &getGT(int frame_id, int _reinit_frame_id = -1);
113  const cv::Mat &getReinitGT(int frame_id, int _reinit_frame_id = -1);
114  const vector<cv::Mat> &getGT(){ return ground_truth; }
115  int getGTSize(){
116  return use_reinit_gt ? ground_truth.size() + reinit_frame_id : ground_truth.size();
117  }
118  bool readGT(string source_name, string source_path,
119  int n_frames = 1, int init_frame_id = 0, int debug_mode = 0,
120  bool use_opt_gt = false, string opt_gt_ssm = "2");
121  bool readReinitGT(string source_name, string source_path,
122  int _reinit_frame_id, int _n_frames, bool use_opt_gt = false,
123  string opt_gt_ssm = "2");
124  bool readObjectsFromFile(int no_of_objs,
125  const char* filename = "sel_objs/selected_objects.txt", int debug_mode = 0);
126  cv::Point getMeanPoint(cv::Point *pt_array, int no_of_points);
127  void cornersToPoint2D(cv::Point2d(&cv_corners)[4], const cv::Mat &cv_corners_mat);
128 
129  private:
130  const std::map<std::string, cv::Scalar> col_rgb;
131 #ifndef DISABLE_VISP
132  const std::map<std::string, vpColor> col_rgb_vp;
133 #endif
134  vector<ObjStruct> init_objects;
135  vector<cv::Mat> ground_truth;
136  vector<cv::Mat> reinit_ground_truth;
137  int init_frame_id, reinit_frame_id;
138  int reinit_n_frames;
139  bool use_reinit_gt;
140  string reinit_gt_filename;
141  vector<cv::Scalar> obj_cols;
142  int no_of_cols;
143 #ifndef DISABLE_VISP
144  vector<vpColor> obj_cols_vp;
145  int no_of_cols_vp;
146 #endif
147  const double resize_factor;
148  const bool resized_images;
149  bool invert_seq;
151  void readReinitGT(int _reinit_frame_id);
152  const vector<cv::Mat> &getReinitGT(){ return reinit_ground_truth; }
153  };
154 }
155 _MTF_END_NAMESPACE
156 #endif
utility functions to obtain initial object location for tracking - either read from a ground truth fi...
Definition: objUtils.h:48
simple structure to store an object read from ground truth or selected by the user; requires that the...
Definition: objUtils.h:22
Definition: inputUtils.h:54
basic functions for preprocessing the raw input image using filtering, resizing and histogram equaliz...
Definition: histUtils.h:20