在處理圖像數據時,常常須要測算性能數據,其中計算耗時是一個關鍵指標。此處,介紹如何利用opencv來進行計時。具體見代碼註釋ios
#include<opencv2/core/core.hpp> #include<opencv2/highgui/highgui.hpp> #include<opencv2/imgproc/imgproc.hpp> #include<iostream> using namespace std; using namespace cv; int main() { //getTickCount獲取CPU自某個事件以來走過的時鐘週期數,例如開機 double start = static_cast<double>(getTickCount()); for (int i = 0; i < 1e9; i++) for (int j = 0; j < 1e9; j++); double end = static_cast<double>(getTickCount()); // getTickFrequency 獲取CPU一秒鐘走過的時鐘週期數 double run_time = (end - start) / getTickFrequency(); cout << "run_time=" << run_time << " seconds" << endl; system("Pause"); }
結果以下:性能