X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=include%2Ffacial_landmark_detector.h;h=3956c2f28b9d45aa4332ce798f5e8a77540e0d9a;hb=bc67426f7a951c1b99c5fa6ba5d25ae0869f7a13;hp=5163fe9a4e810e8b28f94e74521ab916ebd70a73;hpb=2b1f0c7c63dc30d20c9d55fda5e99b208a9f82b3;p=facial-landmarks-for-cubism.git diff --git a/include/facial_landmark_detector.h b/include/facial_landmark_detector.h index 5163fe9..3956c2f 100644 --- a/include/facial_landmark_detector.h +++ b/include/facial_landmark_detector.h @@ -1,10 +1,10 @@ // -*- mode: c++ -*- -#ifndef __FACIAL_LANDMARK_DETECTOR_H__ -#define __FACIAL_LANDMARK_DETECTOR_H__ +#ifndef FACIAL_LANDMARK_DETECTOR_H +#define FACIAL_LANDMARK_DETECTOR_H /**** -Copyright (c) 2020 Adrian I. Lam +Copyright (c) 2020-2021 Adrian I. Lam Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -27,10 +27,18 @@ SOFTWARE. #include #include -#include -#include -#include -#include + +struct Point +{ + double x; + double y; + + Point(double _x = 0, double _y = 0) + { + x = _x; + y = _y; + } +}; class FacialLandmarkDetector { @@ -50,11 +58,12 @@ public: bool autoBreath; bool randomMotion; // TODO eyebrows currently not supported... - // I'd like to include them, but the dlib detection is very + // I'd like to include them, but the dlib / OSF detection is very // noisy and inaccurate (at least for my face). }; FacialLandmarkDetector(std::string cfgPath); + ~FacialLandmarkDetector(); Params getParams(void) const; @@ -63,35 +72,37 @@ public: void mainLoop(void); private: + FacialLandmarkDetector(const FacialLandmarkDetector&) = delete; + FacialLandmarkDetector& operator=(const FacialLandmarkDetector &) = delete; + enum LeftRight : bool { LEFT, RIGHT }; - cv::VideoCapture webcam; - dlib::image_window win; - dlib::frontal_face_detector detector; - dlib::shape_predictor predictor; bool m_stop; - double calcEyeAspectRatio(dlib::point& p1, dlib::point& p2, - dlib::point& p3, dlib::point& p4, - dlib::point& p5, dlib::point& p6) const; + int m_sock; + static const int m_faceId = 0; // Only support one face for now + + double calcEyeAspectRatio(Point& p1, Point& p2, + Point& p3, Point& p4, + Point& p5, Point& p6) const; - double calcRightEyeAspectRatio(dlib::full_object_detection& shape) const; - double calcLeftEyeAspectRatio(dlib::full_object_detection& shape) const; + double calcRightEyeAspectRatio(Point landmarks[]) const; + double calcLeftEyeAspectRatio(Point landmarks[]) const; double calcEyeOpenness(LeftRight eye, - dlib::full_object_detection& shape, + Point landmarks[], double faceYAngle) const; - double calcMouthForm(dlib::full_object_detection& shape) const; - double calcMouthOpenness(dlib::full_object_detection& shape, double mouthForm) const; + double calcMouthForm(Point landmarks[]) const; + double calcMouthOpenness(Point landmarks[], double mouthForm) const; - double calcFaceXAngle(dlib::full_object_detection& shape) const; - double calcFaceYAngle(dlib::full_object_detection& shape, double faceXAngle, double mouthForm) const; - double calcFaceZAngle(dlib::full_object_detection& shape) const; + double calcFaceXAngle(Point landmarks[]) const; + double calcFaceYAngle(Point landmarks[], double faceXAngle, double mouthForm) const; + double calcFaceZAngle(Point landmarks[]) const; void populateDefaultConfig(void); void parseConfig(std::string cfgPath); @@ -111,15 +122,12 @@ private: struct Config { - int cvVideoCaptureId; - std::string predictorPath; + std::string osfIpAddress; + int osfPort; double faceYAngleCorrection; double eyeSmileEyeOpenThreshold; double eyeSmileMouthFormThreshold; double eyeSmileMouthOpenThreshold; - bool showWebcamVideo; - bool renderLandmarksOnVideo; - bool lateralInversion; std::size_t faceXAngleNumTaps; std::size_t faceYAngleNumTaps; std::size_t faceZAngleNumTaps; @@ -127,7 +135,6 @@ private: std::size_t mouthOpenNumTaps; std::size_t leftEyeOpenNumTaps; std::size_t rightEyeOpenNumTaps; - int cvWaitKeyMs; double eyeClosedThreshold; double eyeOpenThreshold; double mouthNormalThreshold; @@ -140,6 +147,7 @@ private: double faceYAngleZeroValue; double faceYAngleUpThreshold; double faceYAngleDownThreshold; + bool winkEnable; bool autoBlink; bool autoBreath; bool randomMotion;