IKH

Pre-processing Frames – I

Now that you have learnt to capture the video using OpenCV, let’s capture frames and do pre-process before extracting the vehicles. Pre-processing will help to speed up process and make the results more accurate.

The pre-processing steps are generally converting the colour image to grayscale, blurring it (Gaussian blur or some other blurring), applying thresholding, dilation and erosion. You are already familiar with these steps from an earlier part of the session.

The steps are:

  • Capture 2 consecutive frames (images) from the video.
  • Convert those to a grayscale image.
  • Take the difference between images to capture the motion.
  • Threshold the image. Convert the pixels to either o or 255.
  • Remove noise using dilation and erosion.

We need to capture two consecutive frames to capture the motion. Further explanation regarding the processing of the frames is present in the next segment. Remember, the preprocessing steps will be the same for both the frames.

After drawing of the line, using the variable ‘callback’, we start to capture the frames from the video. Remember that ‘callback=True’ was executed in the last ‘if statement of myMouseHandler() function when we finished drawing the yellow line. Further, we do all preprocessing such as converting a frame to grayscale, etc. in the copied frame.

Now, let’s proceed with the lecture.

Here, we used Gaussian blur to decrease the Gaussian noise in the video. Noise is any unwanted signal. Here, we are discussing noise that appears in the form of graininess in the image. By blurring/smoothing using filters, graininess dissolves with the surrounding pixel. Image smoothing out but it may also result in blurring the edges as shown below:

You will see further preprocessing in the next segment.

Report an error