Reputation: 407
For a while I've been trying to calculate the FPS of a video stream coming through my OpenCV program, and was wondering if there's any way to do it using Chrono rather than time.h or any other API that measures with CPU ticks. After a good amount of experimenting and researching, I haven't found a simple solution using Chrono.
Is there a Keep-It-Simple-Stupid solution to calculating your FPS with Chrono? Or is working with CPU ticks unavoidable?
Upvotes: 1
Views: 1325
Reputation: 1444
You got the method
VideoCapture::get(CV_CAP_PROP_FPS) Is it not working?
As far as I know a chrono approach would still use CPU Ticks. Supposing your loop is something like
cv::Mat frame; cv::VideoCapture cap(video_path);
while (cap.read(frame)) {
/* .. */
}
You could try something like
#include <chrono>
using namespace std::chrono;
time_point<steady_clock> begin_time = steady_clock::now(), new_time;
cv::Mat frame;
cv::VideoCapture cap(video_path);
size_t frame_counter = 0;
while (cap.read(frame)) {
/* do stuff.. */
frame_counter++;
new_time = steady_clock::now();
if (new_time - begin_time >= seconds{1}) {
/* Do something with the fps in frame_counter */
frame_counter = 0;
begin_time = new_time;
}
}
Upvotes: 1