Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

plotCamera

Plot a camera in 3-D coordinates

Syntax

cam = plotCamera()
cam = plotCamera(cameraTable)
cam = plotCamera(Name,Value)

Description

example

cam = plotCamera() creates a camera visualization object rendered in the current axes.

example

cam = plotCamera(cameraTable) returns an array of camera visualization objects rendered in the current axes.

example

cam = plotCamera(Name,Value) creates a camera visualization object with the property values specified by one or more Name,Value pair arguments.

Examples

collapse all

Plot a camera pointing along the y-axis.

    R = [1     0     0;
         0     0    -1;
         0     1     0];

Set the opacity of the camera to zero for faster animation.

    cam = plotCamera('Location',[10 0 20],'Orientation',R,'Opacity',0);

Set the view properties.

    grid on
    axis equal
    axis manual

Make the space large enough for the animation.

    xlim([-15,20]);
    ylim([-15,20]);
    zlim([15,25]);

Rotate the camera about the camera's y-axis.

    for theta = 0:pi/64:10*pi
        T = [cos(theta)  0  sin(theta);
                0        1      0;
             -sin(theta) 0  cos(theta)];
        cam.Orientation = T * R;
        cam.Location = [10 * cos(theta),10 * sin(theta),20];
        drawnow();
    end

Create a set of calibration images.

images = imageSet(fullfile(toolboxdir('vision'),'visiondata',...
    'calibration','slr'));

Detect the checkerboard corners in the images.

[imagePoints, boardSize] = detectCheckerboardPoints(images.ImageLocation);

Generate the world coordinates of the checkerboard corners in the pattern-centric coordinate system, with the upper-left corner at (0,0). Set the square size to 29 mm.

squareSize = 29;
worldPoints = generateCheckerboardPoints(boardSize,squareSize);

Calibrate the camera.

cameraParams = estimateCameraParameters(imagePoints,worldPoints);

Load an image at its new location.

imOrig = imread(fullfile(toolboxdir('vision'),'visiondata',...
    'calibration','slr','image9.jpg'));
figure; imshow(imOrig,'InitialMagnification',50);
title('Input Image');

Undistort the image.

im = undistortImage(imOrig,cameraParams);

Find the reference object in the new image.

[imagePoints,boardSize] = detectCheckerboardPoints(im);

Compute the new extrinsics.

[rotationMatrix,translationVector] = extrinsics(imagePoints,...
    worldPoints,cameraParams);

Plot the world points.

figure;
plot3(worldPoints(:,1),worldPoints(:,2),zeros(size(worldPoints, 1),1),'*');
hold on

Mark the origin.

plot3(0,0,0,'g*');

Compute the camera location and orientation.

orientation = rotationMatrix';
location = -translationVector * orientation;

Plot the camera.

cam = plotCamera('Location',location,'Orientation',orientation,'Size',20);

Make the z -axis point down.

set(gca,'CameraUpVector',[0 0 -1]);

Set the view parameters.

camorbit(gca,-110,60,'data',[0 0 1]);
axis equal
grid on

Turn on 3-D rotation.

cameratoolbar('SetMode','orbit');

Label the axes.

xlabel('X (mm)');
ylabel('Y (mm)');
zlabel('Z (mm)');

Input Arguments

collapse all

Camera visualization object properties, specified as a table. The columns contain the Name,Value properties of the camera visualization object except for Parent, which specifies the axes for display. If the table contains a 'ViewId' column, then the view IDs are used as camera labels.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Location', [0,0,0]

collapse all

Camera location coordinates, specified as the comma-separated pair consisting of 'Location' and a three-element vector. The [x, y, z] coordinates are specified in the data units of the parent axes.

Matrix orientation, specified as the comma-separated pair consisting of 'Orientation' and a 3-by-3 3-D rotation matrix.

Camera base width, specified as the comma-separated pair consisting of 'Size' and a scalar.

Camera label, specified as the comma-separated pair consisting of 'Label' and a character vector.

Camera color, specified as the comma-separated pair consisting of 'Color' and a character vector or a three-element vector of RGB values in the range [0 1]. See colorspec for more information on how to specify an RGB color.

Camera opacity, specified as the comma-separated pair consisting of 'Opacity' and a scalar in the range [0 1].

Camera visibility, specified as the comma-separated pair consisting of 'Visible' and the logical true or false.

Camera axes visibility, specified as the comma-separated pair consisting of 'AxesVisible' and the logical true or false.

Callback function, specified as the comma-separated pair consisting of 'ButtonDownFcn' and a function name that executes when you click the camera.

Output axes, specified as the comma-separated pair consisting of 'Parent' and an axes handle. The default is set to the current axes handle, gca.

Introduced in R2015a