gaze  0.1.0
Perform gaze tracking with common webcams.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
Public Member Functions | List of all members
gaze::pipeline::GazeCapture Class Referencefinal

Uses iTracker to track Gaze. More...

#include "gaze/pipeline_steps/gaze_capture.h"

Inheritance diagram for gaze::pipeline::GazeCapture:
gaze::PipelineStep gaze::gui::Visualizeable< widget_type > gaze::gui::VisualizeableBase

Public Member Functions

void process (util::Data &data) override
 
void visualize (util::Data &data) override
 
- Public Member Functions inherited from gaze::PipelineStep
 PipelineStep ()
 
std::string get_name ()
 
virtual ~PipelineStep ()=default
 
- Public Member Functions inherited from gaze::gui::Visualizeable< widget_type >
std::shared_ptr< dlib::drawable > init (dlib::drawable_window &parent, int width, int height, std::string text="No visualization.") final
 
void remove_widget () override
 
- Public Member Functions inherited from gaze::gui::VisualizeableBase
virtual ~VisualizeableBase ()=default
 

Additional Inherited Members

- Protected Attributes inherited from gaze::PipelineStep
int number
 
std::string name
 
- Protected Attributes inherited from gaze::gui::Visualizeable< widget_type >
std::shared_ptr< widget_type > widget
 

Detailed Description

Uses iTracker to track Gaze.

This step does nothing if not compiled using the -DWITH_CAFFE=ON option.

If it is compiled, it holds a pointer to an instance of itracker::ITracker, which it passes extracted eyes, the face, and a face mask to. It then maps the result to the target area on the screen.

Definition at line 29 of file gaze_capture.h.

Member Function Documentation

void gaze::pipeline::GazeCapture::process ( util::Data data)
overridevirtual

Estimates the gaze point using iTracker.

Parameters
dataThe data object to be updated.
Returns
via data the modified data object.

Implements gaze::PipelineStep.

Definition at line 73 of file gaze_capture.cpp.

References gaze::util::Data::estimated_gaze_point, gaze::util::get_eyes_chip_details(), gaze::util::Data::image, gaze::util::Data::landmarks, left(), mask, right(), and toMat().

73  {
74  if (data.landmarks.num_parts() < 5) {
75  return;
76  }
77 
78 #ifdef HAS_CAFFE
79  // Gather input
81  util::get_eyes_chip_details(data.landmarks);
82 
83  auto right_dlib = dlib::sub_image(data.image, chips[0].rect);
84  auto left_dlib = dlib::sub_image(data.image, chips[1].rect);
85  auto face_dlib = dlib::sub_image(data.image, data.landmarks.get_rect());
86  cv::Mat right = dlib::toMat(right_dlib);
87  cv::Mat left = dlib::toMat(left_dlib);
88  cv::Mat face = dlib::toMat(face_dlib);
89 
90  dlib::matrix<unsigned char> mask_in =
91  dlib::zeros_matrix<unsigned char>(data.image.nr(), data.image.nc());
92  dlib::set_subm(mask_in, data.landmarks.get_rect()) = 1;
93  dlib::matrix<unsigned char, 25, 25> mask_out;
94  dlib::resize_image(mask_in, mask_out, dlib::interpolate_nearest_neighbor());
95  cv::Mat mask = dlib::toMat(mask_out);
96 
97  cv::Vec2d prediction_cam = this->itracker->predict(left, right, face, mask);
98  // Note that the prediction is in cm, thus DIV100 is needed
99  double x = (prediction_cam[0] / 100 + this->camera_offset[0])
100  / this->screen_size_m[0] * this->target_size[0];
101  double y = (-prediction_cam[1] / 100 + this->camera_offset[1])
102  / this->screen_size_m[1] * this->target_size[1];
103  data.estimated_gaze_point = cv::Vec2d(x, y);
104 #endif
105 }
ios_base & left(ios_base &__base)
std::vector< dlib::chip_details > get_eyes_chip_details(const dlib::full_object_detection object_detection)
Vec< double, 2 > Vec2d
cv::Mat toMat() const
ios_base & right(ios_base &__base)
void gaze::pipeline::GazeCapture::visualize ( util::Data data)
overridevirtual

Visualizes the estimated gaze point.

Parameters
dataThe data object to be visualized.

Implements gaze::gui::VisualizeableBase.

Definition at line 107 of file gaze_capture.cpp.

References std::cout, std::endl(), and gaze::util::Data::estimated_gaze_point.

107  {
108 #ifdef HAS_CAFFE
109  std::cout << data.estimated_gaze_point << std::endl;
110 #endif
111 }
ostream cout
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)

The documentation for this class was generated from the following files: