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::EyeLike Class Referencefinal

Direct copy of https://github.com/trishume/eyelike. More...

#include "gaze/pipeline_steps/eye_like.h"

Inheritance diagram for gaze::pipeline::EyeLike:
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

Direct copy of https://github.com/trishume/eyelike.

Definition at line 17 of file eye_like.h.

Member Function Documentation

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

Detects the eye center for each eye.

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

Implements gaze::PipelineStep.

Definition at line 290 of file eye_like.cpp.

References gaze::util::Data::centers, cv::COLOR_RGB2GRAY, cv::Mat::cols, cv::cvtColor(), gaze::util::Data::landmarks, rectangle(), cv::Mat::rows, and gaze::util::Data::source_image.

290  {
291  if (data.landmarks.num_parts() < 5) {
292  return;
293  }
294 
295  dlib::rectangle face = data.landmarks.get_rect();
296 
297  // avoid OpenCV ROI errors since dlib's bounding box can be outside
298  face = face.intersect(
299  dlib::rectangle(0, 0,
300  data.source_image.cols - 1, data.source_image.rows - 1));
301 
302  cv::Mat face_mat = data.source_image(util::dlib_to_cv(face));
303  cv::cvtColor(face_mat, face_mat, cv::COLOR_RGB2GRAY);
304 
305  for (int i = 0; i < 2; ++i) {
306  dlib::rectangle eye = util::get_eye_region(i, data.landmarks);
307  eye.set_left(eye.left() - face.left());
308  eye.set_right(eye.right() - face.left());
309  eye.set_top(eye.top() - face.top());
310  eye.set_bottom(eye.bottom() - face.top());
311 
312  cv::Point pupil = eyelike::find_eye_center(face_mat,
313  util::dlib_to_cv(eye),
314  this->relative_threshold_factor, 50);
315 
316  data.centers[i] = util::cv_to_dlib(pupil);
317  }
318 }
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
dlib::rectangle get_eye_region(int eye, dlib::full_object_detection object_detection)
Definition: eye_like.cpp:239
dlib::point cv_to_dlib(const cv::Point &to_convert)
Definition: dlibcv.cpp:8
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
COLOR_RGB2GRAY
cv::Rect dlib_to_cv(const dlib::rectangle &to_convert)
Definition: dlibcv.cpp:17
void gaze::pipeline::EyeLike::visualize ( util::Data data)
overridevirtual
Parameters
dataThe data object to be updated.

Implements gaze::gui::VisualizeableBase.

Definition at line 320 of file eye_like.cpp.

References gaze::util::Data::centers, gaze::util::Data::eyes, gaze::util::Data::image, gaze::util::Data::landmarks, and rectangle().

320  {
321  if (data.landmarks.num_parts() < 5) {
322  return;
323  }
324  // Ensures output of this pipeline step is visualized
325  this->process(data);
326 
327  // define offsets
328  dlib::point offset_x(5, 0);
329  dlib::point offset_y(0, 5);
330 
331  dlib::extract_image_chips(data.image,
332  util::get_eyes_chip_details(data.landmarks), data.eyes);
333 
334 
335  // assign eyes to new images
336  dlib::array<dlib::array2d<dlib::bgr_pixel>> eyes(3);
337  dlib::assign_image(eyes[2], data.image);
338  for (auto i = decltype(data.eyes.size()){0};
339  i < data.eyes.size(); ++i) {
340  dlib::rectangle eye = util::get_eye_region(i, data.landmarks);
341  dlib::assign_image(eyes[i], data.eyes[i]);
342 
343  dlib::draw_line(eyes[i],
344  data.centers[i] + offset_x,
345  data.centers[i] - offset_x,
346  dlib::rgb_pixel(255, 0, 0));
347  dlib::draw_line(eyes[i],
348  data.centers[i] + offset_y,
349  data.centers[i] - offset_y,
350  dlib::rgb_pixel(255, 0, 0));
351 
352  dlib::draw_line(eyes[2],
353  data.centers[i] + offset_x + eye.tl_corner(),
354  data.centers[i] - offset_x + eye.tl_corner(),
355  dlib::rgb_pixel(255, 0, 0));
356  dlib::draw_line(eyes[2],
357  data.centers[i] + offset_y + eye.tl_corner(),
358  data.centers[i] - offset_y + eye.tl_corner(),
359  dlib::rgb_pixel(255, 0, 0));
360  }
361  dlib::resize_image(0.5, eyes[2]);
362 
363  this->widget->set_image(dlib::tile_images(eyes));
364 }
std::vector< dlib::chip_details > get_eyes_chip_details(const dlib::full_object_detection object_detection)
std::shared_ptr< widget_type > widget
dlib::rectangle get_eye_region(int eye, dlib::full_object_detection object_detection)
Definition: eye_like.cpp:239
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
void process(util::Data &data) override
Definition: eye_like.cpp:290

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