Adding ability to not use MTCNN if the model is not present in GUI.

This commit is contained in:
Tadas Baltrusaitis
2018-05-02 08:06:37 +01:00
parent 7b60f3bfa1
commit 3c5dad7825
7 changed files with 63 additions and 19 deletions

1
.gitignore vendored
View File

@@ -86,3 +86,4 @@ gui/OpenFaceOffline/obj/
gui/OpenFaceDemo/obj/
exe/FeatureExtraction/processed/
matlab_runners/
exe/FaceLandmarkVidMulti/processed/

View File

@@ -233,7 +233,6 @@ int main(int argc, char **argv)
// Setting up the recorder output
open_face_rec.SetObservationHOG(face_model.detection_success, hog_descriptor, num_hog_rows, num_hog_cols, 31); // The number of channels in HOG is fixed at the moment, as using FHOG
open_face_rec.SetObservationVisualization(visualizer.GetVisImage());
open_face_rec.SetObservationActionUnits(face_analyser.GetCurrentAUsReg(), face_analyser.GetCurrentAUsClass());
open_face_rec.SetObservationLandmarks(face_model.detected_landmarks, face_model.GetShape(image_reader.fx, image_reader.fy, image_reader.cx, image_reader.cy),
face_model.params_global, face_model.params_local, face_model.detection_certainty, face_model.detection_success);
@@ -249,6 +248,7 @@ int main(int argc, char **argv)
visualizer.ShowObservation();
}
open_face_rec.SetObservationVisualization(visualizer.GetVisImage());
open_face_rec.WriteObservationTracked();
// Grabbing the next frame in the sequence

View File

