Error using movie command in Matlab
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I generated multiple images which I converted into frames with im2frame in order to create a movie. I used this code:
for i = 10:20
images = sprintf('img%d.jpg',i);
ImageData = imread(images);
M(i) = im2frame(ImageData);
end
movie(M)
movie2avi(M,'sonar.avi','compression','None','fps',5,'quality',100)
When I run it, I get the following error:
Error using hgMovie
Movie contains uninitialized frames
Error in movie (line 41)
builtin('hgMovie',varargin{:});
Error in open83B_edited_2 (line 324)
movie(M)
Does anyone have a clue what might be wrong with my code? Thank you!
0 commentaires
Réponse acceptée
Geoff Hayes
le 8 Mai 2014
Hi Adrian,
I was able to reproduce the same issue with your above code. The problem is how the M array is being updated. The for loop iterates from 10 to 20 and the code uses these iteration values to assign the frame to the array. This means that M becomes an array of 20 frames, with the first nine not initialized - hence the error.
You can try the following instead:
% use this index into M
idxInM = 1;
for i = 10:20
images = sprintf('img%d.jpg',i);
ImageData = imread(images);
M(idxInM) = im2frame(ImageData);
idxInM = idxInM + 1;
end
Or any other mechanism that allows you to control how M is updated at each iteration.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Convert Image Type 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!