How to count the total number of frames in OpenCV using C++?

We will learn how to calculate the total number of frames in OpenCV. Using OpenCV, it is elementary to count and show the total number of frames of a video. However, you have to store one thing in mind that we cannot count the total number of real-time video frames. Because a real-time video does not have a specific number of frames.

The following program counts the number of total frames and shows it in the console window.

Example

#include
#include
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 

As the output, we will get an integer value.

Output

Updated on: 2021-03-10T08:34:48+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements