在OpenCV中,类videoccapture处理摄像头读取视频和抓取帧。通过使用videoccapture中的get(PROPERTY_NAME)方法,你可以找到很多关于你正在播放的视频文件的信息。

如何在OpenCV中找到一个摄像头/网络摄像头的帧率?

在OpenCV中,查找连接的摄像头/网络摄像头的帧率不是直接的。文档说get(CAP_PROP_FPS)get(CV_CAP_PROP_FPS)给出每秒的帧数。这对视频文件是正确的,但对网络摄像头不是。对于网络摄像头和许多其他连接摄像头,你必须手动计算每秒的帧数。您可以从视频中读取一定数量的帧,并查看计算每秒帧需要花费多少时间。

Python

#!/usr/bin/env pythonimport cv2
import timeif __name__ == '__main__' :# Start default cameravideo = cv2.VideoCapture(0);# Find OpenCV version(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')# With webcam get(CV_CAP_PROP_FPS) does not work.# Let's see for ourselves.if int(major_ver)  < 3 :fps = video.get(cv2.cv.CV_CAP_PROP_FPS)print("Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".format(fps))else :fps = video.get(cv2.CAP_PROP_FPS)print("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps))# Number of frames to capturenum_frames = 120;print("Capturing {0} frames".format(num_frames))# Start timestart = time.time()# Grab a few framesfor i in range(0, num_frames) :ret, frame = video.read()# End timeend = time.time()# Time elapsedseconds = end - startprint ("Time taken : {0} seconds".format(seconds))# Calculate frames per secondfps  = num_frames / secondsprint("Estimated frames per second : {0}".format(fps))# Release videovideo.release()

C++

#include "opencv2/opencv.hpp"
#include <time.h>using namespace cv;
using namespace std;int main(int argc, char** argv)
{// Start default cameraVideoCapture video(0);// With webcam get(CV_CAP_PROP_FPS) does not work.// Let's see for ourselves.// double fps = video.get(CV_CAP_PROP_FPS);// If you do not care about backward compatibility// You can use the following instead for OpenCV 3double fps = video.get(CAP_PROP_FPS);cout << "Frames per second using video.get(CAP_PROP_FPS) : " << fps << endl;// Number of frames to captureint num_frames = 120;// Start and end timestime_t start, end;// Variable for storing video framesMat frame;cout << "Capturing " << num_frames << " frames" << endl ;// Start timetime(&start);// Grab a few framesfor(int i = 0; i < num_frames; i++){video >> frame;}// End Timetime(&end);// Time elapseddouble seconds = difftime (end, start);cout << "Time taken : " << seconds << " seconds" << endl;// Calculate frames per secondfps  = num_frames / seconds;cout << "Estimated frames per second : " << fps << endl;// Release videovideo.release();return 0;
}

如何在OpenCV中找到视频的帧率?

如果你正在读取一个视频文件,你可以简单地使用get方法来获得每秒的帧数。下面的例子展示了使用方法
Python

import cv2
if __name__ == '__main__' :video = cv2.VideoCapture("video.mp4");# Find OpenCV version(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')if int(major_ver)  < 3 :fps = video.get(cv2.cv.CV_CAP_PROP_FPS)print ("Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".format(fps))else :fps = video.get(cv2.CAP_PROP_FPS)print ("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps))video.release()

C++

