From 32a9ee0a7ed22674121ee92fb75c13134a3bb5de Mon Sep 17 00:00:00 2001 From: Tadas Baltrusaitis Date: Wed, 1 Nov 2017 19:59:23 +0000 Subject: [PATCH] Working on the HOG recorder. --- lib/local/Recorder/include/RecorderCSV.h | 6 +- lib/local/Recorder/include/RecorderHOG.h | 12 ++-- lib/local/Recorder/src/RecorderHOG.cpp | 89 ++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 lib/local/Recorder/src/RecorderHOG.cpp diff --git a/lib/local/Recorder/include/RecorderCSV.h b/lib/local/Recorder/include/RecorderCSV.h index 9b58426..2b6933a 100644 --- a/lib/local/Recorder/include/RecorderCSV.h +++ b/lib/local/Recorder/include/RecorderCSV.h @@ -54,13 +54,13 @@ namespace Recorder RecorderCSV(); // Opening the file and preparing the header for it - bool open(std::string output_file_name, bool output_2D_landmarks, bool output_3D_landmarks, bool output_model_params, bool output_pose, bool output_AUs, bool output_gaze, + bool Open(std::string output_file_name, bool output_2D_landmarks, bool output_3D_landmarks, bool output_model_params, bool output_pose, bool output_AUs, bool output_gaze, int num_face_landmarks, int num_model_modes, int num_eye_landmarks, std::vector au_names_class, std::vector au_names_reg); // Closing the file and cleaning up - void close(); + void Close(); - void writeLine(); + void WriteLine(); // TODO have set functions? diff --git a/lib/local/Recorder/include/RecorderHOG.h b/lib/local/Recorder/include/RecorderHOG.h index 45797c9..7971eb2 100644 --- a/lib/local/Recorder/include/RecorderHOG.h +++ b/lib/local/Recorder/include/RecorderHOG.h @@ -50,19 +50,23 @@ namespace Recorder public: // The constructor for the recorder, by default does not do anything - RecorderHOG() {}; + RecorderHOG(int num_rows, int num_cols, int num_channels); - // Adding observations to the recorder - void AddObservationHOG(cv::Mat_ aligned_HOG, bool success); + void AddObservationHOG(bool success, const cv::Mat_& hog_descriptor); - void Open(std::string filename); + bool Open(std::string filename); void Close(); + private: + std::ofstream hog_file; + int num_rows; + int num_cols; + const int num_channels; }; } #endif \ No newline at end of file diff --git a/lib/local/Recorder/src/RecorderHOG.cpp b/lib/local/Recorder/src/RecorderHOG.cpp new file mode 100644 index 0000000..fb75b29 --- /dev/null +++ b/lib/local/Recorder/src/RecorderHOG.cpp @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017, Tadas Baltrusaitis, all rights reserved. +// +// ACADEMIC OR NON-PROFIT ORGANIZATION NONCOMMERCIAL RESEARCH USE ONLY +// +// BY USING OR DOWNLOADING THE SOFTWARE, YOU ARE AGREEING TO THE TERMS OF THIS LICENSE AGREEMENT. +// IF YOU DO NOT AGREE WITH THESE TERMS, YOU MAY NOT USE OR DOWNLOAD THE SOFTWARE. +// +// License can be found in OpenFace-license.txt +// +// * Any publications arising from the use of this software, including but +// not limited to academic journal and conference publications, technical +// reports and manuals, must cite at least one of the following works: +// +// OpenFace: an open source facial behavior analysis toolkit +// Tadas Baltrušaitis, Peter Robinson, and Louis-Philippe Morency +// in IEEE Winter Conference on Applications of Computer Vision, 2016 +// +// Rendering of Eyes for Eye-Shape Registration and Gaze Estimation +// Erroll Wood, Tadas Baltrušaitis, Xucong Zhang, Yusuke Sugano, Peter Robinson, and Andreas Bulling +// in IEEE International. Conference on Computer Vision (ICCV), 2015 +// +// Cross-dataset learning and person-speci?c normalisation for automatic Action Unit detection +// Tadas Baltrušaitis, Marwa Mahmoud, and Peter Robinson +// in Facial Expression Recognition and Analysis Challenge, +// IEEE International Conference on Automatic Face and Gesture Recognition, 2015 +// +// Constrained Local Neural Fields for robust facial landmark detection in the wild. +// Tadas Baltrušaitis, Peter Robinson, and Louis-Philippe Morency. +// in IEEE Int. Conference on Computer Vision Workshops, 300 Faces in-the-Wild Challenge, 2013. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "RecorderHOG.h" + +#include + +using namespace Recorder; + +// Default constructor initializes the variables +RecorderHOG::RecorderHOG(int num_rows, int num_cols, int num_channels) :hog_file(),num_rows(num_rows), num_cols(num_cols), num_channels(num_channels) {}; + +// TODO the other 4 constructors + destructors? + +// Opening the file and preparing the header for it +bool RecorderHOG::Open(std::string output_file_name) +{ + hog_file.open(output_file_name, std::ios_base::out | std::ios_base::binary); + + return hog_file.is_open(); +} + +void RecorderHOG::Close() +{ + hog_file.close(); +} + +// Writing to a HOG file +void RecorderHOG::AddObservationHOG(bool good_frame, const cv::Mat_& hog_descriptor) +{ + + hog_file.write((char*)(&num_cols), 4); + hog_file.write((char*)(&num_rows), 4); + hog_file.write((char*)(&num_channels), 4); + + // Not the best way to store a bool, but will be much easier to read it + float good_frame_float; + if (good_frame) + good_frame_float = 1; + else + good_frame_float = -1; + + hog_file.write((char*)(&good_frame_float), 4); + + cv::MatConstIterator_ descriptor_it = hog_descriptor.begin(); + + for (int y = 0; y < num_cols; ++y) + { + for (int x = 0; x < num_rows; ++x) + { + for (unsigned int o = 0; o < 31; ++o) + { + + float hog_data = (float)(*descriptor_it++); + hog_file.write((char*)&hog_data, 4); + } + } + } +} \ No newline at end of file