This section explains how to read and display videos using OpenCV. OpenCV provides VideoCapture object for reading and writing videos. We can also use VideoCapture object to capture images from camera as well. The constructor can be used to read a video by providing a string path of the video to read. We can also provide the integer value indicating the camera index to capture the camera.
Let us look at an example to read a video file and display the frames one by one. Normally, the video frames are display at 25 FPS, which means 25 frames are displayed in one second. In this example, we will need to handle it manually by using waitKey() method of OpenCV. It will give an impression of playing the video at the original frame rate. The following code reads a video and displays the frames one by one:
Figure 1. A sample frame captured from the video.