フィルターのクリア

How do I create a video from an image being rotated?

9 ビュー (過去 30 日間)
Devon Rose
Devon Rose 2021 年 11 月 1 日
回答済み: Dave B 2021 年 11 月 1 日
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')

採用された回答

Dave B
Dave B 2021 年 11 月 1 日
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 件)

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by