一、把视频分成一帧帧的图片的几种方法
obj = VideoReader('E:\工业相机\sp\PIC_0145.MP4');%输入视频位置
numFrames = obj.NumFrames;% 帧的总数
for k = 1 : 15% 读取前15帧
frame = read(obj,k);%读取第几帧
imwrite(frame,strcat('E:\工业相机\111\',num2str(k),'.jpg'),'jpg');% 保存帧
end
二、把图片按指定帧率合成视频
srcDic = uigetdir('E:\工业相机\111');
cd(srcDic);
allnames = struct2cell(dir('*.jpeg'));
[k,len]=size(allnames);
aviobj = VideoWriter('driver7.avi');
aviobj.FrameRate = 5;
open(aviobj)
for i = 1:100
name = allnames{1,i};
frame = imread(name);
writeVideo(aviobj,frame);
end
close(aviobj)