mirror of
https://gitcode.com/gh_mirrors/ope/OpenFace.git
synced 2026-05-18 13:18:11 +00:00
Adding a dedicated FPS tracker.
This commit is contained in:
@@ -71,7 +71,7 @@ void CreateDirectory(std::string output_path)
|
||||
}
|
||||
|
||||
|
||||
RecorderOpenFace::RecorderOpenFace(const std::string in_filename, RecorderOpenFaceParameters parameters, std::vector<std::string> arguments):video_writer(), params(parameters)
|
||||
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
|
||||
@@ -150,7 +150,14 @@ RecorderOpenFace::RecorderOpenFace(const std::string in_filename, RecorderOpenFa
|
||||
if (params.outputTrackedVideo())
|
||||
{
|
||||
this->video_filename = (path(record_root) / path(filename).replace_extension(".avi")).string();
|
||||
metadata_file << "Output video:" << this->video_filename << endl;
|
||||
if(parameters.isSequence())
|
||||
{
|
||||
metadata_file << "Output video:" << this->video_filename << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
metadata_file << "Output image:" << this->video_filename << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare image recording
|
||||
|
||||
@@ -246,6 +246,12 @@ bool SequenceCapture::OpenVideoFile(std::string video_file, float fx, float fy,
|
||||
|
||||
capture.open(video_file);
|
||||
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout << "Failed to open the video file at location: " << video_file << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
this->fps = capture.get(CV_CAP_PROP_FPS);
|
||||
|
||||
// Check if fps is nan or less than 0
|
||||
@@ -263,12 +269,6 @@ bool SequenceCapture::OpenVideoFile(std::string video_file, float fx, float fy,
|
||||
|
||||
vid_length = (int)capture.get(CV_CAP_PROP_FRAME_COUNT);
|
||||
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout << "Failed to open the video file at location: " << video_file << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
SetCameraIntrinsics(fx, fy, cx, cy);
|
||||
|
||||
this->name = boost::filesystem::path(video_file).filename().replace_extension("").string();
|
||||
|
||||
@@ -44,6 +44,39 @@
|
||||
namespace Utilities
|
||||
{
|
||||
|
||||
FpsTracker::FpsTracker()
|
||||
{
|
||||
// Keep two seconds of history
|
||||
history_length = 2;
|
||||
}
|
||||
|
||||
void FpsTracker::AddFrame()
|
||||
{
|
||||
double current_time = cv::getTickCount() / cv::getTickFrequency();
|
||||
frame_times.push(current_time);
|
||||
DiscardOldFrames();
|
||||
}
|
||||
|
||||
double FpsTracker::GetFPS()
|
||||
{
|
||||
DiscardOldFrames();
|
||||
|
||||
if (frame_times.size() == 0)
|
||||
return 0;
|
||||
|
||||
double current_time = cv::getTickCount() / cv::getTickFrequency();
|
||||
|
||||
return ((double)frame_times.size()) / (current_time - frame_times.front());
|
||||
}
|
||||
|
||||
void FpsTracker::DiscardOldFrames()
|
||||
{
|
||||
double current_time = cv::getTickCount() / cv::getTickFrequency();
|
||||
// Remove old history
|
||||
while (frame_times.size() > 0 && (current_time - frame_times.front()) > history_length)
|
||||
frame_times.pop();
|
||||
}
|
||||
|
||||
void DrawBox(cv::Mat image, cv::Vec6d pose, cv::Scalar color, int thickness, float fx, float fy, float cx, float cy)
|
||||
{
|
||||
auto edge_lines = CalculateBox(pose, fx, fy, cx, cy);
|
||||
|
||||
@@ -232,6 +232,16 @@ void Visualizer::SetObservationGaze(const cv::Point3f& gaze_direction0, const cv
|
||||
}
|
||||
}
|
||||
|
||||
void Visualizer::SetFps(double fps)
|
||||
{
|
||||
// Write out the framerate on the image before displaying it
|
||||
char fpsC[255];
|
||||
std::sprintf(fpsC, "%d", (int)fps);
|
||||
std::string fpsSt("FPS:");
|
||||
fpsSt += fpsC;
|
||||
cv::putText(captured_image, fpsSt, cv::Point(10, 20), CV_FONT_HERSHEY_SIMPLEX, 0.5, CV_RGB(255, 0, 0), 1, CV_AA);
|
||||
}
|
||||
|
||||
void Visualizer::ShowObservation()
|
||||
{
|
||||
if (vis_track)
|
||||
|
||||
Reference in New Issue
Block a user