MATLAB視訊轉換成圖片,圖片轉換動圖
視訊轉換圖片:(20分鐘視訊大概1130000張)
clc;
clear;%% 讀取視訊
video_file='全職高手第11集.avi';%%所在資料夾下面的視訊,最好很短,不然全部轉換需要較長時間
video=VideoReader(video_file);
frame_number=floor(video.Duration * video.FrameRate);
%% 分離圖片
for i=1:frame_number
image_name=strcat('11',num2str(i));
image_name=strcat(image_name,'.jpg');
I=read(video,i); %讀出圖片
imwrite(I,image_name,'jpg'); %寫圖片
I=[];
end
圖片轉換動畫(動圖):
clc;close all;clear all;figure(1);
%製作電影動畫
m=moviein(28); %分配儲存幀的記憶體
a0=int2str(0);
for i=1:9 % 依次讀入1-9張數字影象
a=int2str(i);%%整數轉換為字元
a1=strcat('C:\Users\dell\Desktop\程式\第9章\P9-6\葉修\葉修',a0,a0,a,'.jpg');
X1=imread(a1);imshow(X1);m(i)=getframe;
end
for i=10:28 % 依次讀入10-28張數字影象
a2=int2str(i);
a3=strcat('C:\Users\dell\Desktop\程式\第9章\P9-6\葉修\葉修',a0,a2,'.jpg');
X2=imread(a3);imshow(X2);m(i)=getframe;
end
movie(m,8); %播放動畫
%輸出各個電影幀
figure(2);
for i=1:9
subplot(7,4,i);
a=int2str(i);
a1=strcat('C:\Users\dell\Desktop\程式\第9章\P9-6\葉修\葉修',a0,a0,a,'.jpg');
X1=imread(a1);
image(X1);axis off;box off;
a4=int2str(i);
a5=strcat('第',a4,'幀');
title(a5,'fontsize',9,'fontname','隸書');
end
for i=10:28
subplot(7,4,i);
a2=int2str(i);
a3=strcat('C:\Users\dell\Desktop\程式\第9章\P9-6\葉修\葉修',a0,a2,'.jpg');
X2=imread(a3);
image(X2);axis off;box off;
a6=int2str(i);
a7=strcat('第',a6,'幀');
title(a7,'fontsize',9,'fontname','隸書');
end
把剛剛全職高手的圖片重新轉換結果如下: