필터 지우기
필터 지우기

How to resolve this error of VideoWriter?

조회 수: 16 (최근 30일)
Gulfam Saju
Gulfam Saju 2022년 3월 15일
댓글: Gulfam Saju 2022년 3월 15일
% 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)

채택된 답변

Image Analyst
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개)

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by