MATLAB if exist([img_path num2str(1, ‘%04i.png’)], ‘file’),
img_files = num2str((1:seq.len)’, [img_path ‘%04i.png’]);
elseif exist([img_path num2str(1, ‘%04i.jpg’)], ‘file’),
img_files = num2str((1:seq.len)’, [img_path ‘%04i.jpg’]);
elseif exist([img_path num2str(1, ‘%04i.bmp’)], ‘file’),
img_files = num2str((1:seq.len)’, [img_path ‘%04i.bmp’]);
else
error(‘No image files to load.’)
end
依次判断img_path文件夹中是否存在图片文件0001.png、0001.jpg、0001.bmp,如果存在某种类型的文件,则按照同类型产生0002.*、0003.*等序列文件名(一直到seq.len)。如果没找到上述三种类型的图片文件,则报错。
需要注意的是,img_path中如果包含多层目录,则分隔符应使用“\”或“/”,而不能使用“\”。