|
|
@ -19,13 +19,19 @@ void extract_frames(const std::string &videoFilePath,std::vector<cv::Mat>& frame |
|
|
|
if(!cap.isOpened()) // check if we succeeded
|
|
|
|
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); |
|
|
|
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;
|
|
|
|
//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++) |
|
|
|
for(int frameNum = 0; frameNum < cap.get(cv::CAP_PROP_FRAME_COUNT);frameNum++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
cv::Mat frame; |
|
|
|
cv::Mat frame; |
|
|
|
cap >> frame; // get the next frame from video
|
|
|
|
cap >> frame; // get the next frame from video
|
|
|
|
frames.push_back(frame); |
|
|
|
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 ){ |
|
|
|
catch( cv::Exception& e ){ |
|
|
|
std::cerr << e.msg << std::endl; |
|
|
|
std::cerr << e.msg << std::endl; |
|
|
@ -33,6 +39,12 @@ void extract_frames(const std::string &videoFilePath,std::vector<cv::Mat>& 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 |
|
|
|
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: |
|
|
|
public: |
|
|
|
std::vector<cv::Mat>frames; |
|
|
|
std::vector<cv::Mat>frames; |
|
|
|
float frameView=0; |
|
|
|
float frameView=0; |
|
|
|
|
|
|
|
cv::VideoCapture video; // open the video file
|
|
|
|
bool OnUserCreate() override |
|
|
|
bool OnUserCreate() override |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Called once at the start, so create things here
|
|
|
|
// 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; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UpdateScreen(){ |
|
|
|
void UpdateScreen(){ |
|
|
|
Clear(BLACK); |
|
|
|
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<targetFrame.rows;y++){ |
|
|
|
for(int y=0;y<targetFrame.rows;y++){ |
|
|
|
for(int x=0;x<targetFrame.cols;x++){ |
|
|
|
for(int x=0;x<targetFrame.cols;x++){ |
|
|
|
cv::Vec3b col=targetFrame.at<cv::Vec3b>(cv::Point{x,y}); |
|
|
|
cv::Vec3b col=targetFrame.at<cv::Vec3b>(cv::Point{x,y}); |
|
|
@ -93,10 +106,18 @@ public: |
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Called once per frame, draws random coloured pixels
|
|
|
|
// Called once per frame, draws random coloured pixels
|
|
|
|
|
|
|
|
if(GetKey(RIGHT).bPressed){ |
|
|
|
|
|
|
|
frameView+=1; |
|
|
|
|
|
|
|
UpdateScreen(); |
|
|
|
|
|
|
|
} |
|
|
|
if(GetKey(RIGHT).bHeld){ |
|
|
|
if(GetKey(RIGHT).bHeld){ |
|
|
|
frameView+=fElapsedTime*60; |
|
|
|
frameView+=fElapsedTime*60; |
|
|
|
UpdateScreen(); |
|
|
|
UpdateScreen(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(GetKey(LEFT).bPressed){ |
|
|
|
|
|
|
|
frameView-=1; |
|
|
|
|
|
|
|
UpdateScreen(); |
|
|
|
|
|
|
|
} |
|
|
|
if(GetKey(LEFT).bHeld){ |
|
|
|
if(GetKey(LEFT).bHeld){ |
|
|
|
frameView-=fElapsedTime*60; |
|
|
|
frameView-=fElapsedTime*60; |
|
|
|
UpdateScreen(); |
|
|
|
UpdateScreen(); |
|
|
|