ภาพรวม
สาธิตการอ่านค่า FPS (Frames Per Second) ของไฟล์วิดีโอ โดยใช้ Method get(CAP_PROP_FPS) ของคลาส VideoCapture
โค้ดตัวอย่าง C++
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
int FPS;
VideoCapture cap("video1.mp4");
FPS = cap.get(CAP_PROP_FPS);
cout << "Total Number of frames are: " << FPS << endl;
system("pause");
cap.release();
return 0;
}
คำอธิบาย
CAP_PROP_FPS: Property ID สำหรับ FPS (คืนค่า double แปลงเป็น int)cap.get(propId): อ่าน Property ต่างๆ ของวิดีโอ- ทำงานได้กับไฟล์วิดีโอเท่านั้น (กล้อง Real-time ไม่มี FPS คงที่)
cap.release(): ปล่อย Buffer หน่วยความจำ
Property อื่นๆ ที่น่าสนใจ
CAP_PROP_FRAME_COUNT- จำนวนเฟรมทั้งหมดCAP_PROP_FRAME_WIDTH- ความกว้างเฟรมCAP_PROP_FRAME_HEIGHT- ความสูงเฟรมCAP_PROP_POS_MSEC- เวลาปัจจุบัน (ms)CAP_PROP_POS_FRAMES- เฟรมปัจจุบัน
ผลลัพธ์
แสดงค่า FPS ใน Console (ตัวอย่าง: "Total Number of frames are: 30")
