From 0ffc272ff42d5250655fd8d8e324b7692ccda3ee Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Sat, 27 Jan 2018 12:12:36 +0000 Subject: [PATCH] Adding option for camera parameters with new interface. --- gui/OpenFaceOffline/MainWindow.xaml.cs | 15 +++-------- lib/local/CppInerop/SequenceReader.h | 35 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/gui/OpenFaceOffline/MainWindow.xaml.cs b/gui/OpenFaceOffline/MainWindow.xaml.cs index 6bac79a..edde8f9 100644 --- a/gui/OpenFaceOffline/MainWindow.xaml.cs +++ b/gui/OpenFaceOffline/MainWindow.xaml.cs @@ -133,7 +133,6 @@ namespace OpenFaceOffline // Camera calibration parameters public float fx = -1, fy = -1, cx = -1, cy = -1; - bool estimate_camera_parameters = true; public MainWindow() { @@ -161,7 +160,7 @@ namespace OpenFaceOffline { for (int i = 0; i < filenames.Count; ++i) { - SequenceReader reader = new SequenceReader(filenames[i], false); + SequenceReader reader = new SequenceReader(filenames[i], false, fx, fy, cx, cy); ProcessSequence(reader); // Before continuing to next video make sure the user did not stop the processing @@ -709,7 +708,7 @@ namespace OpenFaceOffline string directory = openDirectory(); if (!string.IsNullOrWhiteSpace(directory)) { - SequenceReader reader = new SequenceReader(directory, true); + SequenceReader reader = new SequenceReader(directory, true, fx, fy, cx, cy); processing_thread = new Thread(() => ProcessSequence(reader)); processing_thread.Name = "Image sequence processing"; @@ -789,7 +788,7 @@ namespace OpenFaceOffline int width = cam_sec.selected_camera.Item2; int height = cam_sec.selected_camera.Item3; - SequenceReader reader = new SequenceReader(cam_id, width, height); + SequenceReader reader = new SequenceReader(cam_id, width, height, fx, fy, cx, cy); processing_thread = new Thread(() => ProcessSequence(reader)); processing_thread.Name = "Webcam processing"; @@ -942,14 +941,6 @@ namespace OpenFaceOffline fy = camera_params_entry_window.Fy; cx = camera_params_entry_window.Cx; cy = camera_params_entry_window.Cy; - if(fx == -1 || fy == -1 || cx == -1 || cy == -1) - { - estimate_camera_parameters = true; - } - else - { - estimate_camera_parameters = false; - } } } diff --git a/lib/local/CppInerop/SequenceReader.h b/lib/local/CppInerop/SequenceReader.h index 19d054f..b412f42 100644 --- a/lib/local/CppInerop/SequenceReader.h +++ b/lib/local/CppInerop/SequenceReader.h @@ -97,6 +97,29 @@ namespace UtilitiesOF { } } + SequenceReader(System::String^ filename, bool directory, float fx, float fy, float cx, float cy) + { + m_sequence_capture = new Utilities::SequenceCapture(); + + std::string name_std = msclr::interop::marshal_as(filename); + + bool success; + + if (directory) + { + success = m_sequence_capture->OpenImageSequence(name_std, fx, fy, cx, cy); + } + else + { + success = m_sequence_capture->OpenVideoFile(name_std, fx, fy, cx, cy); + } + + if (!success) + { + throw gcnew ReadingFailedException("Failed to open an image sequence"); + } + } + // Can provide a webcam id SequenceReader(int webcam_id, int width, int height) { @@ -110,6 +133,18 @@ namespace UtilitiesOF { } } + SequenceReader(int webcam_id, int width, int height, float fx, float fy, float cx, float cy) + { + m_sequence_capture = new Utilities::SequenceCapture(); + + bool success = m_sequence_capture->OpenWebcam(webcam_id, width, height, fx, fy, cx, cy); + + if (!success) + { + throw gcnew ReadingFailedException("Failed to open an image sequence"); + } + } + OpenCVWrappers::RawImage^ GetNextImage() { cv::Mat next_image = m_sequence_capture->GetNextFrame();