Working on the HOG recorder.
This commit is contained in:
parent
b9378f8e5e
commit
32a9ee0a7e
3 changed files with 100 additions and 7 deletions
|
@ -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<std::string> au_names_class, std::vector<std::string> au_names_reg);
|
||||
|
||||
// Closing the file and cleaning up
|
||||
void close();
|
||||
void Close();
|
||||
|
||||
void writeLine();
|
||||
void WriteLine();
|
||||
|
||||
// TODO have set functions?
|
||||
|
||||
|
|
|
@ -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_<double> aligned_HOG, bool success);
|
||||
void AddObservationHOG(bool success, const cv::Mat_<double>& 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
|
89
lib/local/Recorder/src/RecorderHOG.cpp
Normal file
89
lib/local/Recorder/src/RecorderHOG.cpp
Normal file
|
@ -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 <fstream>
|
||||
|
||||
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_<double>& 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_<double> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue