Writing a plot into a video

17 visualizaciones (últimos 30 días)
Yanjika O
Yanjika O el 28 de Jun. de 2020
Respondida: Image Analyst el 28 de Jun. de 2020
Hello all,
I have this code for generating plots with complete dark and green rectangular. I wanted to get the frames and save them into video. How do i do this?
clear all
clc
repeats=5;
x=[3 7 7 3];
y=[3 3 7 7];
plot(x,y);
set(gca,'color','k','XTick',[], 'YTick', [])
set(gcf, 'WindowState', 'maximized')
for k=1:repeats
fill(x,y,'k')
set(gca,'color','k')
ax=gca;
xlim([0 10]);
ylim([0 10]);
pause(5)
fill(x,y,'g')
set(gca,'color','k')
ax=gca;
xlim([0 10]);
ylim([0 10]);
pause(5)
F(k)=getframe(gcf);
end
close all
writerObj=VideoWriter('safeGreen.avi','Uncompressed AVI');
writerObj.FrameRate=30;
open(writerObj);
writeVideo(writerObj,F);
close(writerObj);
  4 comentarios
Walter Roberson
Walter Roberson el 28 de Jun. de 2020
I suspect that you want the frames you draw to last 5 seconds each upon display.
In order to do that at 30 fps, you would have to record 150 copies of the same frame.
Alternately, you can switch to 1/5 fps, like in the below code.
repeats=5;
x=[3 7 7 3];
y=[3 3 7 7];
plot(x,y);
set(gca,'color','k','XTick',[], 'YTick', [])
set(gcf, 'WindowState', 'maximized')
for k=1:2:repeats*2
fill(x,y,'k')
set(gca,'color','k')
ax=gca;
xlim([0 10]);
ylim([0 10]);
pause(1)
F(k)=getframe(gcf);
fill(x,y,'g')
set(gca,'color','k')
ax=gca;
xlim([0 10]);
ylim([0 10]);
pause(1)
F(k+1)=getframe(gcf);
end
close all
writerObj=VideoWriter('safeGreen.avi','Uncompressed AVI');
writerObj.FrameRate=1/5;
open(writerObj);
writeVideo(writerObj,F);
close(writerObj);
Yanjika O
Yanjika O el 28 de Jun. de 2020
Wow, I wish I could be so easy as you to understand and correct this as needed. It was really helpful Thank you~

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 28 de Jun. de 2020

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by