OpenCV测试摄像头帧率
生活随笔
收集整理的這篇文章主要介紹了
OpenCV测试摄像头帧率
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <stdlib.h>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
int main(int argc, const char** argv)
{cv::Mat frame;// 可從攝像頭輸入視頻流或直接播放視頻文件cv::VideoCapture capture(0);
// cv::VideoCapture capture("vedio1.avi");double fps;char string[10]; // 用于存放幀率的字符串cv::namedWindow("Camera FPS");double t = 0;while (1){t = (double)cv::getTickCount();if (cv::waitKey(1) == 1){ break; }if (capture.isOpened()){capture >> frame;// getTickcount函數:返回從操作系統啟動到當前所經過的毫秒數// getTickFrequency函數:返回每秒的計時周期數// t為該處代碼執行所耗的時間,單位為秒,fps為其倒數t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();fps = 1.0 / t;sprintf(string, "%.2f", fps); // 幀率保留兩位小數std::string fpsString("FPS:");fpsString += string; // 在"FPS:"后加入幀率數值字符串printf("fps: %.2f width:%d height:%d fps:%.2f\n", fps,frame.cols,frame.rows, capture.get(CV_CAP_PROP_FPS));// 將幀率信息寫在輸出幀上cv::putText(frame, // 圖像矩陣fpsString, // string型文字內容cv::Point(5, 20), // 文字坐標,以左下角為原點cv::FONT_HERSHEY_SIMPLEX, // 字體類型0.5, // 字體大小cv::Scalar(0, 0, 0)); // 字體顏色cv::imshow("Camera FPS", frame);}else{std::cout << "No Camera Input!" << std::endl;break;}}
}
總結
以上是生活随笔為你收集整理的OpenCV测试摄像头帧率的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C/C++中的声明与定义
- 下一篇: struts2学习笔记之十一:strut