MATLAB Answers

G-ONE
1

Key Frames Extraction in a Video

Asked by G-ONE
on 13 Nov 2012
Latest activity Commented on by Walter Roberson
on 18 Jul 2016

Hello Everyone

I am working on a assignment "key frames extraction in a video sequence" Method that i am using as follows

   ->extracts frames one by one
   ->histogram difference between two consecutive frames using imhist() and 
     imabsdiff()
   ->calculate mean and standard deviation of difference and threshold
   ->continue till end of video
   ->again extracts frames one by one
   ->histogram difference between two consecutive frames using imhist() and 
     imabsdiff()
   ->compare this difference with threshold and if it is greater than threshold     
      select it as a key frame
   ->continue till end of video

is this method correct??

if anyone have good solution plz help me with the code

thanks in advance

my simple code

   vid = 'Wildlife 00_00_20-00_00_30.avi';
   readerobj = mmreader(vid);
   for k=1:  readerobj.NumberOfFrames
           I=read(readerobj,k);
           if(k~= readerobj.NumberOfFrames)
                 J=read(readerobj,k+1);
                 sss=absdif(I,J);
                 X(k)=sss;
           end
   end
   mean=mean2(X)
   std=std2(X)
   threshold=std+mean*4
   for k=1: readerobj.NumberOfFrames
       I =  read(readerobj,k);
       if(k~=readerobj.NumberOfFrames)
        J=   read(readerobj,k+1);
        sss=absdif(I,J);
        if(sss>mean)
            imwrite(J,strcat('D:\',Names{k+1}));
       end
   end

% absdif function

   function [ res ] = absdif( I,J )
       k=rgb2gray(I);
       l=rgb2gray(J);
       m=imhist(k);
       n=imhist(l);
       dif=imabsdiff(m,n);
       res=sum(dif);
   end

  18 Comments

i m geting error in following line X(k)=sss.... Subscripted assignment dimension mismatch.

m getting error at last function part, can u please help me.

Please post the entire error message, everything in red. Also since there were several revisions suggested to the posted code, please post your code so we know what we are dealing with.

0 Answers

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!