-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrealVideo.m
77 lines (65 loc) · 1.77 KB
/
realVideo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function realVideo()
% Define frame rate
NumberFrameDisplayPerSecond=10;
% Open figure
hFigure=figure(1);
% Set-up webcam video input
try
% For windows
vid = videoinput('integrated', 1);
catch
try
% For macs.
vid = videoinput('macvideo', 1);
catch
errordlg('No webcam available');
end
end
% Set parameters for video
% Acquire only one frame each time
set(vid,'FramesPerTrigger',1);
% Go on forever until stopped
set(vid,'TriggerRepeat',Inf);
% Get a grayscale image
set(vid,'ReturnedColorSpace','grayscale');
triggerconfig(vid, 'Manual');
% set up timer object
TimerData=timer('TimerFcn', {@FrameRateDisplay,vid},'Period',1/NumberFrameDisplayPerSecond,'ExecutionMode','fixedRate','BusyMode','drop');
% Start video and timer object
start(vid);
start(TimerData);
% We go on until the figure is closed
uiwait(hFigure);
% Clean up everything
stop(TimerData);
delete(TimerData);
stop(vid);
delete(vid);
% clear persistent variables
clear functions;
% This function is called by the timer to display one frame of the figure
function FrameRateDisplay(obj, event,vid)
persistent IM;
persistent handlesRaw;
persistent handlesPlot;
trigger(vid);
IM=getdata(vid,1,'uint8');
if isempty(handlesRaw)
% if first execution, we create the figure objects
subplot(2,1,1);
handlesRaw=imagesc(IM);
title('CurrentImage');
% Plot first value
Values=mean(IM(:));
subplot(2,1,2);
handlesPlot=plot(Values);
title('Average of Frame');
xlabel('Frame number');
ylabel('Average value (au)');
else
% We only update what is needed
set(handlesRaw,'CData',IM);
Value=mean(IM(:));
OldValues=get(handlesPlot,'YData');
set(handlesPlot,'YData',[OldValues Value]);
end