From 72859cac77aafb861e928e1b490df912042c935c Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Fri, 6 Jan 2017 16:43:55 -0500 Subject: [PATCH] Editing camera calibration from the GUI, nicer interface for setting output size --- gui/OpenFaceOffline/MainWindow.xaml | 5 +- gui/OpenFaceOffline/MainWindow.xaml.cs | 59 ++--- gui/OpenFaceOffline/OpenFaceOffline.csproj | 7 + .../UI_items/CameraParametersEntry.xaml | 47 ++++ .../UI_items/CameraParametersEntry.xaml.cs | 219 ++++++++++++++++++ .../UI_items/NumberEntryWindow.xaml | 19 +- .../UI_items/NumberEntryWindow.xaml.cs | 43 ++-- 7 files changed, 344 insertions(+), 55 deletions(-) create mode 100644 gui/OpenFaceOffline/UI_items/CameraParametersEntry.xaml create mode 100644 gui/OpenFaceOffline/UI_items/CameraParametersEntry.xaml.cs diff --git a/gui/OpenFaceOffline/MainWindow.xaml b/gui/OpenFaceOffline/MainWindow.xaml index 9729bba..e580e5f 100644 --- a/gui/OpenFaceOffline/MainWindow.xaml +++ b/gui/OpenFaceOffline/MainWindow.xaml @@ -44,8 +44,9 @@ - - + + + diff --git a/gui/OpenFaceOffline/MainWindow.xaml.cs b/gui/OpenFaceOffline/MainWindow.xaml.cs index 1d4440a..c5f0349 100644 --- a/gui/OpenFaceOffline/MainWindow.xaml.cs +++ b/gui/OpenFaceOffline/MainWindow.xaml.cs @@ -147,10 +147,6 @@ namespace OpenFaceOffline public bool ShowAUs { get; set; } = true; // Showing Facial Action Units int image_output_size = 112; - - // TODO classifiers converted to regressors - - // TODO indication that track is done // Where the recording is done (by default in a record directory, from where the application executed) String record_root = "./record"; @@ -158,6 +154,9 @@ namespace OpenFaceOffline // For AU prediction, if videos are long dynamic models should be used public bool DynamicAUModels { get; set; } = true; + // Camera calibration parameters + public double fx = -1, fy = -1, cx = -1, cy = -1; + public MainWindow() { InitializeComponent(); @@ -374,15 +373,18 @@ namespace OpenFaceOffline clnf_model.Reset(); face_analyser.Reset(); - // TODO add an ability to change these through a calibration procedure or setting menu - double fx = 500.0 * (capture.width / 640.0); - double fy = 500.0 * (capture.height / 480.0); + // If the camera calibration parameters are not set (indicated by -1), guesstimate them + if(fx == -1 || fy == -1 || cx == -1 || cy == -1) + { + fx = 500.0 * (capture.width / 640.0); + fy = 500.0 * (capture.height / 480.0); - fx = (fx + fy) / 2.0; - fy = fx; + fx = (fx + fy) / 2.0; + fy = fx; - double cx = capture.width / 2f; - double cy = capture.height / 2f; + cx = capture.width / 2f; + cy = capture.height / 2f; + } // Setup the recorder first recorder = new Recorder(record_root, output_file_name, capture.width, capture.height, Record2DLandmarks, Record3DLandmarks, RecordModelParameters, RecordPose, @@ -410,7 +412,6 @@ namespace OpenFaceOffline break; } - // TODO stop button should actually clear the video lastFrameTime = CurrentTime; processing_fps.AddFrame(); @@ -468,20 +469,7 @@ namespace OpenFaceOffline DateTime? startTime = CurrentTime; var lastFrameTime = CurrentTime; - - clnf_model.Reset(); - face_analyser.Reset(); - - // TODO these need to be stored so that they could be loaded somewhere - double fx = 500.0 * (capture.width / 640.0); - double fy = 500.0 * (capture.height / 480.0); - - fx = (fx + fy) / 2.0; - fy = fx; - - double cx = capture.width / 2f; - double cy = capture.height / 2f; - + int frame_id = 0; double fps = capture.GetFPS(); @@ -1024,7 +1012,7 @@ namespace OpenFaceOffline private void setOutputImageSize_Click(object sender, RoutedEventArgs e) { - NumberEntryWindow number_entry_window = new NumberEntryWindow(); + NumberEntryWindow number_entry_window = new NumberEntryWindow(image_output_size); number_entry_window.Icon = this.Icon; number_entry_window.WindowStartupLocation = WindowStartupLocation.CenterScreen; @@ -1038,6 +1026,22 @@ namespace OpenFaceOffline } } + private void setCameraParameters_Click(object sender, RoutedEventArgs e) + { + CameraParametersEntry camera_params_entry_window = new CameraParametersEntry(fx, fy, cx, cy); + camera_params_entry_window.Icon = this.Icon; + + camera_params_entry_window.WindowStartupLocation = WindowStartupLocation.CenterScreen; + + if (camera_params_entry_window.ShowDialog() == true) + { + fx = camera_params_entry_window.Fx; + fy = camera_params_entry_window.Fy; + cx = camera_params_entry_window.Cx; + cy = camera_params_entry_window.Cy; + } + } + private void OutputLocationItem_Click(object sender, RoutedEventArgs e) { var dlg = new CommonOpenFileDialog(); @@ -1057,5 +1061,6 @@ namespace OpenFaceOffline record_root = folder; } } + } } diff --git a/gui/OpenFaceOffline/OpenFaceOffline.csproj b/gui/OpenFaceOffline/OpenFaceOffline.csproj index a3f6d81..4a26cbf 100644 --- a/gui/OpenFaceOffline/OpenFaceOffline.csproj +++ b/gui/OpenFaceOffline/OpenFaceOffline.csproj @@ -94,6 +94,9 @@ BarGraphHorizontal.xaml + + CameraParametersEntry.xaml + MultiBarGraph.xaml @@ -129,6 +132,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/gui/OpenFaceOffline/UI_items/CameraParametersEntry.xaml b/gui/OpenFaceOffline/UI_items/CameraParametersEntry.xaml new file mode 100644 index 0000000..f1ad043 --- /dev/null +++ b/gui/OpenFaceOffline/UI_items/CameraParametersEntry.xaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +