Frame must be 1464 by 834 but why ?

46 vues (au cours des 30 derniers jours)
muhammad choudhry
muhammad choudhry le 21 Avr 2021
Commenté : Walter Roberson le 26 Avr 2021
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);

Réponse acceptée

Mohammad Sami
Mohammad Sami le 26 Avr 2021
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 commentaire
Walter Roberson
Walter Roberson le 26 Avr 2021
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Mohammad Sami
Mohammad Sami le 21 Avr 2021
Modifié(e) : Mohammad Sami le 21 Avr 2021
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 commentaire
muhammad choudhry
muhammad choudhry le 21 Avr 2021
Hi Sami, that is the problem, all the images in the folder are of same size 1280x720 but I am still getting this error.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by