-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathframes.m
More file actions
39 lines (33 loc) · 1.26 KB
/
Copy pathframes.m
File metadata and controls
39 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
%%Extracting & Saving of frames from a Video file through Matlab Code%%
clc;
close all;
clear all;
% assigning the name of sample avi file to a variable
filename = 'D:\PhD kkj\PhD\capuse endoscopy\prj\impl\Bleeding\Bleeding videos\15.wmv';
%reading a video file
mov = VideoReader(filename);
% Defining Output folder as 'snaps'
opFolder = fullfile(cd, '/Bleeding/snaps');
%if not existing
if ~exist(opFolder, 'dir')
%make directory & execute as indicated in opfolder variable
mkdir(opFolder);
end
%getting no of frames
numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero
numFramesWritten = 0;
%for loop to traverse & process from frame '1' to 'last' frames
for t = 1 : numFrames
currFrame = read(mov, t); %reading individual frames
opBaseFileName = sprintf('%3.3d.png', t);
opFullFileName = fullfile(opFolder, opBaseFileName);
imwrite(currFrame, opFullFileName, 'png'); %saving as 'png' file
%indicating the current progress of the file/frame written
progIndication = sprintf('Wrote frame %4d of %d.', t, numFrames);
disp(progIndication);
numFramesWritten = numFramesWritten + 1;
end %end of 'for' loop
progIndication = sprintf('Wrote %d frames to folder "%s"',numFramesWritten, opFolder);
disp(progIndication);
%End of the code