Antal.Ai - Virtual Makeup
FaceDetectorYunet.h
1 #pragma once
2 
3 #include "Detection.h"
4 #include <opencv2/dnn.hpp>
5 #include <opencv2/objdetect/face.hpp>
6 
7 namespace core {
8  namespace face {
9 
19  public:
23  FaceDetectorYunet() = default;
24 
28  ~FaceDetectorYunet() = default;
29 
53  void init(std::string framework,
54  std::string modelWeightsFile,
55  std::string classesFile,
56  std::string modelConfigurationFile,
57  std::string inputLayerName,
58  std::string outputLayerName,
59  std::string networkName,
60  int inputWidth,
61  int inputHeight,
62  double scale,
63  double mean0,
64  double mean1,
65  double mean2,
66  std::string configBackend,
67  std::string configTarget,
68  double confidenceThreshold = 0.9,
69  double nmsThreshold = 0.3,
70  double maxWH = 312.0,
71  int topK = 5000);
72 
79  std::vector<core::Detection> process(const cv::Mat& frame);
80 
81  private:
82  cv::Ptr<cv::FaceDetectorYN> mDetector;
84  double maxWidthOrHeight;
86  // Available backend configurations for DNN processing.
87  std::map<std::string, cv::dnn::Backend> backends = {
88  {"DNN_BACKEND_DEFAULT", cv::dnn::DNN_BACKEND_DEFAULT},
89  {"DNN_BACKEND_HALIDE", cv::dnn::DNN_BACKEND_HALIDE},
90  {"DNN_BACKEND_INFERENCE_ENGINE", cv::dnn::DNN_BACKEND_INFERENCE_ENGINE},
91  {"DNN_BACKEND_OPENCV", cv::dnn::DNN_BACKEND_OPENCV},
92  {"DNN_BACKEND_CUDA", cv::dnn::DNN_BACKEND_CUDA}
93  };
94 
95  // Available target configurations for DNN processing.
96  std::map<std::string, cv::dnn::Target> targets = {
97  {"DNN_TARGET_CPU", cv::dnn::DNN_TARGET_CPU},
98  {"DNN_TARGET_CUDA", cv::dnn::DNN_TARGET_CUDA},
99  {"DNN_TARGET_OPENCL", cv::dnn::DNN_TARGET_OPENCL},
100  {"DNN_TARGET_OPENCL_FP16", cv::dnn::DNN_TARGET_OPENCL_FP16},
101  {"DNN_TARGET_MYRIAD", cv::dnn::DNN_TARGET_MYRIAD}
102  };
103  };
104 
105  } // namespace face
106 } // namespace core
Face detection class utilizing OpenCV's FaceDetectorYN model with DNN support.
Definition: FaceDetectorYunet.h:18
FaceDetectorYunet()=default
Default constructor for FaceDetectorYunet.
std::vector< core::Detection > process(const cv::Mat &frame)
Processes an image frame to detect faces and returns a list of detections.
Definition: FaceDetectorYunet.cpp:70
void init(std::string framework, std::string modelWeightsFile, std::string classesFile, std::string modelConfigurationFile, std::string inputLayerName, std::string outputLayerName, std::string networkName, int inputWidth, int inputHeight, double scale, double mean0, double mean1, double mean2, std::string configBackend, std::string configTarget, double confidenceThreshold=0.9, double nmsThreshold=0.3, double maxWH=312.0, int topK=5000)
Initializes the face detector with specified parameters and model configurations.
Definition: FaceDetectorYunet.cpp:11
~FaceDetectorYunet()=default
Default destructor for FaceDetectorYunet.