Towards better eye landmark vis.

This commit is contained in:
Tadas Baltrusaitis 2016-11-28 15:34:42 -05:00
parent 04afc144f7
commit a57fbdea7b
3 changed files with 37 additions and 0 deletions

View file

@ -503,11 +503,13 @@ namespace OpenFaceOffline
List<Tuple<Point, Point>> lines = null; List<Tuple<Point, Point>> lines = null;
List<Tuple<double, double>> landmarks = null; List<Tuple<double, double>> landmarks = null;
List<Tuple<double, double>> eye_landmarks = null;
List<Tuple<Point, Point>> gaze_lines = null; List<Tuple<Point, Point>> gaze_lines = null;
if (detectionSucceeding) if (detectionSucceeding)
{ {
landmarks = clnf_model.CalculateLandmarks(); landmarks = clnf_model.CalculateLandmarks();
eye_landmarks = clnf_model.CalculateEyeLandmarks();
lines = clnf_model.CalculateBox((float)fx, (float)fy, (float)cx, (float)cy); lines = clnf_model.CalculateBox((float)fx, (float)fy, (float)cx, (float)cy);
gaze_lines = face_analyser.CalculateGazeLines(scale, (float)fx, (float)fy, (float)cx, (float)cy); gaze_lines = face_analyser.CalculateGazeLines(scale, (float)fx, (float)fy, (float)cx, (float)cy);
} }

View file

@ -291,6 +291,17 @@ namespace CppInterop {
return landmarks; return landmarks;
} }
System::Collections::Generic::List<System::Tuple<double, double>^>^ CalculateEyeLandmarks() {
vector<cv::Point2d> vecLandmarks = ::LandmarkDetector::CalculateEyeLandmarks(*clnf);
auto landmarks = gcnew System::Collections::Generic::List<System::Tuple<double, double>^>();
for (cv::Point2d p : vecLandmarks) {
landmarks->Add(gcnew System::Tuple<double, double>(p.x, p.y));
}
return landmarks;
}
System::Collections::Generic::List<System::Windows::Media::Media3D::Point3D>^ Calculate3DLandmarks(double fx, double fy, double cx, double cy) { System::Collections::Generic::List<System::Windows::Media::Media3D::Point3D>^ Calculate3DLandmarks(double fx, double fy, double cx, double cy) {
cv::Mat_<double> shape3D = clnf->GetShape(fx, fy, cx, cy); cv::Mat_<double> shape3D = clnf->GetShape(fx, fy, cx, cy);

View file

@ -1064,6 +1064,30 @@ vector<cv::Point2d> CalculateLandmarks(CLNF& clnf_model)
} }
// Computing eye landmarks (to be drawn later or in different interfaces)
vector<cv::Point2d> CalculateEyeLandmarks(CLNF& clnf_model)
{
int idx = clnf_model.patch_experts.GetViewIdx(clnf_model.params_global, 0);
vector<cv::Point2d> to_return;
// If the model has hierarchical updates draw those too
for (size_t i = 0; i < clnf_model.hierarchical_models.size(); ++i)
{
if (clnf_model.hierarchical_model_names[i].compare("left_eye_28") == 0 ||
clnf_model.hierarchical_model_names[i].compare("right_eye_28") == 0)
{
auto lmks = CalculateLandmarks(clnf_model.hierarchical_models[i].detected_landmarks, clnf_model.hierarchical_models[i].patch_experts.visibilities[0][idx]);
for (auto lmk : lmks)
{
to_return.push_back(lmk);
}
}
}
return to_return;
}
// Drawing landmarks on a face image // Drawing landmarks on a face image
void Draw(cv::Mat img, const cv::Mat_<double>& shape2D, const cv::Mat_<int>& visibilities) void Draw(cv::Mat img, const cv::Mat_<double>& shape2D, const cv::Mat_<int>& visibilities)
{ {