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

Retrieves frames from a webcam or video source. More...

#include "gaze/pipeline_steps/source_capture.h"

Inheritance diagram for gaze::pipeline::SourceCapture:
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
 
Creating a source capture
 SourceCapture ()
 
- 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

Retrieves frames from a webcam or video source.

Should be used at the beginning of a Pipeline.

Definition at line 24 of file source_capture.h.

Constructor & Destructor Documentation

gaze::pipeline::SourceCapture::SourceCapture ( )

Creates a cv::VideoCapture as the input source.

If the source specified in the yaml configuration is a string, it is considered as a path, otherwise the number will be parsed as a webcam address.

Definition at line 18 of file source_capture.cpp.

References cv::CAP_PROP_FPS, cv::CAP_PROP_FRAME_HEIGHT, cv::CAP_PROP_FRAME_WIDTH, gaze::util::get_config(), gaze::PipelineStep::name, gaze::PipelineStep::number, and cv::VideoCapture::set().

18  {
19  YAML::Node config = util::get_config(this->number);
20  this->name = config["name"] ?
21  config["name"].as<std::string>() : "SourceCapture";
22 
23  std::string source = config["source"] ?
24  config["source"].as<std::string>() : "0";
25 
26  bool is_webcam = true;
27  try {
28  int cam_source = std::stoi(source);
29  this->video_capture = cv::VideoCapture(cam_source);
30  } catch (const std::invalid_argument&) {
31  is_webcam = false;
32  this->video_capture = cv::VideoCapture(source);
33  }
34 
35  if (is_webcam) {
36  YAML::Node camera_config = util::get_config()["meta"]["camera"];
37  this->video_capture.set(cv::CAP_PROP_FPS,
38  camera_config["fps"] ? camera_config["fps"].as<double>() : 60.0);
39  this->video_capture.set(cv::CAP_PROP_FRAME_WIDTH,
40  camera_config["resolution"]["width"] ?
41  camera_config["resolution"]["width"].as<double>() : 640.0);
42  this->video_capture.set(cv::CAP_PROP_FRAME_HEIGHT,
43  camera_config["resolution"]["height"] ?
44  camera_config["resolution"]["height"].as<double>() : 360.0);
45  }
46 }
CAP_PROP_FRAME_WIDTH
CAP_PROP_FRAME_HEIGHT
virtual bool set(int propId, double value)
std::string name
Definition: pipeline_step.h:31
CAP_PROP_FPS
YAML::Node get_config()
Definition: config.in.cpp:12

Member Function Documentation

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

Reads a frame from the video source and stores it as the data's util::Data::souce_image.

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

Implements gaze::PipelineStep.

Definition at line 52 of file source_capture.cpp.

References cv::CAP_PROP_POS_AVI_RATIO, cv::VideoCapture::get(), gaze::util::Data::image, cv::VideoCapture::read(), and gaze::util::Data::source_image.

52  {
53  if (static_cast<int>(this->video_capture.get(cv::CAP_PROP_POS_AVI_RATIO))
54  == 1) {
55  return;
56  }
57  bool received = this->video_capture.read(data.source_image);
58  if (received) {
59  this->last_frame = data.source_image;
60  } else {
61  data.source_image = this->last_frame;
62  }
63  dlib::assign_image(
64  data.image,
65  dlib::cv_image<dlib::bgr_pixel>(data.source_image));
66 }
virtual bool read(OutputArray image)
CAP_PROP_POS_AVI_RATIO
virtual double get(int propId) const
void gaze::pipeline::SourceCapture::visualize ( util::Data data)
overridevirtual

Just assigns the data's raw camera image to the widget.

Parameters
datathe data object.

Implements gaze::gui::VisualizeableBase.

Definition at line 68 of file source_capture.cpp.

References gaze::util::Data::image, and gaze::gui::Visualizeable< widget_type >::widget.

68  {
69  this->widget->set_image(data.image);
70 }
std::shared_ptr< widget_type > widget

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