- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 get the position of the current frame in OpenCV using C++?
The current frame means that you are playing a video and the frame shown now is the current frame. It is also referred to as the active frame. In many application, you can require to get the number of the current frame.
The following program reads the position of the current frame and shows it in the console window.
Example
#include<opencv2/opencv.hpp>//OpenCV header to use VideoCapture class// #include<iostream> using namespace std; using namespace cv; int main() { Mat myImage;//Declaring a matrix to load the frames// namedWindow("Video Player");//Declaring the video to show the video// VideoCapture cap("video.mp4");//Declaring an object to load video from device// if(!cap.isOpened()){ //This section prompt an error message if no video stream is found// cout << "No video stream detected" << endl; system("pause"); return-1; } while (true){ //Taking an everlasting loop to show the video// cap >> myImage; int current_Frame;//Declaring an integer variable to store the position of the current frame// current_Frame = cap.get(CAP_PROP_POS_FRAMES);//Reading the position of current frame// if (myImage.empty()){ //Breaking the loop if no video frame is detected// break; } cout << "Current Frame Number:" << current_Frame << endl; imshow("Video Player", myImage);//Showing the video// char c = (char)waitKey(25);//Allowing 25 milliseconds frame processing time and initiating break condition// if (c == 27){ //If 'Esc' is entered break the loop// break; } } cap.release();//Releasing the buffer memory// return 0; }
This program will play the video and show the current frame's position in the console window.
Output
- Related Articles
- How to track the position of the face in OpenCV using C++?
- How to get the FPS value in OpenCV using C++?
- How to get the value of a specific pixel in OpenCV using C++?
- How to get the name of the current executable in C#?
- How to get the current time in millisecond using JavaScript?
- How to get the style of current selection in Text using FabricJS?
- How to get the table name of the current ResultSet using JDBC?
- How to detect the color using OpenCV in C++?
- How to track the color in OpenCV using C++?
- How to detect the eye in OpenCV using C++?
- How to track the eye in OpenCV using C++?
- How to count the number of faces in OpenCV using C++?
- How to change the brightness of an image in OpenCV using C++?
- How to decrease the Brightness of an image in OpenCV using C++?
- How to count the total number of frames in OpenCV using C++?

Advertisements