- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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<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; }
As the output, we will get an integer value.
Output
Advertisements