1 #include "gaze/pipeline_steps/gaze_capture.h"
5 #include "dlib/image_processing.h"
6 #include "dlib/image_transforms.h"
7 #include "dlib/opencv.h"
8 #include "opencv2/opencv.hpp"
9 #include "yaml-cpp/yaml.h"
12 #include "itracker/itracker.h"
15 #include "gaze/gui/visualizeable.h"
16 #include "gaze/pipeline_step.h"
17 #include "gaze/util/config.h"
18 #include "gaze/util/data.h"
19 #include "gaze/util/pipeline_utils.h"
26 GazeCapture::GazeCapture() {
28 this->
name = config[
"name"] ?
33 config[
"model"].as<
std::string>() :
"models/itracker_deploy.prototxt";
36 "models/snapshots/itracker25x_iter_92000.caffemodel";
39 "models/mean_images/mean_left_224_new.binaryproto";
40 std::string mean_right_file = config[
"mean_right"] ?
42 "models/mean_images/mean_right_224.binaryproto";
45 "models/mean_images/mean_face_224.binaryproto";
49 YAML::Node camera_config = meta_config[
"camera"];
50 this->camera_offset =
cv::Vec2d(camera_config[
"position"][
"x"].as<double>(),
51 camera_config[
"position"][
"y"].as<double>());
53 YAML::Node screen_config = meta_config[
"screen"];
55 cv::Vec2d(screen_config[
"measurements"][
"width"].as<double>(),
56 screen_config[
"measurements"][
"height"].as<double>());
58 cv::Vec2d(screen_config[
"resolution"][
"width"].as<double>(),
59 screen_config[
"resolution"][
"height"].as<double>());
63 mean_left_file, mean_right_file, mean_face_file));
65 if (meta_config[
"target"]) {
67 cv::Vec2d(meta_config[
"target"][
"width"].as<int>(),
68 meta_config[
"target"][
"height"].as<int>());
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());
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());
97 cv::Vec2d prediction_cam = this->itracker->predict(left, right, face, mask);
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];
ios_base & left(ios_base &__base)
void process(util::Data &data) override
std::vector< dlib::chip_details > get_eyes_chip_details(const dlib::full_object_detection object_detection)
void visualize(util::Data &data) override
dlib::array2d< dlib::bgr_pixel > image
Implements a wrapper around the pre-trained caffe model by .
cv::Vec2d estimated_gaze_point
dlib::full_object_detection landmarks
Wraps the data acquired per frame into a single instance.
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ios_base & right(ios_base &__base)