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

# Key Frames Extraction in a Video

Asked by G-ONE on 13 Nov 2012

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

my simple code

```   vid = 'Wildlife 00_00_20-00_00_30.avi';
`   for k=1:  readerobj.NumberOfFrames`
```           I=read(readerobj,k);
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`

msp on 29 Apr 2013

hello sir when i save frames of video they are not saved continuously they save in random order of index say example

frame_0015, frame_00124 so on... i want to save them continuously like index from 1 to n from frame_001,frame_002.... so on.

filename = fullfile('D:\', sprintf('frame_%05d.JPG', k) ); imwrite(J, filename);

Walter Roberson on 29 Apr 2013

Before the for loop,

```frc = 0;
```

Then change the filename assignment to

```frc = frc + 1;
filename = fullfile('D:\', sprintf('frame_%05d.JPG', frc));
```
msp on 29 Apr 2013

thank you sir.