Giới thiệu
Dùng VideoCapture::get(CAP_PROP_FRAME_COUNT) lấy tổng số frame của file video. Lưu ý: Không áp dụng cho camera real-time (vô hạn frame).
Chương trình đếm tổng frame
#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 << "Tổng số khung hình: " << frame_Number << endl;
system("pause");
cap.release();
return 0;
}
Kết quả
Console in ra tổng số frame (ví dụ: 4500).