如何使用 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.