How to resolve this error of VideoWriter?
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gulfam Saju
am 15 Mär. 2022
Kommentiert: Gulfam Saju
am 15 Mär. 2022
% 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 Kommentare
Akzeptierte Antwort
Image Analyst
am 15 Mär. 2022
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
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!