如何使用 C++ 在 OpenCV 中计算总帧数?


我们将学习如何在 OpenCV 中计算总帧数。利用 OpenCV,你可以轻而易举地统计并显示视频的总帧数。但是,你必须牢记一点,我们无法统计实时视频的总帧数。因为实时视频没有特定数目的帧。

以下程序统计总帧数并将其显示在控制台窗口中。

示例

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main() {
   int frame_Number;//Declaring an integervariable to store the number of total frames//
   VideoCapture cap("video.mp4");//Declaring an object to capture stream of frames from default camera//
   frame_Number = cap.get(CAP_PROP_FRAME_COUNT);//Getting the total number of frames//
   cout << "Total Number of frames are:" << frame_Number << endl;//Showing the number in console window//
   system("pause");//Pausing the system to see the result//
   cap.release();//Releasing the buffer memory//
   return 0;
}

输出将是一个整数。

输出

更新日期:2021-03-10

1K+ 浏览量

开启您的职业生涯

通过完成课程获得认证

开始学习
广告
© . All rights reserved.