เราจะเรียนรู้วิธีคำนวณจำนวนเฟรมทั้งหมดใน 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;
} จากผลลัพธ์ เราจะได้ค่าจำนวนเต็ม
ผลลัพธ์
