www.gusucode.com > vision 源码程序 matlab案例代码 > vision/SystemObjectDesignVision1StepCreateConfigTunableExample.m

    %% Tunable Edge Detection System Design with System Objects
% This example shows how to create a system that finds the edges of objects
% in a video stream, using System objects. System objects are components 
% you can use to create your system in MATLAB. 
%% Create and Configure Components at the Same Time  
% This section of the example shows how to create your System object(TM) 
% components and configure the desired properties at the same time. Specify
% each property with a |'Name'|,|Value| argument pair. 
%
% For the video file reader object, specify the file to read and set the
% image color space. 
% 
% For the alpha blender object, specify the type of operation to use. 
% 
% For the video player objects, specify the names, the window size, and
% the window position. 
hVideoSrc = vision.VideoFileReader('vipmen.avi', ...
     'ImageColorSpace', 'Intensity');  

hAB = vision.AlphaBlender('Operation', 'Highlight selected pixels');  

WindowSize = [190 150];
hVideoOrig = vision.VideoPlayer('Name', 'Original',...
    'Position',[10 100 WindowSize]);

hVideoEdges = vision.VideoPlayer('Name', 'Edges',...
    'Position',[210 100 WindowSize]);

hVideoOverlay = vision.VideoPlayer('Name', 'Overlay',...
    'Position',[410 100 WindowSize]);
%% Change a Tunable Property in Your System
% You can change the threshold value as your code is running by modifying an
% object property. This example modifies the |Location| property of the 
% |AlphaBlender| object. The change takes effect the next time the object 
% runs (in this case, at the next iteration of the while loop). 
while ~isDone(hVideoSrc)
    frame     = step(hVideoSrc);               % Read input video
    edges     = edge(frame,'Prewitt',15/256);  % Edge detection
    composite = hAB(frame,edges);              % AlphaBlender

    hAB.Location(1) = hAB.Location(1)+1;       % Offset edges 
    if (hAB.Location(1)==120) 
        hAB.Location = [1 1];                  % wrap
    end
    
    hVideoOrig(frame);                         % Display original
    hVideoEdges(edges);                        % Display edges
    hVideoOverlay(composite);                  % Display edges overlaid
end