Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
FacialLandmarksCV.h
1#pragma once
2
3#include <opencv2/face.hpp>
4#include "Module.h"
5#include "declarative/PropertyMacros.h"
6
7class Detail;
8class DetailSSD;
10
12{
13public:
19
20 // Default constructor for declarative pipeline
22
24
25 FacialLandmarkCVProps(FaceDetectionModelType _type, const std::string _Face_Detection_Configuration, const std::string _Face_Detection_Weights, const std::string _landmarksDetectionModel, cv::Ptr<cv::face::Facemark> _facemark)
26 : type(_type), Face_Detection_Configuration(_Face_Detection_Configuration), Face_Detection_Weights(_Face_Detection_Weights), landmarksDetectionModel(_landmarksDetectionModel),facemark(_facemark)
27 {
28 if (_type != FaceDetectionModelType::SSD)
29 {
30 throw AIPException(AIP_FATAL, "This constructor only supports SSD");
31 }
32 }
33
34 FacialLandmarkCVProps(FaceDetectionModelType _type, const std::string _faceDetectionModel,const std::string _landmarksDetectionModel, cv::Ptr<cv::face::Facemark> _facemark)
35 : type(_type), landmarksDetectionModel(_landmarksDetectionModel), faceDetectionModel(_faceDetectionModel), facemark(_facemark)
36 {
38 {
39 throw AIPException(AIP_FATAL, "This constructor only supports HAAR_CASCADE ");
40 }
41 }
42
44 std::string Face_Detection_Configuration = "./data/assets/deploy.prototxt";
45 std::string Face_Detection_Weights = "./data/assets/res10_300x300_ssd_iter_140000_fp16.caffemodel";
46 std::string landmarksDetectionModel = "./data/assets/face_landmark_model.dat";
47 std::string faceDetectionModel = "./data/assets/haarcascade.xml";
48 cv::Ptr<cv::face::Facemark> facemark = cv::face::FacemarkKazemi::create();
49
51 {
52 return ModuleProps::getSerializeSize() + sizeof(type);
53 }
54
55 // ============================================================
56 // Property Binding for Declarative Pipeline
57 // ============================================================
58 template<typename PropsT>
59 static void applyProperties(
60 PropsT& props,
61 const std::map<std::string, apra::ScalarPropertyValue>& values,
62 std::vector<std::string>& missingRequired
63 ) {
64 // Handle FaceDetectionModelType enum
65 auto it = values.find("modelType");
66 if (it != values.end()) {
67 if (auto* strVal = std::get_if<std::string>(&it->second)) {
68 if (*strVal == "SSD") props.type = SSD;
69 else if (*strVal == "HAAR_CASCADE") props.type = HAAR_CASCADE;
70 }
71 }
72 apra::applyProp(props.Face_Detection_Configuration, "faceDetectionConfig", values, false, missingRequired);
73 apra::applyProp(props.Face_Detection_Weights, "faceDetectionWeights", values, false, missingRequired);
74 apra::applyProp(props.landmarksDetectionModel, "landmarksModel", values, false, missingRequired);
75 apra::applyProp(props.faceDetectionModel, "haarCascadeModel", values, false, missingRequired);
76 }
77
78 apra::ScalarPropertyValue getProperty(const std::string& propName) const {
79 if (propName == "modelType") return type == SSD ? std::string("SSD") : std::string("HAAR_CASCADE");
80 if (propName == "faceDetectionConfig") return Face_Detection_Configuration;
81 if (propName == "faceDetectionWeights") return Face_Detection_Weights;
82 if (propName == "landmarksModel") return landmarksDetectionModel;
83 if (propName == "haarCascadeModel") return faceDetectionModel;
84 throw std::runtime_error("Unknown property: " + propName);
85 }
86
87 bool setProperty(const std::string& propName, const apra::ScalarPropertyValue& value) {
88 // All properties are static (models loaded at init)
89 return false;
90 }
91
92 static std::vector<std::string> dynamicPropertyNames() {
93 return {}; // No dynamically changeable properties
94 }
95
96private:
98
99 template <class Archive>
100 void serialize(Archive& ar, const unsigned int version)
101 {
102 ar& boost::serialization::base_object<ModuleProps>(*this);
103 ar& type;
104 }
105};
106
108{
109 public:
111 virtual ~FacialLandmarkCV();
112 bool init();
113 bool term();
114 void setProps(FacialLandmarkCVProps& props);
116
117protected:
118 bool process(frame_container &frames);
119 bool processSOS(frame_sp &frame);
120 bool validateInputPins();
121 bool validateOutputPins();
122 void addInputPin(framemetadata_sp &metadata, string &pinId); // throws exception if validation fails
123 bool shouldTriggerSOS();
124 bool processEOS(string &pinId);
125 boost::shared_ptr<Detail> mDetail;
127 bool handlePropsChange(frame_sp& frame);
128 std::string mOutputPinId;
129};
Definition FacialLandmarksCV.cpp:157
Definition FacialLandmarksCV.cpp:99
Definition FacialLandmarksCV.cpp:17
Definition FacialLandmarksCV.h:12
FacialLandmarkCVProps(FaceDetectionModelType _type, const std::string _faceDetectionModel, const std::string _landmarksDetectionModel, cv::Ptr< cv::face::Facemark > _facemark)
Definition FacialLandmarksCV.h:34
static std::vector< std::string > dynamicPropertyNames()
Definition FacialLandmarksCV.h:92
std::string Face_Detection_Weights
Definition FacialLandmarksCV.h:45
std::string faceDetectionModel
Definition FacialLandmarksCV.h:47
FacialLandmarkCVProps()
Definition FacialLandmarksCV.h:21
apra::ScalarPropertyValue getProperty(const std::string &propName) const
Definition FacialLandmarksCV.h:78
FaceDetectionModelType
Definition FacialLandmarksCV.h:15
@ SSD
Definition FacialLandmarksCV.h:16
@ HAAR_CASCADE
Definition FacialLandmarksCV.h:17
FacialLandmarkCVProps(FaceDetectionModelType _type, const std::string _Face_Detection_Configuration, const std::string _Face_Detection_Weights, const std::string _landmarksDetectionModel, cv::Ptr< cv::face::Facemark > _facemark)
Definition FacialLandmarksCV.h:25
static void applyProperties(PropsT &props, const std::map< std::string, apra::ScalarPropertyValue > &values, std::vector< std::string > &missingRequired)
Definition FacialLandmarksCV.h:59
FaceDetectionModelType type
Definition FacialLandmarksCV.h:43
std::string landmarksDetectionModel
Definition FacialLandmarksCV.h:46
std::string Face_Detection_Configuration
Definition FacialLandmarksCV.h:44
void serialize(Archive &ar, const unsigned int version)
Definition FacialLandmarksCV.h:100
size_t getSerializeSize()
Definition FacialLandmarksCV.h:50
cv::Ptr< cv::face::Facemark > facemark
Definition FacialLandmarksCV.h:48
FacialLandmarkCVProps(FaceDetectionModelType _type)
Definition FacialLandmarksCV.h:23
friend class boost::serialization::access
Definition FacialLandmarksCV.h:97
bool setProperty(const std::string &propName, const apra::ScalarPropertyValue &value)
Definition FacialLandmarksCV.h:87
Definition FacialLandmarksCV.h:108
boost::shared_ptr< Detail > mDetail
Definition FacialLandmarksCV.h:125
void setProps(FacialLandmarkCVProps &props)
Definition FacialLandmarksCV.cpp:331
bool process(frame_container &frames)
Definition FacialLandmarksCV.cpp:278
bool validateInputPins()
Definition FacialLandmarksCV.cpp:189
std::string mOutputPinId
Definition FacialLandmarksCV.h:128
FacialLandmarkCVProps getProps()
Definition FacialLandmarksCV.cpp:336
bool processSOS(frame_sp &frame)
Definition FacialLandmarksCV.cpp:311
bool term()
Definition FacialLandmarksCV.cpp:272
FacialLandmarkCV(FacialLandmarkCVProps props)
Definition FacialLandmarksCV.cpp:185
bool shouldTriggerSOS()
Definition FacialLandmarksCV.cpp:320
FacialLandmarkCVProps mProp
Definition FacialLandmarksCV.h:126
void addInputPin(framemetadata_sp &metadata, string &pinId)
Definition FacialLandmarksCV.cpp:241
bool validateOutputPins()
Definition FacialLandmarksCV.cpp:215
bool handlePropsChange(frame_sp &frame)
Definition FacialLandmarksCV.cpp:342
virtual ~FacialLandmarkCV()
Definition FacialLandmarksCV.cpp:187
bool processEOS(string &pinId)
Definition FacialLandmarksCV.cpp:325
bool init()
Definition FacialLandmarksCV.cpp:248
Definition Module.h:33
virtual size_t getSerializeSize()
Definition Module.h:101
Definition Module.h:151
void applyProp(T &member, const char *propName, const std::map< std::string, ScalarPropertyValue > &values, bool isRequired, std::vector< std::string > &missingRequired)
Definition PropertyMacros.h:36
std::variant< int64_t, double, bool, std::string > ScalarPropertyValue
Definition ModuleRegistry.h:30