Working on the recorder interop
This commit is contained in:
parent
05efaf730c
commit
deec0528cb
7 changed files with 184 additions and 74 deletions
|
@ -185,6 +185,7 @@
|
|||
<ClInclude Include="LandmarkDetectorInterop.h" />
|
||||
<ClInclude Include="FaceDetectorInterop.h" />
|
||||
<ClInclude Include="OpenCVWrappers.h" />
|
||||
<ClInclude Include="RecorderInterop.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\3rdParty\dlib\dlib.vcxproj">
|
||||
|
|
|
@ -44,5 +44,8 @@
|
|||
<ClInclude Include="FaceDetectorInterop.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="RecorderInterop.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,6 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2017, Carnegie Mellon University and University of Cambridge,
|
||||
// all rights reserved.
|
||||
// Copyright (C) 2017, Tadas Baltrusaitis.
|
||||
//
|
||||
// ACADEMIC OR NON-PROFIT ORGANIZATION NONCOMMERCIAL RESEARCH USE ONLY
|
||||
//
|
||||
|
@ -44,7 +43,49 @@
|
|||
|
||||
#pragma managed
|
||||
|
||||
namespace Utilities {
|
||||
namespace UtilitiesOF {
|
||||
|
||||
public ref class RecorderOpenFaceParameters
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
Utilities::RecorderOpenFaceParameters *m_params;
|
||||
|
||||
public:
|
||||
RecorderOpenFaceParameters(bool sequence, bool is_from_webcam, bool output_2D_landmarks, bool output_3D_landmarks,
|
||||
bool output_model_params, bool output_pose, bool output_AUs, bool output_gaze, bool output_hog, bool output_tracked,
|
||||
bool output_aligned_faces, float fx, float fy, float cx, float cy, double fps_vid_out)
|
||||
{
|
||||
|
||||
m_params = new Utilities::RecorderOpenFaceParameters(sequence, is_from_webcam,
|
||||
output_2D_landmarks, output_3D_landmarks, output_model_params, output_pose, output_AUs,
|
||||
output_gaze, output_hog, output_tracked, output_aligned_faces, fx, fy, cx, cy, fps_vid_out);
|
||||
|
||||
}
|
||||
|
||||
Utilities::RecorderOpenFaceParameters * GetParams()
|
||||
{
|
||||
return m_params;
|
||||
}
|
||||
|
||||
!RecorderOpenFaceParameters()
|
||||
{
|
||||
// Automatically closes capture object before freeing memory.
|
||||
if (m_params != nullptr)
|
||||
{
|
||||
delete m_params;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Destructor. Called on explicit Dispose() only.
|
||||
~RecorderOpenFaceParameters()
|
||||
{
|
||||
this->!RecorderOpenFaceParameters();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public ref class RecorderOpenFace
|
||||
{
|
||||
|
@ -56,8 +97,9 @@ namespace Utilities {
|
|||
public:
|
||||
|
||||
// Can provide a directory, or a list of files
|
||||
RecorderOpenFace()
|
||||
RecorderOpenFace(const std::string in_filename, UtilitiesOF::RecorderOpenFaceParameters^ parameters, std::string output_directory, std::string output_name)
|
||||
{
|
||||
m_recorder = new Utilities::RecorderOpenFace(in_filename, parameters->GetParams(), output_directory, output_name);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ namespace Utilities
|
|||
|
||||
// The constructor for the recorder, need to specify if we are recording a sequence or not, in_filename should be just the name and not contain extensions
|
||||
RecorderOpenFace(const std::string in_filename, RecorderOpenFaceParameters parameters, std::vector<std::string>& arguments);
|
||||
RecorderOpenFace(const std::string in_filename, RecorderOpenFaceParameters parameters, std::string output_directory, std::string output_name);
|
||||
|
||||
~RecorderOpenFace();
|
||||
|
||||
|
@ -104,6 +105,8 @@ namespace Utilities
|
|||
RecorderOpenFace(const RecorderOpenFace&& other);
|
||||
RecorderOpenFace(const RecorderOpenFace& other);
|
||||
|
||||
void PrepareRecording(std::string in_filename);
|
||||
|
||||
// Keeping track of what to output and how to output it
|
||||
const RecorderOpenFaceParameters params;
|
||||
|
||||
|
|
|
@ -54,6 +54,9 @@ namespace Utilities
|
|||
|
||||
// Constructors
|
||||
RecorderOpenFaceParameters(std::vector<std::string> &arguments, bool sequence, bool is_from_webcam, float fx = -1, float fy = -1, float cx = -1, float cy = -1, double fps_vid_out = 30);
|
||||
RecorderOpenFaceParameters(bool sequence, bool is_from_webcam, bool output_2D_landmarks, bool output_3D_landmarks,
|
||||
bool output_model_params, bool output_pose, bool output_AUs, bool output_gaze, bool output_hog, bool output_tracked,
|
||||
bool output_aligned_faces, float fx = -1, float fy = -1, float cx = -1, float cy = -1, double fps_vid_out = 30);
|
||||
|
||||
bool isSequence() const { return is_sequence; }
|
||||
bool isFromWebcam() const { return is_from_webcam; }
|
||||
|
|
|
@ -71,62 +71,8 @@ void CreateDirectory(std::string output_path)
|
|||
}
|
||||
}
|
||||
|
||||
RecorderOpenFace::RecorderOpenFace(const std::string in_filename, RecorderOpenFaceParameters parameters, std::vector<std::string>& arguments):video_writer(), params(parameters)
|
||||
void RecorderOpenFace::PrepareRecording(std::string in_filename)
|
||||
{
|
||||
|
||||
// From the filename, strip out the name without directory and extension
|
||||
if (boost::filesystem::is_directory(in_filename))
|
||||
{
|
||||
filename = boost::filesystem::canonical(boost::filesystem::path(in_filename)).filename().string();
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = boost::filesystem::path(in_filename).filename().replace_extension("").string();
|
||||
}
|
||||
|
||||
// Consuming the input arguments
|
||||
bool* valid = new bool[arguments.size()];
|
||||
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
valid[i] = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
if (arguments[i].compare("-out_dir") == 0)
|
||||
{
|
||||
record_root = arguments[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
// Determine output directory
|
||||
bool output_found = false;
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
if (!output_found && arguments[i].compare("-of") == 0)
|
||||
{
|
||||
record_root = (boost::filesystem::path(record_root) / boost::filesystem::path(arguments[i + 1])).remove_filename().string();
|
||||
filename = path(boost::filesystem::path(arguments[i + 1])).replace_extension("").filename().string();
|
||||
valid[i] = false;
|
||||
valid[i + 1] = false;
|
||||
i++;
|
||||
output_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If recording directory not set, record to default location
|
||||
if (record_root.empty())
|
||||
record_root = default_record_directory;
|
||||
|
||||
for (int i = (int)arguments.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (!valid[i])
|
||||
{
|
||||
arguments.erase(arguments.begin() + i);
|
||||
}
|
||||
}
|
||||
|
||||
// Construct the directories required for the output
|
||||
CreateDirectory(record_root);
|
||||
|
||||
|
@ -206,6 +152,88 @@ RecorderOpenFace::RecorderOpenFace(const std::string in_filename, RecorderOpenFa
|
|||
|
||||
}
|
||||
|
||||
RecorderOpenFace::RecorderOpenFace(const std::string in_filename, RecorderOpenFaceParameters parameters, std::vector<std::string>& arguments):video_writer(), params(parameters)
|
||||
{
|
||||
|
||||
// From the filename, strip out the name without directory and extension
|
||||
if (boost::filesystem::is_directory(in_filename))
|
||||
{
|
||||
filename = boost::filesystem::canonical(boost::filesystem::path(in_filename)).filename().string();
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = boost::filesystem::path(in_filename).filename().replace_extension("").string();
|
||||
}
|
||||
|
||||
// Consuming the input arguments
|
||||
bool* valid = new bool[arguments.size()];
|
||||
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
valid[i] = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
if (arguments[i].compare("-out_dir") == 0)
|
||||
{
|
||||
record_root = arguments[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
// Determine output directory
|
||||
bool output_found = false;
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
if (!output_found && arguments[i].compare("-of") == 0)
|
||||
{
|
||||
record_root = (boost::filesystem::path(record_root) / boost::filesystem::path(arguments[i + 1])).remove_filename().string();
|
||||
filename = path(boost::filesystem::path(arguments[i + 1])).replace_extension("").filename().string();
|
||||
valid[i] = false;
|
||||
valid[i + 1] = false;
|
||||
i++;
|
||||
output_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If recording directory not set, record to default location
|
||||
if (record_root.empty())
|
||||
record_root = default_record_directory;
|
||||
|
||||
for (int i = (int)arguments.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (!valid[i])
|
||||
{
|
||||
arguments.erase(arguments.begin() + i);
|
||||
}
|
||||
}
|
||||
|
||||
PrepareRecording();
|
||||
}
|
||||
|
||||
RecorderOpenFace::RecorderOpenFace(const std::string in_filename, RecorderOpenFaceParameters parameters, std::string output_directory, std::string output_name)
|
||||
{
|
||||
// From the filename, strip out the name without directory and extension
|
||||
if (boost::filesystem::is_directory(in_filename))
|
||||
{
|
||||
filename = boost::filesystem::canonical(boost::filesystem::path(in_filename)).filename().string();
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = boost::filesystem::path(in_filename).filename().replace_extension("").string();
|
||||
}
|
||||
|
||||
record_root = output_directory;
|
||||
filename = output_name;
|
||||
|
||||
// If recording directory not set, record to default location
|
||||
if (record_root.empty())
|
||||
record_root = default_record_directory;
|
||||
|
||||
PrepareRecording();
|
||||
}
|
||||
|
||||
|
||||
void RecorderOpenFace::SetObservationFaceAlign(const cv::Mat& aligned_face)
|
||||
{
|
||||
this->aligned_face = aligned_face;
|
||||
|
|
|
@ -40,8 +40,6 @@ using namespace Utilities;
|
|||
RecorderOpenFaceParameters::RecorderOpenFaceParameters(std::vector<std::string> &arguments, bool sequence, bool from_webcam, float fx, float fy, float cx, float cy, double fps_vid_out)
|
||||
{
|
||||
|
||||
string separator = string(1, boost::filesystem::path::preferred_separator);
|
||||
|
||||
this->is_sequence = sequence;
|
||||
this->is_from_webcam = from_webcam;
|
||||
this->fx = fx;
|
||||
|
@ -138,3 +136,35 @@ RecorderOpenFaceParameters::RecorderOpenFaceParameters(std::vector<std::string>
|
|||
|
||||
}
|
||||
|
||||
RecorderOpenFaceParameters::RecorderOpenFaceParameters(bool sequence, bool is_from_webcam, bool output_2D_landmarks, bool output_3D_landmarks,
|
||||
bool output_model_params, bool output_pose, bool output_AUs, bool output_gaze, bool output_hog, bool output_tracked,
|
||||
bool output_aligned_faces, float fx = -1, float fy = -1, float cx = -1, float cy = -1, double fps_vid_out = 30)
|
||||
{
|
||||
this->is_sequence = sequence;
|
||||
this->is_from_webcam = is_from_webcam;
|
||||
this->fx = fx;
|
||||
this->fy = fy;
|
||||
this->cx = cx;
|
||||
this->cy = cy;
|
||||
|
||||
if (fps_vid_out > 0)
|
||||
{
|
||||
this->fps_vid_out = fps_vid_out;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->fps_vid_out = 30; // If an illegal value for fps provided, default to 30
|
||||
}
|
||||
// Default output code
|
||||
this->output_codec = "DIVX";
|
||||
|
||||
this->output2DLandmarks = output_2D_landmarks;
|
||||
this->output3DLandmarks = output_3D_landmarks;
|
||||
this->outputPDMParams = output_model_params;
|
||||
this->outputPose = output_pose;
|
||||
this->outputAUs = output_AUs;
|
||||
this->outputGaze = output_gaze;
|
||||
this->outputHOG = output_hog;
|
||||
this->outputTracked = output_tracked;
|
||||
this->outputAlignedFaces = output_aligned_faces;
|
||||
}
|
Loading…
Reference in a new issue