1 #ifndef MTF_PRE_PROC_UTILS_H 2 #define MTF_PRE_PROC_UTILS_H 10 #include "mtf/Utilities/excpUtils.h" 11 #include "mtf/Utilities/imgUtils.h" 12 #include "opencv2/imgproc/imgproc.hpp" 18 const vector<int> supported_output_types = { CV_32FC3, CV_32FC1, CV_8UC3, CV_8UC1 };
21 typedef std::shared_ptr<PreProcBase> Ptr;
27 PreProcBase(
const std::string &name,
int _output_type = CV_32FC1,
28 double _resize_factor = 1,
bool _hist_eq =
false);
32 virtual void initialize(
const cv::Mat &frame_raw,
int _frame_id = -1,
bool print_types =
true);
33 virtual void update(
const cv::Mat &frame_raw,
int _frame_id = -1){
34 if(_frame_id > 0 && frame_id == _frame_id){
return; }
36 processFrame(frame_raw);
37 if(next.get()){ next->update(frame_raw, _frame_id); }
39 virtual const cv::Mat& getFrame(){
40 return resize_images ? frame_resized : rgb_output ? frame_rgb : frame_gs;
42 virtual std::string type(){
return _type; }
43 virtual void showFrame(std::string window_name);
44 virtual int outputType()
const{
return output_type; }
45 virtual void setFrameID(
int _frame_id){ frame_id = _frame_id; }
46 virtual int getFrameID()
const{
return frame_id; }
47 virtual int getWidth() {
return getFrame().cols; }
48 virtual int getHeight() {
return getFrame().rows; }
51 cv::Mat frame_rgb, frame_gs, frame_rgb_uchar;
52 cv::Mat frame_resized;
55 bool rgb_input, rgb_output;
62 virtual void apply(cv::Mat &img_gs)
const = 0;
63 virtual void processFrame(
const cv::Mat &frame_raw);
69 int _output_type = CV_32FC1,
double _resize_factor = 1,
bool _hist_eq =
false,
70 int _kernel_size = 5,
double _sigma_x = 3.0,
double _sigma_y = 0);
71 void apply(cv::Mat &img_gs)
const override{
72 cv::GaussianBlur(img_gs, img_gs, kernel_size, sigma_x, sigma_y);
81 int _output_type = CV_32FC1,
double _resize_factor = 1,
bool _hist_eq =
false,
82 int _kernel_size = 5);
83 void apply(cv::Mat &img_gs)
const override{
84 cv::medianBlur(img_gs, img_gs, kernel_size);
91 int _output_type = CV_32FC1,
double _resize_factor = 1,
bool _hist_eq =
false,
92 int _kernel_size = 5);
93 void apply(cv::Mat &img_gs)
const override{
94 cv::blur(img_gs, img_gs, kernel_size);
101 int _output_type = CV_32FC1,
double _resize_factor = 1,
bool _hist_eq =
false,
102 int _diameter = 5,
double _sigma_col = 15,
double _sigma_space = 15);
103 void apply(cv::Mat &img_gs)
const override{
105 cv::Mat orig_img = img_gs.clone();
107 cv::bilateralFilter(orig_img, img_gs, diameter, sigma_col, sigma_space);
115 SobelFltering(
int _output_type = CV_32FC1,
double _resize_factor = 1,
116 bool _hist_eq =
false,
int _kernel_size = 3,
bool _normalize=
false);
117 void initialize(
const cv::Mat &frame_raw,
118 int _frame_id = -1,
bool print_types =
true)
override;
119 void processFrame(
const cv::Mat &frame_raw)
override;
120 void apply(cv::Mat &img_gs)
const override;
121 const cv::Mat& getFrame()
override{
124 void showFrame(std::string window_name)
override;
127 cv::Mat frame_out, frame_in;
128 cv::Mat grad_x, grad_y, grad;
129 cv::Mat abs_grad_x, abs_grad_y, abs_grad;
130 const int kernel_size;
131 const bool normalize;
135 int _output_type = CV_32FC1,
double _resize_factor = 1,
bool _hist_eq =
false,
136 double _lambda = 0.14285714285,
double _k = 30,
unsigned int _n_iters = 15);
137 void apply(cv::Mat &img_gs)
const override{
138 mtf::utils::anisotropicDiffusion(img_gs, lambda, k, n_iters);
143 unsigned int n_iters;
147 double _resize_factor = 1,
bool _hist_eq =
false) :
148 PreProcBase(
"NoFiltering",_output_type, _resize_factor, _hist_eq){
149 printf(
"Filtering is disabled\n");
151 void apply(cv::Mat &img_gs)
const override{}
156 printf(
"Pre processing is disabled\n");
158 void initialize(
const cv::Mat &frame_raw,
159 int _frame_id = -1,
bool print_types =
true)
override;
160 void update(
const cv::Mat &frame_raw,
int _frame_id = -1)
override{
161 if(frame_raw.data != curr_frame.data){
164 frame_id = _frame_id;
166 void apply(cv::Mat &img_gs)
const override{}
167 const cv::Mat& getFrame()
override{
170 int outputType()
const override{
return output_type; }
Definition: preprocUtils.h:89
Ptr next
linked list of shared PreProc pointers to deal with heterogeneous output types and multiple trackers ...
Definition: preprocUtils.h:26
Definition: excpUtils.h:38
Definition: preprocUtils.h:67
Definition: preprocUtils.h:20
Definition: preprocUtils.h:153
Definition: preprocUtils.h:145
std::string _type
unique ID to prevent creating duplicate pre processors with identical processing
Definition: preprocUtils.h:60
Definition: preprocUtils.h:114
Definition: preprocUtils.h:99
basic functions for preprocessing the raw input image using filtering, resizing and histogram equaliz...
Definition: histUtils.h:20
Definition: preprocUtils.h:133