Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facelandmarks cv #218

Merged
merged 13 commits into from
Jul 18, 2023
3 changes: 3 additions & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ SET(IP_FILES
src/ImageViewerModule.cpp
src/BMPConverter.cpp
src/ImageResizeCV.cpp
src/FacialLandmarksCV.cpp
src/ImageEncoderCV.cpp
src/RotateCV.cpp
src/BrightnessContrastControlXform.cpp
Expand Down Expand Up @@ -288,6 +289,7 @@ SET(IP_FILES_H
include/ImageDecoderCV.h
include/BMPConverter.h
include/ImageResizeCV.h
include/FacialLandmarksCV.h
include/ImageEncoderCV.h
include/RotateCV.h
include/BrightnessContrastControlXform.h
Expand Down Expand Up @@ -520,6 +522,7 @@ SET(UT_FILES
test/findexstrategy_tests.cpp
test/jpegdecodercv_tests.cpp
test/Imageresizecv_tests.cpp
test/faciallandmarkscv_tests.cpp
test/ImageEncodeCV_tests.cpp
test/rotatecv_tests.cpp
test/brightness_contrast_tests.cpp
Expand Down
5 changes: 5 additions & 0 deletions base/include/ApraPoint2f.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class ApraPoint2f : public cv::Point2f

}

ApraPoint2f(cv::Point2f &point) : cv::Point2f(point)
{

}

private:
friend class boost::serialization::access;

Expand Down
84 changes: 84 additions & 0 deletions base/include/FacialLandmarksCV.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#pragma once

#include <opencv2/face.hpp>
#include "Module.h"

class Detail;
class DetailSSD;
class DetailHCASCADE;

class FacialLandmarkCVProps : public ModuleProps
venkat0907 marked this conversation as resolved.
Show resolved Hide resolved
{
public:
enum FaceDetectionModelType
{
SSD,
HAAR_CASCADE
};

FacialLandmarkCVProps(FaceDetectionModelType _type) : type(_type) {}

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)
: type(_type), Face_Detection_Configuration(_Face_Detection_Configuration), Face_Detection_Weights(_Face_Detection_Weights), landmarksDetectionModel(_landmarksDetectionModel),facemark(_facemark)
{
if (_type != FaceDetectionModelType::SSD)
{
throw AIPException(AIP_FATAL, "This constructor only supports SSD");
}
}

FacialLandmarkCVProps(FaceDetectionModelType _type, const std::string _faceDetectionModel,const std::string _landmarksDetectionModel, cv::Ptr<cv::face::Facemark> _facemark)
: type(_type), landmarksDetectionModel(_landmarksDetectionModel), faceDetectionModel(_faceDetectionModel), facemark(_facemark)
{
if (_type != FaceDetectionModelType::HAAR_CASCADE)
{
throw AIPException(AIP_FATAL, "This constructor only supports HAAR_CASCADE ");
}
}

FaceDetectionModelType type;
const std::string Face_Detection_Configuration = "./data/assets/deploy.prototxt";
const std::string Face_Detection_Weights = "./data/assets/res10_300x300_ssd_iter_140000_fp16.caffemodel";
const std::string landmarksDetectionModel = "./data/assets/face_landmark_model.dat";
const std::string faceDetectionModel = "./data/assets/haarcascade.xml";
cv::Ptr<cv::face::Facemark> facemark = cv::face::FacemarkKazemi::create();

size_t getSerializeSize()
{
return ModuleProps::getSerializeSize() + sizeof(type);
}

private:
friend class boost::serialization::access;

template <class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar& boost::serialization::base_object<ModuleProps>(*this);
ar& type;
}
};

class FacialLandmarkCV : public Module
{
public:
FacialLandmarkCV(FacialLandmarkCVProps props);
virtual ~FacialLandmarkCV();
bool init();
bool term();
void setProps(FacialLandmarkCVProps& props);
FacialLandmarkCVProps getProps();

protected:
bool process(frame_container &frames);
bool processSOS(frame_sp &frame);
bool validateInputPins();
bool validateOutputPins();
void addInputPin(framemetadata_sp &metadata, string &pinId); // throws exception if validation fails
bool shouldTriggerSOS();
bool processEOS(string &pinId);
boost::shared_ptr<Detail> mDetail;
FacialLandmarkCVProps mProp;
bool handlePropsChange(frame_sp& frame);
std::string mOutputPinId1;
};
3 changes: 2 additions & 1 deletion base/include/FrameMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class FrameMetadata {
MP4_VIDEO_METADATA,
HEVC_DATA, //H265
MOTION_VECTOR_DATA,
OVERLAY_INFO_IMAGE
OVERLAY_INFO_IMAGE,
FACE_LANDMARKS_INFO
};

enum MemType
Expand Down
Loading
Loading