From 79d7116dae7f6b5335016dcb0e9ea64e1f931287 Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Fri, 29 Jun 2018 09:57:45 +0100 Subject: [PATCH] Bug fix with output aligned faces and videos if no face is detected in the first frame. Adding .webm file support --- gui/OpenFaceOffline/MainWindow.xaml.cs | 2 +- lib/local/Utilities/include/RecorderOpenFace.h | 2 ++ lib/local/Utilities/src/RecorderOpenFace.cpp | 15 ++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gui/OpenFaceOffline/MainWindow.xaml.cs b/gui/OpenFaceOffline/MainWindow.xaml.cs index 39e319ffe..11f74edf4 100644 --- a/gui/OpenFaceOffline/MainWindow.xaml.cs +++ b/gui/OpenFaceOffline/MainWindow.xaml.cs @@ -759,7 +759,7 @@ private List openMediaDialog(bool images) } else { - d.Filter = "Video files|*.avi;*.wmv;*.mov;*.mpg;*.mpeg;*.mp4"; + d.Filter = "Video files|*.avi;*.webm;*.wmv;*.mov;*.mpg;*.mpeg;*.mp4"; } if (d.ShowDialog(this) == true) { diff --git a/lib/local/Utilities/include/RecorderOpenFace.h b/lib/local/Utilities/include/RecorderOpenFace.h index 70f9ce094..1a712dec1 100644 --- a/lib/local/Utilities/include/RecorderOpenFace.h +++ b/lib/local/Utilities/include/RecorderOpenFace.h @@ -175,11 +175,13 @@ namespace Utilities // Do not exceed 100MB in the concurrent queue const int TRACKED_QUEUE_CAPACITY = 100; + bool tracked_writing_thread_started; cv::Mat vis_to_out; tbb::concurrent_bounded_queue > vis_to_out_queue; // For aligned face writing const int ALIGNED_QUEUE_CAPACITY = 100; + bool aligned_writing_thread_started; cv::Mat aligned_face; tbb::concurrent_bounded_queue > aligned_face_queue; diff --git a/lib/local/Utilities/src/RecorderOpenFace.cpp b/lib/local/Utilities/src/RecorderOpenFace.cpp index 9b64a9baa..74b36706c 100644 --- a/lib/local/Utilities/src/RecorderOpenFace.cpp +++ b/lib/local/Utilities/src/RecorderOpenFace.cpp @@ -213,6 +213,8 @@ void RecorderOpenFace::PrepareRecording(const std::string& in_filename) } this->frame_number = 0; + this->tracked_writing_thread_started = false; + this->aligned_writing_thread_started = false; } RecorderOpenFace::RecorderOpenFace(const std::string in_filename, const RecorderOpenFaceParameters& parameters, std::vector& arguments):video_writer(), params(parameters) @@ -363,10 +365,10 @@ void RecorderOpenFace::WriteObservation() // Write aligned faces if (params.outputAlignedFaces()) { - // To support both video and image input - if ((face_id == 0 && frame_number == 0) || (face_id == 0 && frame_number == 1)) - { + if (!aligned_writing_thread_started) + { + aligned_writing_thread_started = true; int capacity = (1024 * 1024 * ALIGNED_QUEUE_CAPACITY) / (aligned_face.size().width *aligned_face.size().height * aligned_face.channels()) + 1; aligned_face_queue.set_capacity(capacity); @@ -412,9 +414,10 @@ void RecorderOpenFace::WriteObservationTracked() if (params.outputTracked()) { - // To support both video and image input - if ((!params.isSequence() && frame_number == 0) || (params.isSequence() && frame_number == 1)) + + if (!tracked_writing_thread_started) { + tracked_writing_thread_started = true; // Set up the queue for video writing based on output size int capacity = (1024 * 1024 * TRACKED_QUEUE_CAPACITY) / (vis_to_out.size().width * vis_to_out.size().height * vis_to_out.channels()) + 1; vis_to_out_queue.set_capacity(capacity); @@ -547,6 +550,8 @@ void RecorderOpenFace::Close() aligned_writing_thread.join(); #endif + tracked_writing_thread_started = false; + aligned_writing_thread_started = false; hog_recorder.Close(); csv_recorder.Close();