mirror of
https://gitcode.com/gh_mirrors/ope/OpenFace.git
synced 2026-05-20 22:28:03 +00:00
Separating threading on unix and windows systems.
This commit is contained in:
@@ -215,7 +215,6 @@ void RecorderOpenFace::PrepareRecording(const std::string& in_filename)
|
||||
}
|
||||
|
||||
this->frame_number = 0;
|
||||
closed = false;
|
||||
}
|
||||
|
||||
RecorderOpenFace::RecorderOpenFace(const std::string in_filename, const RecorderOpenFaceParameters& parameters, std::vector<std::string>& arguments):video_writer(), params(parameters)
|
||||
@@ -278,7 +277,7 @@ RecorderOpenFace::RecorderOpenFace(const std::string in_filename, const Recorder
|
||||
|
||||
}
|
||||
|
||||
RecorderOpenFace::RecorderOpenFace(const std::string in_filename, const RecorderOpenFaceParameters& parameters, std::string output_directory):video_writer(), params(parameters), closed(false)
|
||||
RecorderOpenFace::RecorderOpenFace(const std::string in_filename, const RecorderOpenFaceParameters& parameters, std::string output_directory):video_writer(), params(parameters)
|
||||
{
|
||||
// From the filename, strip out the name without directory and extension
|
||||
if (boost::filesystem::is_directory(in_filename))
|
||||
@@ -374,7 +373,13 @@ void RecorderOpenFace::WriteObservation()
|
||||
aligned_face_queue.set_capacity(capacity);
|
||||
|
||||
// Start the alignment output thread
|
||||
#ifdef _WIN32
|
||||
// For keeping track of tasks
|
||||
writing_threads.run([&] {AlignedImageWritingTask(&aligned_face_queue); });
|
||||
#else
|
||||
// Start the alignment output thread
|
||||
aligned_writing_thread = std::thread(&AlignedImageWritingTask, &aligned_face_queue);
|
||||
#endif
|
||||
}
|
||||
|
||||
char name[100];
|
||||
@@ -406,12 +411,9 @@ void RecorderOpenFace::WriteObservation()
|
||||
|
||||
void RecorderOpenFace::WriteObservationTracked()
|
||||
{
|
||||
cout << "WriteObservationTracked called" << endl;
|
||||
|
||||
if (params.outputTracked())
|
||||
{
|
||||
cout << "Track should be output" << endl;
|
||||
|
||||
// To support both video and image input
|
||||
if ((!params.isSequence() && frame_number == 0) || (params.isSequence() && frame_number == 1))
|
||||
{
|
||||
@@ -439,8 +441,13 @@ void RecorderOpenFace::WriteObservationTracked()
|
||||
}
|
||||
|
||||
// Start the video and tracked image writing thread
|
||||
cout << "About to create a writing thread" << endl;
|
||||
#ifdef _WIN32
|
||||
// For keeping track of tasks
|
||||
writing_threads.run([&] {VideoWritingTask(&vis_to_out_queue, params.isSequence(), &video_writer); });
|
||||
#else
|
||||
video_writing_thread = std::thread(&VideoWritingTask, &vis_to_out_queue, params.isSequence(), &video_writer);
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -528,22 +535,25 @@ RecorderOpenFace::~RecorderOpenFace()
|
||||
|
||||
void RecorderOpenFace::Close()
|
||||
{
|
||||
if(!closed)
|
||||
{
|
||||
// Insert terminating frames to the queues
|
||||
vis_to_out_queue.push(std::pair<string, cv::Mat>("", cv::Mat()));
|
||||
aligned_face_queue.push(std::pair<string, cv::Mat>("", cv::Mat()));
|
||||
|
||||
// Insert terminating frames to the queues
|
||||
vis_to_out_queue.push(std::pair<string, cv::Mat>("", cv::Mat()));
|
||||
aligned_face_queue.push(std::pair<string, cv::Mat>("", cv::Mat()));
|
||||
// Make sure the recording threads complete
|
||||
#ifdef _WIN32
|
||||
writing_threads.wait();
|
||||
#else
|
||||
if (video_writing_thread.joinable())
|
||||
video_writing_thread.join();
|
||||
if (aligned_writing_thread.joinable())
|
||||
aligned_writing_thread.join();
|
||||
#endif
|
||||
|
||||
// Make sure the recording threads complete
|
||||
writing_threads.wait();
|
||||
|
||||
hog_recorder.Close();
|
||||
csv_recorder.Close();
|
||||
video_writer.release();
|
||||
metadata_file.close();
|
||||
closed = true;
|
||||
}
|
||||
hog_recorder.Close();
|
||||
csv_recorder.Close();
|
||||
video_writer.release();
|
||||
metadata_file.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user