32 string faceMarkModelFilename,
38 string msg =
"CVTrackedFaces: File not found: " + faceClassifierFilename;
46 string msg =
"CVTrackedFaces: File not found: " + faceMarkModelFilename;
50 cv::face::FacemarkLBF::Params facemarkParams;
51 facemarkParams.verbose =
false;
52 _facemark = cv::face::FacemarkLBF::create(facemarkParams);
53 _facemark->loadModel(faceMarkModelFilename);
106 assert(!imageGray.empty() &&
"ImageGray is empty");
107 assert(!imageBgr.empty() &&
"ImageBGR is empty");
108 assert(!calib->
cameraMat().empty() &&
"Calibration is empty");
118 int min = (int)((
float)imageGray.rows * 0.4f);
119 int max = (int)((
float)imageGray.rows * 0.8f);
131 for (
auto& face : faces)
132 face.height = (int)(face.height * 1.2f);
142 bool foundLandmarks =
_facemark->fit(imageBgr, faces, lm);
150 for (
unsigned long i = 0; i < lm.size(); i++)
178 cv::rectangle(imageBgr,
180 cv::Scalar(255, 0, 0),
184 for (
auto& j : lm[i])
188 cv::Scalar(0, 0, 255),
196 cv::Scalar(0, 255, 0),
246 CVSize size = imageBgr.size();
247 CVRect rect(0, 0, size.width, size.height);
250 cv::Subdiv2D subdiv(rect);
254 if (rect.contains(point))
255 subdiv.insert(point);
258 float w = (float)size.width;
259 float h = (
float)size.height;
261 subdiv.insert(
CVPoint2f(w * 0.5f, 0.0f));
262 subdiv.insert(
CVPoint2f(w - 1.0f, 0.0f));
263 subdiv.insert(
CVPoint2f(w - 1.0f, h * 0.5f));
264 subdiv.insert(
CVPoint2f(w - 1.0f, h - 1.0f));
265 subdiv.insert(
CVPoint2f(w * 0.5f, h - 1.0f));
266 subdiv.insert(
CVPoint2f(0.0f, h - 1.0f));
267 subdiv.insert(
CVPoint2f(0.0f, h * 0.5f));
272 vector<cv::Vec6f> triangleList;
273 subdiv.getTriangleList(triangleList);
276 for (
auto t : triangleList)
278 pt[0] =
CVPoint(cvRound(t[0]), cvRound(t[1]));
279 pt[1] =
CVPoint(cvRound(t[2]), cvRound(t[3]));
280 pt[2] =
CVPoint(cvRound(t[4]), cvRound(t[5]));
283 if (rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2]))
285 line(imageBgr, pt[0], pt[1], cv::Scalar(255, 255, 255), 1, cv::LINE_AA, 0);
286 line(imageBgr, pt[1], pt[2], cv::Scalar(255, 255, 255), 1, cv::LINE_AA, 0);
287 line(imageBgr, pt[2], pt[0], cv::Scalar(255, 255, 255), 1, cv::LINE_AA, 0);
Utils::Averaged< CVVec2f > AvgCVVec2f
cv::CascadeClassifier CVCascadeClassifier
vector< cv::Point2f > CVVPoint2f
vector< cv::Rect > CVVRect
vector< cv::Point > CVVPoint
vector< vector< cv::Point2f > > CVVVPoint2f
#define PROFILE_FUNCTION()
Live video camera calibration class with OpenCV an OpenCV calibration.
const CVMat & cameraMat() const
const CVMat & distortion() const
int _smoothLength
Smoothing filter lenght.
cv::Ptr< CVFacemark > _facemark
Facial landmarks detector smart pointer.
CVCascadeClassifier * _faceDetector
Viola-Jones face detector.
CVVPoint2f _cvPosePoints2D
vector of OpenCV point2D
vector< AvgCVVec2f > _avgPosePoints2D
vector of averaged facial landmark 2D points
bool track(CVMat imageGray, CVMat imageBgr, CVCalibration *calib) final
Tracks the a face and its landmarks.
CVVPoint3f _cvPosePoints3D
vector of OpenCV point2D
CVTrackedFaces(string faceClassifierFilename, string faceMarkModelFilename, int smoothLength=5)
Constructor for the facial landmark tracker.
static void delaunayTriangulate(CVMat imageBgr, const CVVPoint2f &points, bool drawDetection)
CVMatx44f _objectViewMat
view transformation matrix
static AvgFloat detectTimesMS
Averaged time for video feature detection & description in ms.
bool _drawDetection
Flag if detection should be drawn into image.
static cv::Matx44f createGLMatrix(const CVMat &tVec, const CVMat &rVec)
Create an OpenGL 4x4 matrix from an OpenCV translation & rotation vector.
static AvgFloat detect1TimesMS
Averaged time for video feature detection subpart 1 in ms.
HighResTimer _timer
High resolution timer.
static AvgFloat detect2TimesMS
Averaged time for video feature detection subpart 2 in ms.
static AvgFloat poseTimesMS
Averaged time for video feature pose estimation in ms.
float elapsedTimeInMilliSec()
void set(T value)
Sets the current value in the value array and builds the average.
bool fileExists(const string &pathfilename)
Returns true if a file exists.
void exitMsg(const char *tag, const char *msg, const int line, const char *file)
Terminates the application with a message. No leak checking.