gaze  0.1.0
Perform gaze tracking with common webcams.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
pupil_localization.h
1 #ifndef INCLUDE_GAZE_PIPELINE_STEPS_PUPIL_LOCALIZATION_H_
2 #define INCLUDE_GAZE_PIPELINE_STEPS_PUPIL_LOCALIZATION_H_
3 
4 #include <vector>
5 
6 #include "dlib/matrix.h"
7 
8 #include "gaze/gui/visualizeable.h"
9 #include "gaze/pipeline_step.h"
10 #include "gaze/util/data.h"
11 
12 
13 namespace gaze {
14 
15 namespace util {
16 
64 void fill_displacement_tables(dlib::matrix<double>& table_x, // NOLINT
65  dlib::matrix<double>& table_y, // NOLINT
66  int size);
67 
78 template <typename T>
80  dlib::matrix<T>& horizontal, // NOLINT
81  dlib::matrix<T>& vertical, // NOLINT
82  double relative_threshold = -1) {
83  dlib::matrix<T> magnitude;
84  magnitude = dlib::sqrt(dlib::squared(horizontal) +
85  dlib::squared(vertical));
86 
87  // Thresholding
88  if (relative_threshold >= 0) {
89  T threshold = dlib::mean(magnitude)
90  + dlib::stddev(magnitude) * relative_threshold;
91  for (int row = 0; row < horizontal.nr(); ++row) {
92  for (int col = 0; col < horizontal.nc(); ++col) {
93  if (magnitude(row, col) < threshold) {
94  horizontal(row, col) = 0;
95  vertical(row, col) = 0;
96  }
97  }
98  }
99  }
100 
101  // Normalization
102  horizontal = dlib::pointwise_multiply(
103  horizontal, dlib::reciprocal(magnitude));
104  vertical = dlib::pointwise_multiply(
105  vertical, dlib::reciprocal(magnitude));
106 }
107 
108 } // namespace util
109 
110 namespace pipeline {
111 
125 class PupilLocalization final
126  : public PipelineStep,
127  public gui::ImageVisualizeable {
128  dlib::matrix<double> displacement_table_x;
129  dlib::matrix<double> displacement_table_y;
130  double relative_threshold_factor;
131  double sigma;
132 
133  public:
135 
142  void process(util::Data& data) override;
143 
147  void visualize(util::Data& data) override;
148 };
149 
150 } // namespace pipeline
151 
152 } // namespace gaze
153 
154 #endif // INCLUDE_GAZE_PIPELINE_STEPS_PUPIL_LOCALIZATION_H_
Scalar mean(InputArray src, InputArray mask=noArray())
Abstract base class for PipelineSteps. Must be inherited from.
Definition: pipeline_step.h:18
Implements Timm and Barth (2011) to detect eye centers.
size_t size() const
void magnitude(InputArray x, InputArray y, OutputArray magnitude)
void visualize(util::Data &data) override
void fill_displacement_tables(dlib::matrix< double > &table_x, dlib::matrix< double > &table_y, int size)
Implements VisualizeableBase for several widget types.
void process(util::Data &data) override
double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
Wraps the data acquired per frame into a single instance.
Definition: data.h:27
complex< _Tp > sqrt(const complex< _Tp > &)
void normalize_and_threshold_gradients(dlib::matrix< T > &horizontal, dlib::matrix< T > &vertical, double relative_threshold=-1)