-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebcam1.m
More file actions
105 lines (91 loc) · 4.17 KB
/
webcam1.m
File metadata and controls
105 lines (91 loc) · 4.17 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function out = webcam1
%IMAQTOOLBOX_WEBCAM Code for creating a video input object.
%
% This is the machine generated representation of a video input object.
% This MATLAB code file, IMAQTOOLBOX_WEBCAM.M, was generated from the OBJ2MFILE function.
% A MAT-file is created if the object's UserData property is not
% empty or if any of the callback properties are set to a cell array
% or to a function handle. The MAT-file will have the same name as the
% code file but with a .MAT extension. To recreate this video input object,
% type the name of the code file, imaqToolbox_webcam, at the MATLAB command prompt.
%
% The code file, IMAQTOOLBOX_WEBCAM.M and its associated MAT-file, IMAQTOOLBOX_WEBCAM.MAT (if
% it exists) must be on your MATLAB path.
%
% Example:
% vidobj = imaqToolbox_webcam;
%
% See also VIDEOINPUT, IMAQDEVICE/PROPINFO, IMAQHELP, PATH.
%
% Check if we can check out a license for the Image Acquisition Toolbox.
canCheckoutLicense = license('checkout', 'Image_Acquisition_Toolbox');
% Check if the Image Acquisition Toolbox is installed.
isToolboxInstalled = exist('videoinput', 'file');
if ~(canCheckoutLicense && isToolboxInstalled)
% Toolbox could not be checked out or toolbox is not installed.
error(message('imaq:obj2mfile:invalidToolbox'));
end
% Load the MAT-file containing UserData and CallBack property values.
try
MATvar = load('C:\Users\Dhruv Joshi\Documents\Srujana\Pupil-Tracking\imaqToolbox_webcam');
MATLoaded = true;
catch
warning(message('imaq:obj2mfile:MATload'));
MATLoaded = false;
end
% Device Properties.
adaptorName = 'winvideo';
deviceID = 1;
vidFormat = 'MJPG_640x480';
tag = '';
% Search for existing video input objects.
existingObjs1 = imaqfind('DeviceID', deviceID, 'VideoFormat', vidFormat, 'Tag', tag);
if isempty(existingObjs1)
% If there are no existing video input objects, construct the object.
vidObj1 = videoinput(adaptorName, deviceID, vidFormat);
else
% There are existing video input objects in memory that have the same
% DeviceID, VideoFormat, and Tag property values as the object we are
% recreating. If any of those objects contains the same AdaptorName
% value as the object being recreated, then we will reuse the object.
% If more than one existing video input object contains that
% AdaptorName value, then the first object found will be reused. If
% there are no existing objects with the AdaptorName value, then the
% video input object will be created.
% Query through each existing object and check that their adaptor name
% matches the adaptor name of the object being recreated.
for i = 1:length(existingObjs1)
% Get the object's device information.
objhwinfo = imaqhwinfo(existingObjs1{i});
% Compare the object's AdaptorName value with the AdaptorName value
% being recreated.
if strcmp(objhwinfo.AdaptorName, adaptorName)
% The existing object has the same AdaptorName value as the
% object being recreated. So reuse the object.
vidObj1 = existingObjs1{i};
% There is no need to check the rest of existing objects.
% Break out of FOR loop.
break;
elseif(i == length(existingObjs1))
% We have queried through all existing objects and no
% AdaptorName values matches the AdaptorName value of the
% object being recreated. So the object must be created.
vidObj1 = videoinput(adaptorName, deviceID, vidFormat);
end %if
end %for
end %if
% Configure properties whose values are saved in C:\Users\Dhruv Joshi\Documents\Srujana\Pupil-Tracking\imaqToolbox_webcam.mat.
if (MATLoaded)
% MAT-file loaded successfully. Configure the properties whose values
% are saved in the MAT-file.
set(vidObj1, 'ErrorFcn', MATvar.errorfcn1);
else
% MAT-file could not be loaded. Configure properties whose values were
% saved in the MAT-file to their default value.
set(vidObj1, 'ErrorFcn', @imaqcallback);
end
% Configure vidObj1 properties.
set(vidObj1, 'FramesPerTrigger', 1);
% Configure vidObj1's video source properties.
srcObj1 = get(vidObj1, 'Source');
out = vidObj1 ;