현재 프레임은 비디오를 재생 중이고 지금 표시된 프레임이 현재 프레임임을 의미합니다. 활성 프레임이라고도 합니다. 많은 응용 프로그램에서 현재 프레임의 번호를 가져오도록 요구할 수 있습니다.
다음 프로그램은 현재 프레임의 위치를 읽어 콘솔 창에 표시합니다.
예시
#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;
} 이 프로그램은 비디오를 재생하고 콘솔 창에 현재 프레임의 위치를 표시합니다.
출력

