相关文章推荐
print ( frame_count ) video_cap.release ( ) # The value below are both the number of frames print ( '====>' ,len ( all_frames ))

也可以调用opencv内部计数器

import cv2
video_cap = cv2.VideoCapture('video1.mp4')
frame_count = 0
all_frames = []
NUM = video_cap.get(cv2.CAP_PROP_FRAME_COUNT)
print("test:",NUM)

c++ 代码

#include "stdafx.h"
#include <cv.h>  
#include <highgui.h>  
int main(int argc, char* argv[])
	IplImage *nFrames = NULL;
	CvCapture* pCapture = NULL;
	if( !(pCapture = cvCaptureFromAVI("video1.mp4")))
		fprintf(stderr, "Can not open camera.\n");
		return -1;
	int numFrames = (int) cvGetCaptureProperty(pCapture, CV_CAP_PROP_FRAME_COUNT);  
		printf("vedio's nums = %d",  numFrames);
	getchar();
	return 0;

2、计算帧率(FPS)

python代码

# 视频帧率
import cv2
if __name__ == '__main__':
    video = cv2.VideoCapture("video1.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()

摄像头帧率

import cv2
import time
if __name__ == '__main__' :
    # 启动默认相机
    video = cv2.VideoCapture(0);
    # 获取 OpenCV version
    (major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')
    # 对于 webcam 不能采用 get(CV_CAP_PROP_FPS) 方法 
    # 而是:
    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 capture
    num_frames = 120;
    print("Capturing {0} frames".format(num_frames))
    # Start time
    start = time.time()
    # Grab a few frames
    for i in xrange(0, num_frames):
        ret, frame = video.read()
    # End time
    end = time.time()
    # Time elapsed
    seconds = end - start
    print("Time taken : {0} seconds".format(seconds))
    # 计算FPS,alculate frames per second
    fps  = num_frames / seconds;
    print("Estimated frames per second : {0}".format(fps))
    # 释放 video
    video.release()

C++代码

#include "stdafx.h"
#include <cv.h>  
#include <highgui.h>  
int main(int argc, char* argv[])
	IplImage *nFrames = NULL;
	CvCapture* pCapture = NULL;
	if( !(pCapture = cvCaptureFromAVI("video1.mp4")))
		fprintf(stderr, "Can not open camera.\n");
		return -1;
	int numFrames = (int) cvGetCaptureProperty(pCapture, CV_CAP_PROP_FPS);  
		printf("vedio's nums = %d",  numFrames);
	getchar();
	return 0;

摄像头帧率

#include "opencv2/opencv.hpp"
#include <time.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
    // Start default camera
    VideoCapture 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 3
    // double fps = video.get(CAP_PROP_FPS);
    cout << "Frames per second using video.get(CV_CAP_PROP_FPS) : " << fps << endl;
    // Number of frames to capture
    int num_frames = 120;
    // Start and end times
    time_t start, end;
    // Variable for storing video frames
    Mat frame;
    cout << "Capturing " << num_frames << " frames" << endl ;
    // Start time
    time(&start);
    // Grab a few frames
    for(int i = 0; i < num_frames; i++)
        video >> frame;
    // End Time
    time(&end);
    // Time elapsed
    double seconds = difftime (end, start);
    cout << "Time taken : " << seconds << " seconds" << endl;
    // Calculate frames per second
    fps  = num_frames / seconds;
    cout << "Estimated frames per second : " << fps << endl;
    // Release video
    video.release();
    return 0;

参考文献:https://cloud.tencent.com/developer/article/1446281

2.1 在Qt中新建一个纯C++项目2.2 在项目*.pro文件中添加库文件2.3 添加头文件2.4 播放视频2.4.1 OpenCV播放人的眼睛在某一个时间点看见的是一张图片,当一秒内的图片数量达到24张时就可以欺骗视觉达到连续的效果,称之为。普通视频帧率为24/s,也有60/s,当然了帧率越高效果越好。而所说的1080P指的是每一即每一张图片大小为1920*1080像素,即小像素长度... opencv Python计算视频摄像头帧率FPS的两种方法文章目录:一、方法一:利用时间差二、方法二:利用 计算帧率,一方面能知道我们程序目前每秒钟能够处理多少,也是程序的处理效率,另一方面也决定我们的算法能否达到实时的效果 一、方法一:利用时间差 二、方法二:利用 https://blog.csdn.net/w5688414/article/details/78426153 这篇博客将介绍两种使用OpenCVPython计算视频文件中数的方法。 第一种方法超级快,它依靠OpenCV视频属性功能,能够(几乎)立即确定视频文件中的数。但是,此方法很容易出错,原因在于它依赖(安装的OpenCV +视频编解码器版本),甚至可能返回无意义的结果。 在这种情况下,需要使用第二种方法:手动计算视频中的总数。尽管速度极慢,但此方法具有100%准确的优点。 使用过程中如果偏向准确性,则使用方法2,如果偏向近似和速度,则使用方法1; 在OpenCV中,类videoccapture处理摄像头读取视频和抓取。通过使用videoccapture中的get(PROPERTY_NAME)方法,你可以找到很多关于你正在播放的视频文件的信息。 如何在OpenCV中找到一个摄像头/网络摄像头帧率? 在OpenCV中,查找连接的摄像头/网络摄像头帧率不是直接的。文档说get(CAP_PROP_FPS)或get(CV_CAP_PROP_FPS)给出每秒的数。这对视频文件是正确的,但对网络摄像头不是。对于网络摄像头和许多其他连接摄像头,你必须手动计. C++/Qt 使用OpenCV打开摄像头,旋转视频计算fps 设置摄像头参数 不要随意修改,同时也不一样会修改成功,需要根据实际摄像头的参数选择设置 /*设置摄像头参数 不要随意修改 capture.set(CV_CAP_PROP_FRAME_WIDTH, 1080);//宽度 capture.set(CV_CAP_PROP_FRAME_HEIGHT, 960);//高度 capture.set(CV_CAP_PROP_FPS, 30);//数 capture.s opencv的库有封装好的函数,可以直接调用进行运行时间的计算。需要注意自己选择的起始位置和结束位置,运行时间(帧率)是根据起始位与结束位进行计算的。 代码具体如下: double t = (double)cv::getTickCount();//开始计时 t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();//结束计时 自从我在C++项目中从OpenCV 3.x改成4.x(从源码编译)后,我遇到了一些麻烦。我在一个小例子中复制了这种行为,这个例子只是打开一个网络摄像头并记录5秒钟。在3.x中,我可以在全高清下将摄像头帧率设置为30,但在4.x中,同样的代码只是忽略了 camera.set(cv::CAP_PROP_FPS,30) 并将其设置为5,而不是。如果我使用720p,fps被设置为10。也许这段代码与这里... 原文:OpenCV - 计算相机和视频速率FPS[译] - AIUAI 原文:How to find frame rate or frames per second (fps) in OpenCV ( Python / C++ ) ? - 2015.11.12 OpenCV 库中的 VideoCapture 类主要处理视频读取以及从连接的相机中获取图像. 基于VideoCapture 中...
 
推荐文章