Can't save a video with VideoWrite: Error [Frame must be 550 by 420]

4 次查看(过去 30 天)
% video traiettoria
v = VideoWriter('traiettoria');
open(v);%
figure
scatter(0,0,200,'r','filled','s');
hold on;
grid on, grid minor, axis equal;hold on;
title('traiettoria AUV in coordinate ne USBL');
xlabel('est (m)');hold on;
ylabel('nord (m)'); hold on;
curve = animatedline('Color','b','LineStyle','-','LineWidth',1);
for k = 1:length(t_raw_sec)
addpoints(curve,e_no_outliers(k),n_no_outliers(k))
drawnow;
frame = getframe(gcf);
writeVideo(v,frame);
end
close(v);
I can't save the video because the frames are not the same size, I suppose...any suggestion?Thanks!

回答(1 个)

Image Analyst
Image Analyst 2020-5-4
You need to set up the movie in advance so that all the frames are the same size. Here is a snippet you can modify.
% Set up the movie structure.
% Preallocate movie, which will be an array of structures.
% First get a cell array with all the frames.
allTheFrames = cell(numberOfFrames,1);
vidHeight = 344;
vidWidth = 446;
allTheFrames(:) = {zeros(vidHeight, vidWidth, 3, 'uint8')};
% Next get a cell array with all the colormaps.
allTheColorMaps = cell(numberOfFrames,1);
allTheColorMaps(:) = {zeros(256, 3)};
% Now combine these to make the array of structures.
myMovie = struct('cdata', allTheFrames, 'colormap', allTheColorMaps);
For a full demo, see my attached demo, movie_made_from_surf.m, where I make a movie out of a figure that I'm animating.

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by