Home > simulink > gcamera.m

gcamera

PURPOSE ^

GCAMERA graphical camera model

SYNOPSIS ^

function ovar = gcamera(a1, a2, a3, a4)

DESCRIPTION ^

GCAMERA    graphical camera model

    H = GCAMERA(NAME, C, DIMS)

    Create a graphical camera with name NAME, pixel dimensions given by 
    DIMS = [xmin xmax ymin ymax] for the axes, and calibration matrix C.

  Returns H, the handle to the graphical camera.

  Once created update the camera's view with

    uv = GCAMERA(H, POINTS)
    uv = GCAMERA(H, POINTS, Tobj)
    uv = GCAMERA(H, POINTS, Tobj, Tcam)

  where H is the handle previously returned, and POINTS is the data to be
 displayed.  POINTS represents the 3D data to be displayed in the camera
 view.  If POINTS has 3 columns it is treated as a number of 3D points in
 world coordinates, one point per row.  Each point is transformed and displayed
 as a round marker.  If POINTS has 6 columns, each row is treated as the start
 and end 3D coordinate for a line segment, in world coordinates.  Each end of 
 the line is transformed and a line segment displayed.
 The optional arguments, Tobj, represents a transformation that can be applied
 to the object data, POINTS, prior to 'imaging'.  Tcam is the pose of the
 camera which defaults to the orign looking along the Z-axis.

    Copyright (c) Peter Corke, 1999  Machine Vision Toolbox for Matlab

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %GCAMERA    graphical camera model
0002 %
0003 %    H = GCAMERA(NAME, C, DIMS)
0004 %
0005 %    Create a graphical camera with name NAME, pixel dimensions given by
0006 %    DIMS = [xmin xmax ymin ymax] for the axes, and calibration matrix C.
0007 %
0008 %  Returns H, the handle to the graphical camera.
0009 %
0010 %  Once created update the camera's view with
0011 %
0012 %    uv = GCAMERA(H, POINTS)
0013 %    uv = GCAMERA(H, POINTS, Tobj)
0014 %    uv = GCAMERA(H, POINTS, Tobj, Tcam)
0015 %
0016 %  where H is the handle previously returned, and POINTS is the data to be
0017 % displayed.  POINTS represents the 3D data to be displayed in the camera
0018 % view.  If POINTS has 3 columns it is treated as a number of 3D points in
0019 % world coordinates, one point per row.  Each point is transformed and displayed
0020 % as a round marker.  If POINTS has 6 columns, each row is treated as the start
0021 % and end 3D coordinate for a line segment, in world coordinates.  Each end of
0022 % the line is transformed and a line segment displayed.
0023 % The optional arguments, Tobj, represents a transformation that can be applied
0024 % to the object data, POINTS, prior to 'imaging'.  Tcam is the pose of the
0025 % camera which defaults to the orign looking along the Z-axis.
0026 %
0027 %    Copyright (c) Peter Corke, 1999  Machine Vision Toolbox for Matlab
0028 
0029 % Peter Corke 1996
0030 
0031 function ovar = gcamera(a1, a2, a3, a4)
0032     if isstr(a1),
0033         % creating a new camera
0034         name = a1;
0035         name
0036         C = a2;
0037         %dimcheck(C, 'calibration matrix', 3, 4);
0038         dims = a3;
0039         %dimcheck(dims, 'pixel dimensions', 4);
0040 
0041         h = findobj('Name', name);
0042         if isempty(h),
0043             h = figure;
0044             set(h, 'Name', name);
0045             set(h, 'NextPlot', 'new');
0046         else
0047             figure(h)
0048             clf
0049         end
0050         ovar = axes('XLim', dims(1:2), 'YLim', dims(3:4), ...
0051              'UserData', C, ...
0052             'Xgrid', 'on', 'Ygrid', 'on', 'Ydir' , 'reverse', 'NextPlot', 'new');
0053         %line('LineStyle', 'o', 'Color', 'black');
0054         line('LineStyle', 'none', ...
0055             'Marker', 'o', ...
0056             'Color', 'black', ...
0057             'EraseMode', 'xor');
0058         title(name);
0059     else
0060         h = a1;
0061         points = a2;
0062         nc = numcols(points);
0063         C = get(h, 'UserData');
0064         switch nargin,
0065         case 4,
0066             Tcam = a4;
0067             Tobj = a3;
0068         case 3,
0069             Tobj = a3;
0070             Tcam = eye(4);
0071         otherwise,
0072             Tobj = eye(4);
0073             Tcam = eye(4);
0074         end
0075         if nc == 3,
0076             % draw points
0077             uv = camera(C, points, Tobj, Tcam);
0078             ovar = uv;
0079             l = get(h, 'Children');
0080             set(l, 'Xdata', uv(:,1), 'Ydata', uv(:,2));
0081         elseif nc == 6,
0082             % draw lines
0083             uv_s = camera(C, points(:,1:3), Tobj, Tcam);
0084             uv_f = camera(C, points(:,4:6), Tobj, Tcam);
0085             ovar = [uv_s uv_f];
0086             for c = get(h, 'Children')',
0087                 delete(c);
0088             end
0089             line([uv_s(:,1)'; uv_f(:,1)'], ...
0090                 [uv_s(:,2)'; uv_f(:,2)'], ...
0091                 'EraseMode', 'xor', ...
0092                 'LineStyle', '-');
0093         else
0094             error('Points matrix should be 3 or 6 columns');
0095         end
0096     end

Generated on Sun 15-Feb-2009 18:09:29 by m2html © 2003