image thumbnail

Simple StopMotion Film Studio

by

 

Capture frames from image aquisition devices and create your own stop motion animation.

stopmotionUI(action,varargin)
function stopmotionUI(action,varargin)

% Written by: S.A. van der Wulp

if nargin==0
    action = 'Initialize';    
end

feval(action,varargin{:});

return

function Initialize

%% Create global parameters
global Frames Video Objects Settings

%% Settings
Settings.DeviceID       = 'YUY2_640x480';
Settings.Adaptor        = 2;
Settings.CurrentFrame   = 0;
Settings.TotalFrames    = 0;
Settings.FPS            = 12;
Settings.Quality        = 100;
Settings.Title          = 'My First StopMotionPicture';
Settings.AviOut         = 'StopMotion1.avi'; 
Settings.Capture        = 1;
Settings.Interval       = 60;
Settings.SceneLength    = 5;

%% Create figure
figure('Name','StopMotion v 1.01 ',...
    'NumberTitle','off',...
    'Visible','on',...
    'Position',[100 100  1000 800],... 
    'HandleVisibility','on',...
    'Menubar','none',...
    'IntegerHandle','off',...
    'Resize','on');

%% Controls
Objects.Capture     = uicontrol('Tag', 'Capture', 'String', 'Capture frame', 'Callback', 'capture', 'Position', [20 20 120 40]);
Objects.Previous    = uicontrol('Tag', 'Previous', 'String', 'Previous frame', 'Callback', 'SetFrames','Position', [150 20 120 40]);
Objects.Display     = uicontrol('Tag', 'Display', 'Style', 'Text', 'String', '00:00:00.000s 0/0 (12 fps)', 'Callback', 'SetFrames', 'Position', [280 20 420 40],...
    'FontSize',16,'FontWeight','Normal','FontAngle','Italic','BackgroundColor',[0.8 0.8 0.8]);
Objects.Next        = uicontrol('Tag', 'Next', 'String', 'Next frame', 'Callback', 'SetFrames', 'Position', [720 20 120 40]);
Objects.Generate    = uicontrol('Tag', 'Generate', 'String', 'Generate', 'Callback', 'GenerateFilm', 'Position', [860 20 120 40]);
Objects.Settings    = uicontrol('Tag', 'Settings', 'String', 'Settings', 'Callback', 'AviSettings', 'Position', [860 80 120 40]);

%% Infotexts
uicontrol('Tag', 'Liveview', 'String', 'Live View', 'Callback', 'LiveView','Position', [20 750 120 40]);
uicontrol('Tag', 'Preview', 'String', 'Pre View', 'Position', [520 750 120 40]);

%% Live View
Objects.LiveView    = axes('Tag','LiveViewFrame','Position',[0.01 0.46 0.48 0.45],'Visible','off'); hold on;
set(Objects.LiveView,'ydir','reverse')

%% Camera Settings
Video = videoinput('winvideo', Settings.Adaptor, Settings.DeviceID);

% Initialize Video
Video.ReturnedColorSpace = 'rgb';
Video.FramesPerTrigger = 1;
vidRes = get(Video, 'VideoResolution'); 
nBands = get(Video, 'NumberOfBands');

% Background image
Objects.LiveViewFrameA = image(ones(vidRes(2), vidRes(1), nBands));

% Live View
Objects.LiveViewFrameB = image(zeros(vidRes(2), vidRes(1), nBands));
preview(Video,Objects.LiveViewFrameB);
alpha(0.5);

%% Pre View
Objects.PreView    = axes('Tag','PreViewFrame','Position',[0.51 0.46 0.48 0.45],'Visible','off'); hold on;
set(Objects.PreView,'ydir','reverse')
Objects.PreViewFrameA   = image(ones(vidRes(2), vidRes(1), nBands));

%% Frames initialization
for i = 1:Settings.SceneLength * Settings.FPS
    Frames(i).RGB = ones(vidRes(2), vidRes(1), nBands);    
end

Contact us