Spoofing Detection Engine  1.0
EngineBase.h
1 #pragma once
2 #include <iostream>
3 #include <map>
4 #include <deque>
5 #include <opencv2/imgcodecs.hpp>
6 #include "CvUtils.h"
7 #include "FaceDrawer.h"
8 #include "FaceDetectorYunet.h"
9 #include "FaceMesh.h"
10 #include "LandmarkFlowFilter.h"
11 
12 namespace
13 {
14  // Only available under Emscripten include
15 #ifdef __EMSCRIPTEN__
16 #include <emscripten/emscripten.h>
17 #include <emscripten/val.h>
18 
22  void log(const std::string& message) {
23  emscripten::val console = emscripten::val::global("console");
24  console.call<void>("log", message);
25  }
26 #else
30  void log(const std::string& message) {
31  // Alternative logging on other platforms, e.g. writing to console
32  std::cout << message << std::endl;
33  }
34 #endif
35 
36 };
37 
47 {
48 public:
53 
57  virtual ~EngineBase() {};
58 
63  virtual void init(std::string resourcePath);
64 
74  virtual void process(cv::Mat& input, cv::Mat& output) = 0;
75 
83  void addSigno(cv::Mat& image);
84 
93  void drawHistoryChart(cv::Mat& frame, const cv::Rect& haloRect,
94  const std::deque<std::map<std::string, double>>& history,
95  const std::map<std::string, cv::Scalar>& colors);
96 
97 protected:
98 
108  cv::Mat preProcessImage(cv::Mat& image);
109 
118  cv::Mat postProcessImage(cv::Mat& image, cv::Mat& workingFrame);
119 
123  std::string faceVerticesPath;
124 
129 
134 
139 
141 
142  cv::Rect imageRect;
143 
144  float padding_ratio = 0.3;
145  int top = 0;
146  int bottom = 0;
147  int left = 0;
148  int right = 0;
149 
150  static constexpr size_t HISTORY_LENGTH = 50;
151  std::map<int, std::deque<std::map<std::string, double>>> mHistory;
152 };
Core utilities for image and math operations using OpenCV.
Header file for FaceDrawer class.
Defines the LandmarkFlowFilter class for tracking points in video frames.
Main engine class for processing images and applying visual features.
Definition: EngineBase.h:47
void addSigno(cv::Mat &image)
Adds a watermark (signo) to the specified image.
Definition: EngineBase.cpp:46
core::face::FaceDetectorYunet detector
Face detector object used for detecting faces within images.
Definition: EngineBase.h:128
EngineBase()
Default constructor for the EngineBase class.
Definition: EngineBase.h:52
virtual void init(std::string resourcePath)
Initializes the engine with the specified resource path.
Definition: EngineBase.cpp:109
core::face::FaceMesh faceMesh
Face mesh object used for managing facial geometry data.
Definition: EngineBase.h:138
cv::Mat postProcessImage(cv::Mat &image, cv::Mat &workingFrame)
Remove padding and convert the processed image back to the original format.
Definition: EngineBase.cpp:28
cv::Mat preProcessImage(cv::Mat &image)
Prepare the input image for further processing.
Definition: EngineBase.cpp:5
std::string faceVerticesPath
Path to the face vertices data file in the virtual file system.
Definition: EngineBase.h:123
void drawHistoryChart(cv::Mat &frame, const cv::Rect &haloRect, const std::deque< std::map< std::string, double >> &history, const std::map< std::string, cv::Scalar > &colors)
Draw a simple line chart visualizing the value history for a detection.
Definition: EngineBase.cpp:73
virtual ~EngineBase()
Destructor for the EngineBase class.
Definition: EngineBase.h:57
visualization::FaceDrawer faceDrawer
Face drawer object used for drawing face landmarks and features.
Definition: EngineBase.h:133
virtual void process(cv::Mat &input, cv::Mat &output)=0
Processes an input image and produces an output image.
Face detection class utilizing OpenCV's FaceDetectorYN model with DNN support.
Definition: FaceDetectorYunet.h:18
A class responsible for initializing, configuring, and processing face mesh detection using neural ne...
Definition: FaceMesh.h:16
Implements a filter to track landmarks in a sequence of images.
Definition: LandmarkFlowFilter.h:24
Draws triangulation on faces based on facial points.
Definition: FaceDrawer.h:41