필터 지우기
필터 지우기

Frame must be 1464 by 834 but why ?

조회 수: 39 (최근 30일)
muhammad choudhry
muhammad choudhry 2021년 4월 21일
댓글: Walter Roberson 2021년 4월 26일
Hi,
I am making a video from the images but I am getting error which I do not know how to deal with. Can anyone help please.
Code:
imgFiles = dir('*.jpg') ;
N = length(imgFiles) ;
% create the video writer with 1 fps
writerObj = VideoWriter('myVideo.avi');
%writerObj.FrameRate = 10;
% open the video writer
open(writerObj);
% write the frames to the video
for i=1:N
img = imgFiles(i).name ;
I = imread(img) ;
imshow(I) ;
F = getframe(gcf) ;
writeVideo(writerObj, F);
end
% close the writer object
close(writerObj);
Error:
Error using VideoWriter/writeVideo (line 368)
Frame must be 1464 by 834
Error in framesTovideo (line 21)
writeVideo(writerObj, F);

채택된 답변

Mohammad Sami
Mohammad Sami 2021년 4월 26일
In that case perhaps you can try writing the image directly to the video, instead of using getFrame with imshow.
imgFiles = dir('*.jpg') ;
N = length(imgFiles) ;
% create the video writer with 1 fps
writerObj = VideoWriter('myVideo.avi');
%writerObj.FrameRate = 10;
% open the video writer
open(writerObj);
% write the frames to the video
for i=1:N
img = imgFiles(i).name ;
I = imread(img) ;
writeVideo(writerObj, I);
end
% close the writer object
close(writerObj);
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 4월 26일
Yes, exactly. When you getframe(), you will not always read back exactly the same size frame, even if you are plotting the same amount of data. The frame size can vary between 2 pixels narrower than normal to 3 pixels wider than normal, based upon the absolute value of the data coordinates being used -- and this can be related to the exact width of the last text label on the axes (proportional width fonts.)
Writing directly from matrix to file is better in situations where it is practical.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mohammad Sami
Mohammad Sami 2021년 4월 21일
편집: Mohammad Sami 2021년 4월 21일
The video frame size is set by the first frame that you write. From the documentation.
"The writeVideo method sets values for Height and Width based on the dimensions of the first frame."
If your images are not the same sizes, you will have to use imresize function to resize them to the desired size.
  댓글 수: 1
muhammad choudhry
muhammad choudhry 2021년 4월 21일
Hi Sami, that is the problem, all the images in the folder are of same size 1280x720 but I am still getting this error.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by