#include "opencv2/opencv.hpp"using namespace cv;
using namespace std;int main(int argc, char** argv)
{// Open video fileVideoCapture video("video.mp4");// double fps = video.get(CV_CAP_PROP_FPS);// For OpenCV 3, you can also use the followingdouble fps = video.get(CAP_PROP_FPS);cout << "Frames per second using video.get(CAP_PROP_FPS) : " << fps << endl;video.release();return 0; }

OpenCV 计算fps(frames per second-fps)相关推荐

  1. OpenCV - 计算相机和视频的帧速率FPS

    原文:OpenCV - 计算相机和视频的帧速率FPS[译] - AIUAI 原文:How to find frame rate or frames per second (fps) in OpenCV ...

  2. opencv计算视频和摄像头的帧数及帧率(FPS)

    1.计算总帧数 python代码 import cv2video_cap = cv2.VideoCapture('video1.mp4')frame_count = 0 all_frames = [] ...

  3. 使用Python,OpenCV线程化方式提高视频FPS(每秒帧数)

    使用Python,OpenCV处理视频流时,获得更高FPS(Frams Per Second)的"秘密"是将I / O(即从摄像机传感器读取帧)交给线程去处理: 读取帧 I/O是阻 ...

  4. 为什么OpenCV计算的帧率是错误的?

     点击上方"LiveVideoStack"关注我们 ▲扫描图中二维码或点击阅读原文▲ 了解音视频技术大会更多信息 作者:王伟 编辑:Alex   引 言   我们有一个平台来周期性 ...

  5. 使用Python、OpenCV计算轮廓的中心

    1. 使用Python.OpenCV计算轮廓的中心并标记 2. 使用Python.OpenCV检测轮廓的形状并标记 3. 使用颜色通道统计信息来标记形状的实际颜色并标记 本博客的目标:(1)检测图像中 ...

  6. 使用Python,OpenCV计算图像直方图(cv2.calcHist)

    使用Python,OpenCV计算图像直方图(cv2.calcHist 1. 效果图 2. 原理 2.1 什么是图像直方图? 2.2 计算直方图 2.3 可视化蒙版区域 3. 源码 参考 这篇博客将介 ...

  7. OpenCV计算时刻calculate moments的实例(附完整代码)

    OpenCV计算时刻calculate moments的实例 OpenCV计算时刻calculate moments的实例 OpenCV计算时刻calculate moments的实例 #includ ...

  8. OpenCV计算均值和方差

    OpenCV 计算均值和标准方差: 计算矩阵均值,src是1-4个通道,返回Scalar,保存了1-4通道的均值,结果值位double,Scalar[0],Scalar[1],Scalar[2],Sc ...

  9. opencv计算指定区域黑白像素占比

    如下在我们拿到二值化的图像之后,想要计算红框内黑白像素在该区域的占比.注意单通道的图像无法出现黑白以外的颜色. 上图为我们拿到的红色区域二值化之后的图像.我们通过遍历该区域所有像素来判断.若值为255 ...

最新文章

  1. 时间复杂度O(n),空间复杂度O(1)的排序
  2. Ubuntu tensorflow自定义GPU版本op节点
  3. fail2ban安全设置
  4. 移动端浏览器body的overflow:hidden并没有什么作用
  5. python连等号_Python比较2列表和2元组用等号
  6. SAP License:SAP FI/CO 基本概念
  7. js、jQuery实现文字上下无缝轮播、滚动效果
  8. BG.Hive - part3
  9. Java学习(21-25天, 树与二叉树)
  10. QT应用编程: 开发TCP网络调试助手
  11. Startup.s文件
  12. nn.Sigmoid torch
  13. 音乐播放器制作 (HTML + CSS + JavaScript)
  14. 树莓派 安装Transmission并自动挂载移动硬盘
  15. 合同和协议的区别_你签的是合同还是协议?他们的法律效力有区别吗?
  16. 如何在知网下载期刊封面、扉页、目录?
  17. 推荐:2010年度十大杰出IT博客
  18. NoteExpress使用中的一些问题
  19. 红包雨中:Redis 和 Lua 的邂逅
  20. OCH1661全极超低功耗1.9ua霍尔开关

热门文章

  1. Codeforces 821B Okabe and Banana Trees 题解
  2. matlab科学计算软件,数据分析软件 Matlab 科学计算软件 科软网——专业正版软件供应商...
  3. java jacob更新目录,jacob更新word目录
  4. 数据分析之Hadoop详解
  5. 计算机上u盘变成快捷方式,打开u盘文件变成快捷方式怎么办?
  6. powerbi服务器打开文件慢,Power BI 优化指南
  7. 智能网联汽车信息安全研究报告
  8. LightTools 坐标系定义及旋转方向定义
  9. 棋盘密码(Polybius)
  10. 产品读书《六顶思考帽》