Matlab进行视频分析,首先要能读取单帧图片,然后对图片进行处理分析。尽管这个功能很简单,可是在不同电脑上第一次操作起来,我相信大多数都不能正确播放。(环境:xp+Matlab2008a)
首先看源码:
clc;
clear;
%% this to read avi by using mmread to get every frame
video = mmreader('D:\My Documents\MATLAB\森林火灾\My\fire.avi');
nFrames = video.NumberOfFrames; %得到帧数
H = video.Height; %得到高度
W = video.Width; %得到宽度
Rate = video.FrameRate;
% Preallocate movie structure.
mov(1:nFrames) = struct('cdata',zeros(H,W,3,'uint8'),'colormap',[]);
%read one frame every time
for i = 1:nFrames
mov(i).cdata = read(video,i);
P = mov(i).cdata;
disp('当前播帧数:'),disp(i);
imshow(P),title('原始图片');
% P2=rgb2gray(P);
end
1ÿ