How to resolve this error of VideoWriter?
16 次查看(过去 30 天)
显示 更早的评论
% Make an avi movie from a collection of PNG images in a folder.
% Specify the folder.
myFolder = 'G:\Brain Data\OCMR_data\cardiac_allslice\sense_recon';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a directory listing.
filePattern = fullfile(myFolder, '*.PNG');
pngFiles = dir(filePattern);
% Open the video writer object.
writerObj = VideoWriter('senseRecon.avi');
open(writerObj);
% Go through image by image writing it out to the AVI file.
for frameNumber = 1 : length(pngFiles)
% Construct the full filename.
baseFileName = pngFiles(frameNumber).name;
fullFileName = fullfile(myFolder, baseFileName);
% Display image name in the command window.
fprintf(1, 'Now reading %s\n', fullFileName);
% Display image in an axes control.
thisimage = imread(fullFileName);
imshow(thisimage); % Display image.
drawnow; % Force display to update immediately.
% Write this frame out to the AVI file.
writeVideo(writerObj, thisimage);
end
% Close down the video writer object to finish the file.
close(writerObj);
I tried to make a video from multiple PNG files. The size of all images are 854*364 pixels. But after running the code I got this error:
Error using VideoWriter/writeVideo (line 368)
Frame must be 854 by 364
Error in makevideo (line 27)
0 个评论
采纳的回答
Image Analyst
2022-3-15
Evidently not all your frames are the same size. Why don't you print out their size right after you read the frames in
[rows, columns, numberOfColorChannels] = size(thisImage) % No semicolon
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!