#include "stdafx.h" #include #include using namespace std; #include "opencv2/opencv.hpp" using namespace cv; int main(int argc, char* argv[]) { char buffer[1024] = ""; char vname[512] = "inp.mov"; VideoCapture video(vname); if(!video.isOpened()) { cout << "Can't open video: " << vname << endl; return 0; } int nFrames = video.get(CV_CAP_PROP_FRAME_COUNT); int fWidth = video.get(CV_CAP_PROP_FRAME_WIDTH); int fHeight = video.get(CV_CAP_PROP_FRAME_HEIGHT); bool done = false; bool next = false; int key; Mat display(fHeight + 200, fWidth, CV_8UC3); display(Rect(0,fHeight,fWidth,200)) = 0; namedWindow("Display"); int fNum = 0; Mat currFrame; while(!done) { bool val = video.set(CV_CAP_PROP_POS_FRAMES, fNum); video >> currFrame; if(currFrame.empty()) { cout << "Frame not found" << endl; } currFrame.copyTo(display(Rect(0, 0, fWidth, fHeight))); sprintf(buffer,"%d",fNum); putText(display, buffer, Point(fWidth - 50, 30), FONT_HERSHEY_PLAIN, 1, CV_RGB(0, 155, 0)); imshow("Display", display); next = false; while(!next) { key = waitKey(0); switch(key) { case 'n': case 'N': case ' ': fNum += 20; display(Rect(0, fHeight+100, fWidth, 100)) = 0; if(fNum >= nFrames) { putText(display, "Reached end of the video!", Point(fWidth/2 - 100, fHeight + 180), FONT_HERSHEY_PLAIN, 1, CV_RGB(255,0,0)); fNum -= 20; } else next = true; break; case 'p': case 'P': fNum -= 20; display(Rect(0, fHeight+100, fWidth, 100)) = 0; if(fNum < 0) { putText(display, "Reached start of the video!", Point(fWidth/2 - 100, fHeight + 180), FONT_HERSHEY_PLAIN, 1, CV_RGB(255,0,0)); fNum += 20; } else { //video.set(CV_CAP_PROP_POS_FRAMES, 0); next = true; } break; case 'q': next = true; done = true; break; } } } return 0; }