📄 processframe.m
字号:
function processFrame(data,width,height,frameNr,time)
% processFrame(data,width,height,frameNr)
%
% This is the function prototype to be used by the matlabCommand option of
% mmread.
% INPUT
% data the raw captured frame data, the code below will put it
% into a more usable form
% width the width of the image
% height the height of the image
% frameNr the frame # (counting starts at frame 1)
% time the time stamp of the frame (in seconds)
%
% Warning, the way that this is implemented requires buffering about 1
% seconds worth of video. If you don't have enough memory in your system
% to hold 1 second's worth of video, this will crash on you. Either make
% your movies smaller, or buy more memory.
%
% EXAMPLES
% Process all frames in a movie using this function:
% mmread('mymovie.mpg',[],[],false,false,'processFrame');
%
% Process only frames 1 through 10 using this function:
% mmread('mymovie.mpg',1:10,[],false,false,'processFrame');
persistent warned;
try
scanline = ceil(width*3/4)*4; % the scanline size must be a multiple of 4.
% some times the amount of data doesn't match exactly what we expect...
if (numel(data) ~= scanline*height)
if (numel(data) > 3*width*height)
if (isemtpy(warned))
warning('mmread:general','dimensions do not match data size. Guessing badly...');
warned = true;
end
scanline = width*3;
data = data(1:3*width*height);
else
error('dimensions do not match data size. Too little data.');
end
end
% if there is any extra scanline data, remove it
data = reshape(data,scanline,height);
data = data(1:3*width,:);
% the data ordering is wrong for matlab images, so permute it
data = permute(reshape(data, 3, width, height),[3 2 1]);
% the images are also upside down and colors were backwards.
data = data(end:-1:1,:,3:-1:1);
% now do something with the data...
image(data);
title(['frame ' num2str(frameNr) ' ' num2str(time) 's ']);
drawnow;
% stop early
% if (frameNr == 10)
% error('processFrame:STOP','STOP!!!');
% end
catch
% if we don't catch the error here we will loss the stack trace.
err = lasterror;
disp([err.identifier ': ' err.message]);
for i=1:length(err.stack)
disp([err.stack(i).file ' (' err.stack(i).name ') Line: ' num2str(err.stack(i).line)]);
end
rethrow(err);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -