How do I create a video from an image being rotated?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to create a video by combining an image that is being rotated. The code gives me an .avi file, but the image is not rotating.
FPS=24;
time=10;
theta=1;
degPerFrame=10;
movie=VideoWriter('spinspokes.avi'); %create new video file
open(movie);
for i=1:FPS*time
B=imread('spokes.tif'); %open image file
writeVideo(movie,B);
pause(0.01)
theta=theta+degPerFrame;
B=imrotate(B,theta,'bilinear','crop'); %rotate image
end
close(movie);
implay('spinspokes.avi')
0 commentaires
Réponse acceptée
Dave B
le 1 Nov 2021
You're reading in the image, then writing the video frame, then rotating the image. I think you intended to rotate the video before writing the video:
for i=1:FPS*time
B=imread('spokes.tif'); %open image file
pause(0.01)
theta=theta+degPerFrame;
B=imrotate(B,theta,'bilinear','crop'); %rotate image
writeVideo(movie,B);
end
Better still, just read in the video once:
B=imread('spokes.tif'); %open image file
for i=1:FPS*time
theta = theta + degPerFrame;
B_rotate = imrotate(B, theta, 'bilinear', 'crop'); %rotate image
writeVideo(movie, B_rotate);
end
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!