Load and Display Video OpenCV C++





Example code:

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
VideoCapture video("C:/Users/hashan/Desktop/test.mp4");
//VideoCapture video(0);

if (!video.isOpened())
{
cout << "Cannot open the video cam" << endl;
return -1;
}

double frameWidth = video.get(CV_CAP_PROP_FRAME_WIDTH);
double frameHeight = video.get(CV_CAP_PROP_FRAME_HEIGHT);

cout << "Frame size : " << frameWidth << " x " << frameHeight << endl;

namedWindow("TestVideo", CV_WINDOW_AUTOSIZE);

while (1)
{
Mat frame;

bool bSuccess = video.read(frame);

if (!bSuccess)
{
cout << "Cannot read a frame from video stream" << endl;
break;
}

imshow("TestVideo", frame);

if (waitKey(30) == 27)
{
cout << "esc key pressed " << endl;
break;
}
}
return 0;

}

You can see the video from following.



  • Thank you very much for reading this tutorial. Our next tutorial is about how to develop python using visual studio
  • If you have problems regarding this tutorial feel free to make a comment below or contact us by sending message through our facebook page or by sending email to this address progtpoint@gmail.com
  •  and 


0 comments:

Social