## Key Frames Extraction in a Video

### G-ONE (view profile)

on 13 Nov 2012
Latest activity Commented on by Walter Roberson

### Walter Roberson (view profile)

on 21 Oct 2016 at 17:20

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`

Walter Roberson

### Walter Roberson (view profile)

on 18 Jul 2016

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.

k swati subudhi

### k swati subudhi (view profile)

on 21 Oct 2016 at 17:03

i am getting an error like this :Undefined function 'absdif' for input arguments of type 'uint8'. what should i do ??

Walter Roberson

### Walter Roberson (view profile)

on 21 Oct 2016 at 17:20

## Products

#### Join the 15-year community celebration.

Play games and win prizes!

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