Frame must be 1464 by 834 but why ?

48 visualizaciones (últimos 30 días)
muhammad choudhry
muhammad choudhry el 21 de Abr. de 2021
Comentada: Walter Roberson el 26 de Abr. de 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);

Respuesta aceptada

Mohammad Sami
Mohammad Sami el 26 de Abr. de 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 comentario
Walter Roberson
Walter Roberson el 26 de Abr. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

Mohammad Sami
Mohammad Sami el 21 de Abr. de 2021
Editada: Mohammad Sami el 21 de Abr. de 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 comentario
muhammad choudhry
muhammad choudhry el 21 de Abr. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by