Skip to content
Snippets Groups Projects
Commit b42a08f3 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Allow max framerate control of input

parent f37a897d
No related branches found
No related tags found
No related merge requests found
Pipeline #9881 passed
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"flip": false, "flip": false,
"nostereo": false, "nostereo": false,
"scale": 1.0, "scale": 1.0,
"flip_vert": false "flip_vert": false,
"max_fps": 25
}, },
"calibrate": false, "calibrate": false,
"calibration": { "calibration": {
......
...@@ -28,6 +28,7 @@ class LocalSource { ...@@ -28,6 +28,7 @@ class LocalSource {
private: private:
double timestamp_; double timestamp_;
double tps_;
bool stereo_; bool stereo_;
//float fps_; //float fps_;
bool flip_; bool flip_;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <string> #include <string>
#include <chrono> #include <chrono>
#include <thread>
#include <ftl/local.hpp> #include <ftl/local.hpp>
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
...@@ -19,6 +20,8 @@ using std::string; ...@@ -19,6 +20,8 @@ using std::string;
using std::chrono::duration_cast; using std::chrono::duration_cast;
using std::chrono::duration; using std::chrono::duration;
using std::chrono::high_resolution_clock; using std::chrono::high_resolution_clock;
using std::chrono::milliseconds;
using std::this_thread::sleep_for;
LocalSource::LocalSource(nlohmann::json &config) LocalSource::LocalSource(nlohmann::json &config)
: timestamp_(0.0), : timestamp_(0.0),
...@@ -51,6 +54,8 @@ LocalSource::LocalSource(nlohmann::json &config) ...@@ -51,6 +54,8 @@ LocalSource::LocalSource(nlohmann::json &config)
} else { } else {
stereo_ = true; stereo_ = true;
} }
tps_ = 1.0 / (double)config["max_fps"];
} }
LocalSource::LocalSource(const string &vid, nlohmann::json &config) LocalSource::LocalSource(const string &vid, nlohmann::json &config)
...@@ -89,6 +94,8 @@ LocalSource::LocalSource(const string &vid, nlohmann::json &config) ...@@ -89,6 +94,8 @@ LocalSource::LocalSource(const string &vid, nlohmann::json &config)
LOG(INFO) << "Video size : " << frame.cols << "x" << frame.rows; LOG(INFO) << "Video size : " << frame.cols << "x" << frame.rows;
stereo_ = false; stereo_ = false;
} }
tps_ = 1.0 / (double)config["max_fps"];
} }
bool LocalSource::left(cv::Mat &l) { bool LocalSource::left(cv::Mat &l) {
...@@ -177,8 +184,15 @@ bool LocalSource::get(cv::Mat &l, cv::Mat &r) { ...@@ -177,8 +184,15 @@ bool LocalSource::get(cv::Mat &l, cv::Mat &r) {
} }
// Record timestamp // Record timestamp
timestamp_ = duration_cast<duration<double>>( double timestamp = duration_cast<duration<double>>(
high_resolution_clock::now().time_since_epoch()).count(); high_resolution_clock::now().time_since_epoch()).count();
// Limit max framerate
if (timestamp - timestamp_ < tps_) {
sleep_for(milliseconds((int)std::round((tps_ - (timestamp - timestamp_))*1000)));
}
timestamp_ = timestamp;
if (camera_b_ || !stereo_) { if (camera_b_ || !stereo_) {
if (!camera_a_->retrieve(l)) { if (!camera_a_->retrieve(l)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment