Hướng dẫn kết nối camera với Matlabmột số câu lệnh sử dụng để kết nối với camera trong Matlabkhiển camera bằng Matlabcamvacamva(view_angle)camva(mode)camva(auto)camva(manual)camva(axes_handle,...)videoinput(adaptorname, deviceID)
Trang 1Set or query camera view angle
Syntax
camva
camvăview_angle)
camvắmodé)
camvắautó)
camvắmanual')
camvăaxes_handle, )
Description
camva returns the camera view angle setting in the current axes The camera view angle
determines the field of view of the camerạ Larger angles produce a smaller view of the scenẹ Implement zooming by changing the camera view anglẹ
camvăview_angle) sets the view angle in the current axes to the specified valuẹ Specify the view angle in degrees.
camvắmodé) returns the current value of the camera view angle mode, which can be either
auto (the default) or manual.
camvắautó) sets the camera view angle mode to auto
camvắmanual') sets the camera view angle mode to manual.
camvăaxes_handle, ) performs the set or query on the axes identified by the first argument,
axes_handle When you do not specify an axes handle, camva operates on the current axes.
Tips
The camva function sets or queries values of the axes object CameraViewAngle and
CameraViewAngleMode properties.
When the camera view angle mode is auto, the camera view angle adjusts so that the scene fills the available space in the window If you move the camera to a different position, the camera view angle changes to maintain a view of the scene that fills the available area in the window Setting a camera view angle or setting the camera view angle to manual disables the MATLAB stretch-to-fill feature (stretching of the axes to fit the window) This means setting the camera view angle to its current value,
camvăcamva)
can cause a change in the way the graph looks See axes for more information.
Examples
Create two pushbuttons, one that zooms in and another that zooms out:
% Set the range checking in the callback statements to keep
% the values for the camera view angle in the range greater
% than zero and less than 180
uicontrol('Stylé,'pushbutton',
'String','Zoom In',
'Position',[20 20 60 20],
'Callback','if camva <= 1;return;else;camvăcamva-1);end');
uicontrol('Stylé,'pushbutton',
'String','Zoom Out',
'Position',[100 20 60 20],
'Callback','if camva >= 179;return;else;camvăcamva+1);end');
% Now create a graph to zoom in and out on:
surf(peaks);
Trang 2how to interface a digital camera with MATLAB for real time image processing
Step 1: Set up a video Object:
Create and video object using the" videoinput()" function like so:
videoObj = videoinput(adaptorname, deviceID);
(you can find the adaptor name and device ID by plugging in your device and typing imaqtool into the command window and you will see the adaptor name and the device ID listed beside the device's name
in the hardware browser)
Next, the amount of frames captured per trigger must be configured The set() function can be used for this
set(videoObj, 'FramesPerTrigger', N);
where N is the amount of frames captured every time the camera is triggered
Next, the number of times the camera can be triggered must be configured The set() function can be used for this
set(videoObj, 'TriggerRepeat', N);
where N is the number of times the camera can be triggered (use inf for infinite triggers)
Next, the trigger type must be set The triggerconfig() function can be used for this
triggerconfig(videoObj, triggertype);
where triggertype can be 'manual' for manual triggering 'immediate' for triggering once the start function (explained later) is used or 'hardware' if some external hardware source is to trigger the camera (the trigger condition must also be configured if this is chosen)
Finally for Step 1, for example, if I were to create a video object for my integrated webcam which I want
to manually trigger and I want one frame per trigger I would use:
videoObj = videoinput('winvideo',1);
set(videoObj, 'FramesPerTrigger', 1);
set(videoObj, 'TriggerRepeat', inf);
triggerconfig(videoObj, 'manual');
This should probably be sufficient for most purposes However do look up the functions I've mentioned
Trang 3above should you need to do more configuring
Your object is now set up
Step 2: Open the object
Before you can use the object it must be opened The start() function can be used for this
start(videoObj);
the object is now open
Step 3: Trigger camera
The camera can now be trigged which will capture the image(s) The trigger() function can be used for this
trigger(videoObj);
Step 4: Processing etc
Do processing on the captured image(s)
Step 5: Repeat
Repeat steps 3 & 4 as needed
Step 6: Close object
When done with the camera close the object by using the stop() function
stop(videoObject);
Hope this helps