Daily Archives: 15 Oct 2018

Extracting and Saving Video Frames using OpenCV-Python

In this tutorial, I will show you how to extract and save frames from a video file. Prerequisites are Chapter 1 and 2.

Steps:

  1.  Open the Video file or camera using cv2.VideoCapture()
  2.  Read frame by frame
  3.  Save each frame using cv2.imwrite()
  4.  Release the VideoCapture and destroy all windows

Now, Let’s code

If you don’t have any video, no need to worry. Open the camera instead of the file using cv2.VideoCapture(0) and start extracting frames.

Use: We can perform a number of operations on these frames like crop, flip, reverse etc. save them into a list and iterate over them to get cropped/flipped/reversed video. (See How you can make Video from images)

Hope you enjoy reading. If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time

Creating Video from Images using OpenCV-Python

In this blog, we will do a small project using OpenCV-Python where we will be creating video from image sequences. This project is entirely based on what we read in Chapter 1 and 2. Let’s start

Steps:

  1.  Fetch all the image file names using glob
  2.  Read all the images using cv2.imread()
  3.  Store all the images into a list
  4.  Create a VideoWriter object using cv2.VideoWriter()
  5.  Save the images to video file using cv2.VideoWriter().write()
  6.  Release the VideoWriter and destroy all windows.

Let’s see the code

glob.glob(Pathname) fetches all the filenames present in that path. ‘*.jpg’ means all the jpg files. So, in code glob.glob() fetches the filename of all the jpg files present in that path.

Hope you enjoy reading.

If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.