How to resolve this error of VideoWriter?
17 ビュー (過去 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!