diff --git a/OpenCVVideoParser/OpenCVVideoParser.vcxproj b/OpenCVVideoParser/OpenCVVideoParser.vcxproj index 0cd321e..e7dba16 100644 --- a/OpenCVVideoParser/OpenCVVideoParser.vcxproj +++ b/OpenCVVideoParser/OpenCVVideoParser.vcxproj @@ -97,6 +97,7 @@ _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true C:\Users\sigon\Downloads\opencv\build\include;%(AdditionalIncludeDirectories) + stdcpp17 Console @@ -134,6 +135,7 @@ _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true C:\Users\sigon\Downloads\opencv\build\include;%(AdditionalIncludeDirectories) + stdcpp17 Console diff --git a/OpenCVVideoParser/main.cpp b/OpenCVVideoParser/main.cpp index 945d8b5..470bc2e 100644 --- a/OpenCVVideoParser/main.cpp +++ b/OpenCVVideoParser/main.cpp @@ -19,13 +19,19 @@ void extract_frames(const std::string &videoFilePath,std::vector& frame if(!cap.isOpened()) // check if we succeeded cv::error(CV_StsError,"Can not open Video file",__FUNCTION__,"C:\\Users\\sigon\\source\\repos\\OpenCVVideoParser\\OpenCVVideoParser\\main.cpp",14); + + /* //cap.get(CV_CAP_PROP_FRAME_COUNT) contains the number of frames in the video; for(int frameNum = 0; frameNum < cap.get(cv::CAP_PROP_FRAME_COUNT);frameNum++) { cv::Mat frame; cap >> frame; // get the next frame from video frames.push_back(frame); - } + }*/ + cap.set(cv::CAP_PROP_POS_FRAMES,100); + cv::Mat frame; + cap >> frame; // get the next frame from video + frames.push_back(frame); } catch( cv::Exception& e ){ std::cerr << e.msg << std::endl; @@ -33,6 +39,12 @@ void extract_frames(const std::string &videoFilePath,std::vector& frame } } +cv::Mat get_frame(cv::VideoCapture&video,int frameNumb){ + video.set(cv::CAP_PROP_POS_FRAMES,frameNumb); + cv::Mat frame; + video >> frame; + return frame; +} /* It saves a vector of frames into jpg images into the outputDir as 1.jpg,2.jpg etc where 1,2 etc represents the frame number @@ -69,16 +81,17 @@ public: public: std::vectorframes; float frameView=0; + cv::VideoCapture video; // open the video file bool OnUserCreate() override { // Called once at the start, so create things here - extract_frames("C:/users/sigon/Videos/test.mp4",frames); + video.open("C:/users/sigon/Videos/test.mp4"); return true; } void UpdateScreen(){ Clear(BLACK); - cv::Mat&targetFrame=frames[int(frameView)]; + cv::Mat targetFrame=get_frame(video,std::clamp(int(frameView),0,int(video.get(cv::CAP_PROP_FRAME_COUNT)))); for(int y=0;y(cv::Point{x,y}); @@ -93,10 +106,18 @@ public: bool OnUserUpdate(float fElapsedTime) override { // Called once per frame, draws random coloured pixels + if(GetKey(RIGHT).bPressed){ + frameView+=1; + UpdateScreen(); + } if(GetKey(RIGHT).bHeld){ frameView+=fElapsedTime*60; UpdateScreen(); } + if(GetKey(LEFT).bPressed){ + frameView-=1; + UpdateScreen(); + } if(GetKey(LEFT).bHeld){ frameView-=fElapsedTime*60; UpdateScreen();