Skip to content

Instantly share code, notes, and snippets.

@miguelrochajr
Created May 6, 2017 02:16
Show Gist options
  • Save miguelrochajr/98da3cfaf129207fa7f42a1380debaea to your computer and use it in GitHub Desktop.
Save miguelrochajr/98da3cfaf129207fa7f42a1380debaea to your computer and use it in GitHub Desktop.
How to Open a video file on OpenCV 3.1.0
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
int main() {
cv::VideoCapture cap;
cap.open("myVideo.mp4" );
cv::namedWindow( "myVideo", cv::WINDOW_AUTOSIZE );
cv::Mat frame;
while(true) {
cap >> frame;
if( frame.empty() ){
std::cout << "Could not load the video frames. \n";
break;
}
cv::imshow( "myVideo", frame );
if( cv::waitKey(27) >= 0 ){
std::cout << "Escape pressed \n";
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment