ภาพรวม
สาธิตการอ่าน Total Frame Count ของไฟล์วิดีโอ โดยใช้ CAP_PROP_FRAME_COUNT
โค้ดตัวอย่าง C++
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
int frame_Number;
VideoCapture cap("video.mp4");
frame_Number = cap.get(CAP_PROP_FRAME_COUNT);
cout << "Total Number of frames are: " << frame_Number << endl;
system("pause");
cap.release();
return 0;
}
คำอธิบาย
CAP_PROP_FRAME_COUNT: จำนวนเฟรมทั้งหมดในไฟล์ (double → int)- ใช้ได้กับไฟล์วิดีโอเท่านั้น (Live camera ไม่มีจำนวนเฟรมจำกัด)
- อ่านค่าได้ทันทีหลัง
VideoCaptureเปิดไฟล์สำเร็จ
ผลลัพธ์
แสดงจำนวนเฟรมทั้งหมดใน Console (ตัวอย่าง: "Total Number of frames are: 1250")
