[英]How to find framerate of video using c++ opencv 2.4.10?
實際上,我正在嘗試使用 C++ opencv 2.4.10 從視頻中檢測和跟蹤車輛。我這樣做了。現在,我想找到輸出視頻的幀率。我想知道是否有任何方法可以找出.任何人都可以向我推薦有關此的任何博客或教程嗎?
謝謝。
像這樣的事情可能會有所幫助。
#include <iostream>
#include <opencv2/opencv.hpp> //for opencv3
#include <opencv/cv.hpp> //for opencv2
int main(int argc, const char * argv[]) {
cv::VideoCapture video("video.mp4");
double fps = video.get(cv::CAP_PROP_FPS);
std::cout << "Frames per second : " << fps << std::endl;
video.release();
return 0;
}
您的代碼中必須有一個循環,您可以在其中進行所有視頻處理。
假設您有類似於此偽代碼的內容:
//code initialization
cv::VideoCapture cap("some-video-uri");
//video capture/processing loop
while (1)
{
//here we take the timestamp
auto start = std::chrono::system_clock::now();
//capture the frame
cap >> frame;
//do whatever frame processing you are doing...
do_frame_processing();
//measure timestamp again
auto end = std::chrono::system_clock::now();
//end - start is the time taken to process 1 frame, output it:
std::chrono::duration<double> diff = end-start;
std::cout << "Time to process last frame (seconds): " << diff.count()
<< " FPS: " << 1.0 / diff.count() << "\n";
}
就是這樣......考慮到以逐幀為基礎計算 FPS 可能會產生高度變化的結果。 您應該對幾幀的結果進行平均,以獲得更少變化的 FPS。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.