Coders Packet

Key Frame extraction using Python

By Yashraj Tambe

A video is a series of images which are displayed for less than 0.05 sec. Hence we use this algorithm to extract those important frames from video by using Python language & OpenCV library.

Key Frame extraction algorithm needs a camera or a video in (possibly mp4 format is better) & OpenCV is needed.We are using Python as programminng language & OpenCV library as tool.

Dependencies:-

Use latest version of OpenCV & it can be installed using the following command: -

pip install opencv-python

Algorithm:-

Step 1: 

For each video frame k = 1 to N

Read frame Vk and Vk+1
Obtain the gray level image for Vk and Vk+1
Gk = Gray image of Vk
Gk +1 = Gray image of Vk +1
Find the edge difference between Gk and Gk + 1 using the Canny edge detector.
Let diff(k) be their difference.
dif(k) = summation of i,j (Gk - Gk + 1) where i, j are row and column index.

Step 2:

Compute the mean and standard deviation:

Step 3:

Compute the threshold value 

Threshold = M + a*S , where a = constant

Step 4: 

Find the key frames for k = 1 to (N-1)

If diff(k) > Threshold then, 
Write frame Vk +1 as the output key-frame.

Note:The code is implemented in the file "Key-Frame-Extraction.ipynb" file & click on Run All or Run.

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Yashraj Tambe (yashraj)

Download packets of source code on Coders Packet