在Matlab中创建视频的方法 [英] Approaches to create a video in matlab

查看:85
本文介绍了在Matlab中创建视频的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Matlab中创建视频的可能性是什么?我经过搜索后发现,主要有3个工具箱可用于该领域,包括图像处理,图像采集和视觉控制...但是如果没有它们,我如何才能做到这一点呢?我对概述的各种方法感兴趣,但无法在互联网上找到任何不错的教程或一致的信息来源.

What are the possibilities to create videos in Matlab? I was searching and found mainly 3 toolboxes that work in this field, image processing, image acquisition and control vision... but how can I do it without them, just to create the video from scratch? I'm interested in various approaches to have an overview, but I was unable to find any decent tutorial or consistent source of info on the internet.

感谢您的帮助!

推荐答案

以下是在(核心)MATLAB中创建电影的一些不同方法.

Here are some of the different ways to create movies in (core) MATLAB.

(已弃用,请改用VIDEOWRITER)

(deprecated, use VIDEOWRITER instead)

%# figure
figure, set(gcf, 'Color','white')
Z = peaks; surf(Z);  axis tight
set(gca, 'nextplot','replacechildren', 'Visible','off');

%# preallocate
nFrames = 20;
mov(1:nFrames) = struct('cdata',[], 'colormap',[]);

%# create movie
for k=1:nFrames
   surf(sin(2*pi*k/20)*Z, Z)
   mov(k) = getframe(gca);
end
close(gcf)

%# save as AVI file, and open it using system video player
movie2avi(mov, 'myPeaks1.avi', 'compression','None', 'fps',10);
winopen('myPeaks1.avi')

AVIFILE

(已弃用,请改用VIDEOWRITER)

AVIFILE

(deprecated, use VIDEOWRITER instead)

%# figure
figure, set(gcf, 'Color','white')
Z = peaks; surf(Z);  axis tight
set(gca, 'nextplot','replacechildren', 'Visible','off');

%# create AVI object
nFrames = 20;
aviobj = avifile('myPeaks2.avi', 'fps',10);

%# create movie
for k=1:nFrames
   surf(sin(2*pi*k/20)*Z, Z)
   aviobj = addframe(aviobj, getframe(gca));
end
close(gcf)

%# save as AVI file, and open it using system video player
aviobj = close(aviobj);
winopen('myPeaks2.avi')

视频

%# figure
figure, set(gcf, 'Color','white')
Z = peaks; surf(Z);  axis tight
set(gca, 'nextplot','replacechildren', 'Visible','off');

%# create AVI object
nFrames = 20;
vidObj = VideoWriter('myPeaks3.avi');
vidObj.Quality = 100;
vidObj.FrameRate = 10;
open(vidObj);

%# create movie
for k=1:nFrames
   surf(sin(2*pi*k/20)*Z, Z)
   writeVideo(vidObj, getframe(gca));
end
close(gcf)

%# save as AVI file, and open it using system video player
close(vidObj);
winopen('myPeaks3.avi')

(技术上不是电影,而是GIF动画图片)

IMWRITE

(technically not a movie, but an animated GIF image)

%# figure
figure, set(gcf, 'Color','white')
Z = peaks; surf(Z);  axis tight
set(gca, 'nextplot','replacechildren', 'Visible','off');

%# preallocate
nFrames = 20;
f = getframe(gca);
[f,map] = rgb2ind(f.cdata, 256, 'nodither');
mov = repmat(f, [1 1 1 nFrames]);

%# create movie
for k=1:nFrames
    surf(sin(2*pi*k/20)*Z, Z)
    f = getframe(gca);
    mov(:,:,1,k) = rgb2ind(f.cdata, map, 'nodither');
end
close(gcf)

%# create GIF and open
imwrite(mov, map, 'myPeaks4.gif', 'DelayTime',0, 'LoopCount',inf)
winopen('myPeaks4.gif')

这篇关于在Matlab中创建视频的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