@@ -48,6 +48,7 @@ using CppInterop;
using CppInterop.LandmarkDetector;
using System.Windows.Threading;
using GazeAnalyser_Interop;
using FaceDetectorInterop;
using ZeroMQ;
using System.Drawing;
@@ -370,6 +371,16 @@ namespace HeadPoseLive
String root = AppDomain.CurrentDomain.BaseDirectory;
FaceModelParameters model_params = new FaceModelParameters(root, true, false, false);
// Initialize the face detector
FaceDetector face_detector = new FaceDetector(model_params.GetHaarLocation(), model_params.GetMTCNNLocation());
// If MTCNN model not available, use HOG
if (!face_detector.IsMTCNNLoaded())
{
model_params.SetFaceDetector(false, true, false);
}
CLNF face_model = new CLNF(model_params);
GazeAnalyserManaged gaze_analyser = new GazeAnalyserManaged();
@@ -417,11 +428,12 @@ namespace HeadPoseLive
List<System.Windows.Point> landmarks = new List<System.Windows.Point>();
List<Tuple<System.Windows.Point, System.Windows.Point>> gaze_lines = null;
Tuple<float, float> gaze_angle = new Tuple<float, float>(0, 0);
var visibilities = face_model.GetVisibilities();
double scale = face_model.GetRigidParams()[0];
if (detectionSucceeding)
{
List<Tuple<float, float>> landmarks_doubles = face_model.CalculateVisibleLandmarks();
List<Tuple<float, float>> landmarks_doubles = face_model.CalculateAllLandmarks();
foreach (var p in landmarks_doubles)
landmarks.Add(new System.Windows.Point(p.Item1, p.Item2));
@@ -525,6 +537,7 @@ namespace HeadPoseLive
{
webcam_img.OverlayLines.Add(lines);
webcam_img.OverlayPoints.Add(landmarks);
webcam_img.OverlayPointsVisibility.Add(visibilities);
webcam_img.FaceScale.Add(scale);
List<System.Windows.Point> eye_landmark_points = new List<System.Windows.Point>();

View File

@@ -50,6 +50,7 @@ using OpenFaceOffline;
using OpenCVWrappers;
using CppInterop.LandmarkDetector;
using FaceAnalyser_Interop;
using FaceDetectorInterop;
using GazeAnalyser_Interop;
using UtilitiesOF;
@@ -119,6 +120,15 @@ namespace OpenFaceDemo
face_model_params = new FaceModelParameters(root, true, false, false);
face_model_params.optimiseForVideo();
// Initialize the face detector
FaceDetector face_detector = new FaceDetector(face_model_params.GetHaarLocation(), face_model_params.GetMTCNNLocation());
// If MTCNN model not available, use HOG
if (!face_detector.IsMTCNNLoaded())
{
face_model_params.SetFaceDetector(false, true, false);
}
landmark_detector = new CLNF(face_model_params);
face_analyser = new FaceAnalyserManaged(root, true, 112, true);
gaze_analyser = new GazeAnalyserManaged();

View File

@@ -64,24 +64,15 @@
</MenuItem>
<MenuItem Header="Face Detector" Name="FaceDetectorMenu">
<MenuItem x:Name="FaceDetHaar" Header="OpenCV (Haar)" IsCheckable="true" IsChecked="{Binding DetectorHaar}"></MenuItem>
<MenuItem x:Name="FaceDetHOG" Header="dlib (HOG-SVM)" IsCheckable="true" IsChecked="{Binding DetectorHOG}"></MenuItem>
<MenuItem x:Name="FaceDetCNN" Header="OpenFace (MTCNN)" IsCheckable="true" IsChecked="{Binding DetectorCNN}"></MenuItem>
<i:Interaction.Behaviors>
<OpenFaceOffline:ExclusiveMenuItemBehavior></OpenFaceOffline:ExclusiveMenuItemBehavior>
</i:Interaction.Behaviors>
<MenuItem x:Name="FaceDetHaar" Header="OpenCV (Haar)" IsCheckable="true" IsChecked="{Binding DetectorHaar}" Click="ExclusiveMenuItem_Click"></MenuItem>
<MenuItem x:Name="FaceDetHOG" Header="dlib (HOG-SVM)" IsCheckable="true" IsChecked="{Binding DetectorHOG}" Click="ExclusiveMenuItem_Click"></MenuItem>
<MenuItem x:Name="FaceDetCNN" Header="OpenFace (MTCNN)" IsCheckable="true" IsChecked="{Binding DetectorCNN}" Click="ExclusiveMenuItem_Click"></MenuItem>
</MenuItem>
<MenuItem Header="Landmark Detector" Name="LandmarkDetectorMenu">
<MenuItem x:Name="LandmarkDetCLM" Header="CLM" IsCheckable="true" IsChecked="{Binding LandmarkDetectorCLM}"></MenuItem>
<MenuItem x:Name="LandmarkDetCLNF" Header="CLNF" IsCheckable="true" IsChecked="{Binding LandmarkDetectorCLNF}"></MenuItem>
<MenuItem x:Name="LandmarkDetCECLM" Header="CE-CLM" IsCheckable="true" IsChecked="{Binding LandmarkDetectorCECLM}"></MenuItem>
<i:Interaction.Behaviors>
<OpenFaceOffline:ExclusiveMenuItemBehavior></OpenFaceOffline:ExclusiveMenuItemBehavior>
</i:Interaction.Behaviors>
<MenuItem x:Name="LandmarkDetCLM" Header="CLM" IsCheckable="true" IsChecked="{Binding LandmarkDetectorCLM}" Click="ExclusiveMenuItem_Click"></MenuItem>
<MenuItem x:Name="LandmarkDetCLNF" Header="CLNF" IsCheckable="true" IsChecked="{Binding LandmarkDetectorCLNF}" Click="ExclusiveMenuItem_Click"></MenuItem>
<MenuItem x:Name="LandmarkDetCECLM" Header="CE-CLM" IsCheckable="true" IsChecked="{Binding LandmarkDetectorCECLM}" Click="ExclusiveMenuItem_Click"></MenuItem>
</MenuItem>
</Menu>

View File

@@ -156,8 +156,20 @@ namespace OpenFaceOffline
this.Icon = BitmapFrame.Create(iconUri);
String root = AppDomain.CurrentDomain.BaseDirectory;
face_model_params = new FaceModelParameters(root, LandmarkDetectorCECLM, LandmarkDetectorCLNF, LandmarkDetectorCLM);
// Initialize the face detector
face_detector = new FaceDetector(face_model_params.GetHaarLocation(), face_model_params.GetMTCNNLocation());
// If MTCNN model not available, use HOG
if (!face_detector.IsMTCNNLoaded())
{
FaceDetCNN.IsEnabled = false;
DetectorCNN = false;
DetectorHOG = true;
}
face_model_params.SetFaceDetector(DetectorHaar, DetectorHOG, DetectorCNN);
landmark_detector = new CLNF(face_model_params);
gaze_analyser = new GazeAnalyserManaged();
@@ -980,6 +992,18 @@ namespace OpenFaceOffline
}
}
private void ExclusiveMenuItem_Click(object sender, RoutedEventArgs e)
{
// Disable all other items but this one
MenuItem parent = (MenuItem)((MenuItem)sender).Parent;
foreach (var me in parent.Items)
{
((MenuItem)me).IsChecked = false;
}
((MenuItem)sender).IsChecked = true;
}
private void setCameraParameters_Click(object sender, RoutedEventArgs e)
{
CameraParametersEntry camera_params_entry_window = new CameraParametersEntry(fx, fy, cx, cy);

View File

@@ -124,6 +124,11 @@ namespace FaceDetectorInterop {
}
}
bool IsMTCNNLoaded()
{
return !face_detector_mtcnn->empty();
}
// Face detection using MTCNN face detector
void DetectFacesMTCNN(List<System::Windows::Rect>^ o_regions, OpenCVWrappers::RawImage^ rgb_image, List<float>^ o_confidences)
{