www.gusucode.com > vision 源码程序 matlab案例代码 > vision/SystemObjectDesignVisionExample.m
%% 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 Components for Your System % This section of the example shows how to set up your system. The predefined % components you need are: % % * |vision.VideoFileReader| — Read the file of video data % * |vision.AlphaBlender| — Overlay edges onto the original video images % * |vision.VideoPlayer| — Play the video % % The example uses a function for edge detection. % First, create the component objects, using default property settings. % Create three |VideoPlayer| objects. One to play the original video, one % to play the edges, and one to show the edges overlaid on the original video. hVideoSrc = vision.VideoFileReader; hAB = vision.AlphaBlender; hVideoOrig = vision.VideoPlayer; hVideoEdges = vision.VideoPlayer; hVideoOverlay = vision.VideoPlayer; %% Configure Component Property Values % This section of the example shows how to configure the components for % your system by setting the component objects’ properties. % % Use this procedure if you have created your components separately from % configuring them. You can also create and configure your components % at the same time, as described in a later example. % % 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.Filename = 'vipmen.avi'; hVideoSrc.ImageColorSpace = 'Intensity'; hAB.Operation = 'Highlight selected pixels'; WindowSize = [190 150]; hVideoOrig.Name = 'Original'; hVideoOrig.Position = [10 hVideoOrig.Position(2) WindowSize]; hVideoEdges.Name = 'Edges'; hVideoEdges.Position = [210 hVideoOrig.Position(2) WindowSize]; hVideoOverlay.Name = 'Overlay'; hVideoOverlay.Position = [410 hVideoOrig.Position(2) WindowSize]; %% Connect Components in a System % This section shows how to connect the components together to read the % file, detect edges, form a composite image, and display the video data. % The while loop uses the |isDone| method to read through the entire file. % The |step| method is used on each object inside the loop. while ~isDone(hVideoSrc) frame = hVideoSrc(); % Read input video edges = edge(frame,'Prewitt',15/256); % Edge detection composite = hAB(frame,edges); % AlphaBlender hVideoOrig(frame); % Display original hVideoEdges(edges); % Display edges hVideoOverlay(composite); % Display edges overlaid end release(hVideoSrc);