extract key frames from video
9 views (last 30 days)
I am writing a code having following steps to extract key frames:
1) Read frames from video (let us suppose we have 700 frames)
2) Now using 'ssim' function I am finding similarity between frame 1 and successive frames. For using 'ssim' a reference frame should be there. Initially I made the first frame as reference frame. Also I took the first frame as key frame. The next frame will be keyframe if similarity is less than some threshold 'T'.
3) Suppose My 80th frame has similarity less than 'T'. Now I want to make this frame as my reference frame. And also the for loop should start from this frame only means in this case now for loop will start from 80th frame and correspondingly will find similarity between successive frames i.e.from 81st onwards.
4) I have to repeat the process till last keyframe.
Attaching here the piece of code. Kindly suugest the ways to execute the above steps.
%reading video frames
numFrames = vid.NumberOfFrames;
% making a folder to save the frames
Folder = 'D:\project\Fingerspelling pics\extframes\';
% writing extracted frames into the specified folder
for iFrame = 1:n
frames = read(vid, iFrame);
imwrite(frames, fullfile(Folder, sprintf('%06d.jpg', iFrame)));
FileList = dir(fullfile(Folder, '*.jpg'));
%here refernce is the 1st frame but I have to make such that reference should be current keyframe.
ref = imread('D:\project\Fingerspelling pics\extframes\000001.jpg');
aFile = fullfile(Folder, FileList(iFile).name)
I3 = imread(aFile);