Main Content

drawImageAxesLabels

Display location and orientation of axes labels

Description

example

[originLabel,xLabel,yLabel] = drawImageAxesLabels(detectorObj,imagePoints) displays the orientation and location of the origin originLabel and the X- and Y-axis labels xLabel and yLabel of the circle grid pattern detected in the images rendered in the Camera Calibrator and Stereo Camera Calibrator apps.

If you do not implement this function, or if the returned values are empty, then the function does not render origin or axes labels in the image.

Examples

collapse all

Use the drawImageAxesLabels function to identify and label the orientation and location for the origin and the X- and Y-axis labels of a detected pattern grid in an image. For example:

Labeled checkerboard showing origina and x- and y- directions.

Use this function template, which includes the use of the drawImageAxesLabels object function, to calculate the orientation and location of the origin of the detected calibration pattern in an image. The function omits the X- and Y-labels. The function includes both programmatic and app workflows for detecting the points.

function [originLabel,xLabel,yLabel] = drawImageAxesLabels(this,imagePoints) 
    
    numBoardRows = this.BoardSize(1) - 1;
    numBoardCols = this.BoardSize(2) - 1;
    
    % Reshape checkerboard corners to boardSize-shaped array
    boardCoordsX = reshape(imagePoints(:,1),[numBoardRows numBoardCols]);
    boardCoordsY = reshape(imagePoints(:,2),[numBoardRows numBoardCols]);
    boardCoords = cat(3,boardCoordsX,boardCoordsY);
    
    % Origin label (check if the origin location is inside the image)
    if ~isnan(boardCoordsX(1,1))
        p1 = boardCoords(1,1,:);
        
        refPointIdx = find(~isnan(boardCoordsX(:,1)),2);
        p2 = boardCoords(refPointIdx(2),1,:);
        
        refPointIdx = find(~isnan(boardCoordsX(1,:)),2);
        p3 = boardCoords(1,refPointIdx(2),:);
        
        [loc, theta] = getAxesLabelPosition(p1,p2,p3);
        
        originLabel.Location = loc;
        originLabel.Orientation = theta;
    else
        originLabel = struct;
    end
    
    % X-axis and Y-axis labels
    xLabel = struct('Orientation',[],'Location',[]);
    yLabel = struct('Orientation',[],'Location',[]);
    
    %--------------------------------------------------------------
    % p1+v
    %  \
    %   \     v1
    %    p1 ------ p2
    %    |
    % v2 |
    %    |
    %    p3
    function [loc, theta] = getAxesLabelPosition(p1,p2,p3)
        v1 = p3 - p1;
        theta = -atan2d(v1(2),v1(1));
        
        v2 = p2 - p1;
        v = -v1 - v2;
        d = hypot(v(1),v(2));
        minDist = 40;
        if d < minDist
            v = (v/d) * minDist;
        end
        loc = p1 + v;
    end
end

Calibration pattern with labeled origin

Input Arguments

collapse all

Detector object, specified as a single or stereo vision.calibration.PatternDetector object.

Image coordinates of the detected circle grid, returned as an M-by-2 array of x,y coordinates.

Output Arguments

collapse all

Orientation and location of the pattern origin label, returned as a structure with two fields. The Orientation field contains the rotation of the origin label in the image frame, specified in degrees. The Location field contains the x,y location of the origin label in the image frame.

Orientation and location of the X-axis label, returned as a structure with two fields. The Orientation field contains the rotation of the axis label in the image frame, specified in degrees. The Location field contains the x,y location of the axis label in the image frame.

Orientation and location of the Y-axis label, returned as a structure with two fields. The Orientation field contains the rotation of the axis label in the image frame, specified in degrees. The Location field contains the x,y location of the axis label in the image frame.

Version History

Introduced in R2021b