Better UI visualization and scaling.

This commit is contained in:
Tadas Baltrusaitis 2017-01-09 16:11:19 -05:00
parent 72859cac77
commit e5cc957e37
2 changed files with 29 additions and 8 deletions

View File

@ -156,6 +156,7 @@ namespace OpenFaceOffline
// Camera calibration parameters // Camera calibration parameters
public double fx = -1, fy = -1, cx = -1, cy = -1; public double fx = -1, fy = -1, cx = -1, cy = -1;
bool estimate_camera_parameters = true;
public MainWindow() public MainWindow()
{ {
@ -374,7 +375,7 @@ namespace OpenFaceOffline
face_analyser.Reset(); face_analyser.Reset();
// If the camera calibration parameters are not set (indicated by -1), guesstimate them // If the camera calibration parameters are not set (indicated by -1), guesstimate them
if(fx == -1 || fy == -1 || cx == -1 || cy == -1) if(estimate_camera_parameters || fx == -1 || fy == -1 || cx == -1 || cy == -1)
{ {
fx = 500.0 * (capture.width / 640.0); fx = 500.0 * (capture.width / 640.0);
fy = 500.0 * (capture.height / 480.0); fy = 500.0 * (capture.height / 480.0);
@ -563,13 +564,15 @@ namespace OpenFaceOffline
else if (confidence > 1) else if (confidence > 1)
confidence = 1; confidence = 1;
double scale = 0;
if (detectionSucceeding) if (detectionSucceeding)
{ {
eye_landmarks = clnf_model.CalculateEyeLandmarks(); 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);
double scale = clnf_model.GetRigidParams()[0]; scale = clnf_model.GetRigidParams()[0];
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);
gaze_angle = face_analyser.GetGazeAngle(); gaze_angle = face_analyser.GetGazeAngle();
@ -634,6 +637,7 @@ namespace OpenFaceOffline
video.Confidence = confidence; video.Confidence = confidence;
video.FPS = processing_fps.GetFPS(); video.FPS = processing_fps.GetFPS();
video.Progress = progress; video.Progress = progress;
video.FaceScale = scale;
if (!detectionSucceeding) if (!detectionSucceeding)
{ {
@ -1039,6 +1043,14 @@ namespace OpenFaceOffline
fy = camera_params_entry_window.Fy; fy = camera_params_entry_window.Fy;
cx = camera_params_entry_window.Cx; cx = camera_params_entry_window.Cx;
cy = camera_params_entry_window.Cy; cy = camera_params_entry_window.Cy;
if(fx == -1 || fy == -1 || cx == -1 || cy == -1)
{
estimate_camera_parameters = true;
}
else
{
estimate_camera_parameters = false;
}
} }
} }

View File

@ -100,13 +100,20 @@ namespace OpenFaceOffline
var width = ((WriteableBitmap)Source).PixelWidth; var width = ((WriteableBitmap)Source).PixelWidth;
var height = ((WriteableBitmap)Source).PixelHeight; var height = ((WriteableBitmap)Source).PixelHeight;
// The point and line size should be proportional to the face size and the image scaling
double scaling_p = 0.88 * FaceScale * ActualWidth / width;
// Don't let it get too small
if (scaling_p < 0.6)
scaling_p = 0.6;
foreach (var line in OverlayLines) foreach (var line in OverlayLines)
{ {
var p1 = new Point(ActualWidth * line.Item1.X / width, ActualHeight * line.Item1.Y / height); var p1 = new Point(ActualWidth * line.Item1.X / width, ActualHeight * line.Item1.Y / height);
var p2 = new Point(ActualWidth * line.Item2.X / width, ActualHeight * line.Item2.Y / height); var p2 = new Point(ActualWidth * line.Item2.X / width, ActualHeight * line.Item2.Y / height);
dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(200, (byte)(100 + (155 * (1 - Confidence))), (byte)(100 + (155 * Confidence)), 100)), 2), p1, p2); dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(200, (byte)(100 + (155 * (1 - Confidence))), (byte)(100 + (155 * Confidence)), 100)), 2.0 * scaling_p), p1, p2);
} }
foreach (var line in GazeLines) foreach (var line in GazeLines)
@ -115,7 +122,7 @@ namespace OpenFaceOffline
var p1 = new Point(ActualWidth * line.Item1.X / width, ActualHeight * line.Item1.Y / height); var p1 = new Point(ActualWidth * line.Item1.X / width, ActualHeight * line.Item1.Y / height);
var p2 = new Point(ActualWidth * line.Item2.X / width, ActualHeight * line.Item2.Y / height); var p2 = new Point(ActualWidth * line.Item2.X / width, ActualHeight * line.Item2.Y / height);
dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(200, (byte)(240), (byte)(30), (byte)100)), 3), p1, p2); dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(200, (byte)(240), (byte)(30), (byte)100)), 3.0 * scaling_p), p1, p2);
} }
@ -124,7 +131,8 @@ namespace OpenFaceOffline
var q = new Point(ActualWidth * p.X / width, ActualHeight * p.Y / height); var q = new Point(ActualWidth * p.X / width, ActualHeight * p.Y / height);
dc.DrawEllipse(new SolidColorBrush(Color.FromArgb((byte)(200 * Confidence), 255, 255, 100)), null, q, 1, 1); dc.DrawEllipse(new SolidColorBrush(Color.FromArgb((byte)(230 * Confidence), 255, 50, 50)), null, q, 2.75 * scaling_p, 2.75 * scaling_p);
dc.DrawEllipse(new SolidColorBrush(Color.FromArgb((byte)(230 * Confidence), 255, 255, 100)), null, q, 1.75 * scaling_p, 1.75 * scaling_p);
} }
for (int id = 0; id < OverlayEyePoints.Count; id++) for (int id = 0; id < OverlayEyePoints.Count; id++)
@ -146,11 +154,11 @@ namespace OpenFaceOffline
if (id < 28 && (id < 8 || id > 19) || (id>=28 &&(id-28<8 || id-28 >19))) if (id < 28 && (id < 8 || id > 19) || (id>=28 &&(id-28<8 || id-28 >19)))
{ {
dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(200, (byte)(240), (byte)(30), (byte)100)), 1), q1, q2); dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(200, (byte)(240), (byte)(30), (byte)100)), 1.5 * scaling_p), q1, q2);
} }
else else
{ {
dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(200, (byte)(100), (byte)(30), (byte)240)), 1), q1, q2); dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(200, (byte)(100), (byte)(30), (byte)240)), 2.5 * scaling_p), q1, q2);
} }
} }
@ -190,6 +198,7 @@ namespace OpenFaceOffline
public List<Point> OverlayEyePoints { get; set; } public List<Point> OverlayEyePoints { get; set; }
public double Confidence { get; set; } public double Confidence { get; set; }
public double FPS { get; set; } public double FPS { get; set; }
public double FaceScale { get; set; }
// 0 to 1 indicates how much video has been processed so far // 0 to 1 indicates how much video has been processed so far
public double Progress { get; set; } public double Progress { get; set; }