test.m

来自「1394 接口视觉工具箱 (英文工具箱」· M 代码 · 共 120 行

M
120
字号
% test program to continiously capture pictures from the camera and process
% it using 'CMVISION'
%
% try..
% >> test
%
% ... or
%
% >> test(2, 100, 100, 50, 200)

function test(varargin)

supportedModes = { ...
	'YUV444 (160x120, 30 fps)', ...
	'YUV422 (320x240, 30 fps)', ...
	'YUV411 (640x480, 30 fps)', ...
	'YUV422 (640x480, 15 fps)', ...
	'RGB8 (640x480, 15 fps)', ...
	'Y8 (640x480, 30 fps)', ...
	'Y16 (640x480, 15 fps)' ...
    };

% defaults
mode = 2;                       % default mode: YUV411 (640x320, 30 fps)
fname = 'testcolors.txt';       % default filename
scan4col = [];                  % first colour only
myWidth  = -1;                  % default width (max)
myHeight = -1;                  % default height (max)
myOrigX  = -1;                  % default origin-x (0)
myOrigY  = -1;                  % default origin-y (0)

if(isempty(varargin))
    disp('Image type not specified - using YUV as the default');
elseif(nargin == 1 && isnumeric(varargin{1}))
    mode = varargin{1};
elseif(nargin == 3 && isnumeric(varargin{1}) && isnumeric(varargin{2}) && isnumeric(varargin{3}))
    mode = varargin{1};
    myWidth  = varargin{2};
    myHeight = varargin{3};
elseif(nargin == 5 && isnumeric(varargin{1}) && isnumeric(varargin{2}) && isnumeric(varargin{3}) ...
                                             && isnumeric(varargin{4}) && isnumeric(varargin{5}))
    mode = varargin{1};
    myWidth  = varargin{2};
    myHeight = varargin{3};
    myOrigX  = varargin{4};
    myOrigY  = varargin{5};
end

if(mode == -1)
    
    % switch camera off
    capProc(-1);
    
else

    % ensure we can exit from the while(1) loop gracefully...
    figure
    evalin('base', 'run = 1;');
    set(gcf, 'CloseRequestFcn', 'evalin(''base'', ''run = 0;'');');

    run = 1;
    while(run)
        
        try
            % verbosity: on (4th call-up parameter)
            [out, R] = capProc(mode, fname, scan4col, 1, myWidth, myHeight, myOrigX, myOrigY);
        catch
            % catch driver errors (e.g. unsupported modes)
            set(gcf, 'CloseRequestFcn', 'closereq');
            close all
            rethrow(lasterror)
        end

        % display image
        image(R);
        axis image
        
        % tell the user what to do (eg. ALT+F4 to exit)
        title(['MODE: ' supportedModes{mode+1} ' -- Close figure window to exit (e.g. ALT+F4)'])
        
        % analyse & display regions
        if(~isempty(out))				% no regions detected
            hold on;

            nCol = length(out);		% number of colours with valid regions
            for(j = 1:nCol)
                kk = out(j).nRegions;
                col = out(j).Colour;
                while(kk)
                    cx = out(j).Regions(1,kk);		% centroid
                    cy = out(j).Regions(2,kk);
                    x1 = out(j).Regions(3,kk);		% boundary box
                    y1 = out(j).Regions(4,kk);
                    x2 = out(j).Regions(5,kk);
                    y2 = out(j).Regions(6,kk);
                    % disp(['x1 = ' num2str(x1) ', x2 = ' num2str(x2) ', y1 = ' num2str(y1) ', y2 = ' num2str(y2)])
                    patch([x1 x2 x2 x1], [y1 y1 y2 y2], col);
                    plot(cx, cy, 'w*');
                    kk = kk - 1;
                end
            end

            hold off
        end

        drawnow
        
        % fetch 'run' from 'base' WS
        run = evalin('base', 'run');
        
    end

end

% switch camera off...
capProc(-1);
set(gcf, 'CloseRequestFcn', 'closereq');
close all

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?