在Matlab中循环VideoReader进行处理

时间:2015-04-27 22:05:14

标签: matlab loops video-processing

我到处寻找,我似乎无法成功循环MATLAB的视频播放器。我正在尝试使用MATLAB处理视频并将它们转换为保存的图像序列,我可以通过二进制像素属性分析区域等。我对MATLAB很陌生,所以任何帮助都肯定会有所帮助。

到目前为止,这是我创建图像序列的代码。这也是在R2015a。

    function VideoToImageSequence(dirname,doall)

% load up the set of global variables
global settings
inpath = [settings.inpath, '\' , settings.dirname, '\'];
outpath = inpath; 

%list of files
list = dir([inpath, '\*.avi']);
N =length(list);
display(['Found ', mat2str(N), ' movies in ', inpath]);

%Main converter 
for i= 1:N
rootname{i} = list(i).name(1:end-4);
savefile = [rootname{i}, '.mat'];
if exist([inpath, savefile], 'file') && doall==0
    display(['Found analyzed file ', savefile, ' .... skipping']);
    else

    %Directory
    addpath(genpath([settings.inpath,'\', settings.dirname,'\'     ,rootname{i}]));
    workingDir = [settings.inpath,'\' , settings.dirname, '\' , rootname(i)];
    cd([settings.inpath, '\', settings.dirname, '\'])

    filename= rootname(i) ;

    VideoFile = VideoReader(filename) ; 

    ii = 1;

    %Spits out image sequence
     while hasFrame(VideoFile(i))
        img = readFrame(VideoFile(i));
        filename = [sprintf('%03d',ii) '.jpg'];
        fullname = fullfile(workingDir,'images',filename);
         imwrite(img,fullname)    % Write out to a JPEG file (img1.jpg, img2.jpg, etc.)
         ii = ii+1;
     end
end
end

你能给予的任何帮助都很棒!感谢。

0 个答案:

没有答案