Plot a camera in 3-D coordinates
plots a default
camera in 3-D coordinates in the current axes. The function returns
cam = plotCameracam, a Camera object that contains
the properties of the plotted camera.
plots one or more cameras specified by cam = plotCamera(cameraTable)cameraTable.
specifies options using one or more name-value pair arguments. For example,
cam = plotCamera(Name,Value)'Opacity',0.4 sets the opacity of the
plotted camera to 0.4.
The name-value pair arguments set the associated properties of the plotted camera visualization object.
Create a rigid3d object.
R = [1 0 0; 0 0 -1;0 1 0]; t = [10 0 20]; pose = rigid3d(R,t);
Plot a camera with an opacity of zero and an absolute pose based on the created rigid3d object.
cam = plotCamera('AbsolutePose',pose,'Opacity',0)
cam =
Camera with properties:
Parent: [1x1 Axes]
Size: 1
AbsolutePose: [1x1 rigid3d]
Visible: 1
AxesVisible: 0
ButtonDownFcn: ''
Color: [1 0 0]
Opacity: 0
Label: ''
Set viewing properties for the current axes.
grid on axis equal axis manual
Expand the viewable limits of each axis. These changes enable the entire animation to be visible in the next step.
xlim([-15 20]); ylim([-15 20]); zlim([15 25]);
Rotate the camera around the y-axis.
for theta = 0:pi/64:10*pi T = [cos(theta) 0 sin(theta);0 1 0;-sin(theta) 0 cos(theta)]; cam.AbsolutePose = rigid3d(T * R, [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.
absPose = rigid3d(orientation,location); cam = plotCamera('AbsolutePose',absPose,'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)');

cameraTable — Properties of cameras for visualizationProperties of cameras for visualization, specified as a table. Each row
represents a single camera. Each column title must match the name-part of a
name-value pair argument. The nth-row values set the
properties for the nth element of
cam. You cannot specify values for
'Parent'. If the table contains a
'ViewId' column, then the view IDs are used to set
the 'Label' values of the cameras.
Specify optional
comma-separated pairs of Name,Value arguments. Name is
the argument name and Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN.
'Size',0.3 specifies the camera-base width as
0.3.'AbsolutePose' — Camera absolute poserigid3d objectCamera absolute pose in the world coordinate system, specified as the
comma-separated pair consisting of 'AbsolutePose' a
rigid3d object.
'Size' — Camera-base width1 (default) | positive real numberCamera-base width, specified as the comma-separated pair consisting of
'Size' and a positive real number.
'Label' — Camera label'' (default) | character vector | string scalarCamera label, specified as the comma-separated pair consisting of 'Label'
and a character vector or a string scalar.
'Color' — Camera color[1 0 0] (red) (default) | RGB tripletCamera color, specified as the comma-separated pair consisting of 'Color'
and an RGB triplet. An RGB triplet is a three-element row vector whose
elements specify the intensities of the red, green, and blue components
of the color. The intensities must be in the range [0, 1].
'Opacity' — Camera opacity0.2 (default) | scalar in the range [0,1]Camera opacity, specified as the comma-separated pair consisting of
'Opacity' and a scalar in the range
[0,1].
'Visible' — Camera visibilitytrue or
1 (default) | false or 0Camera visibility, specified as the comma-separated pair consisting of
'Visible' and a numeric or logical
1 (true) or
0 (false).
'AxesVisible' — Camera axes visibilityfalse or
0 (default) | true or 1Camera axes visibility, specified as the comma-separated pair consisting of
'AxesVisible' and a numeric or logical
1 (true) or
0 (false).
'ButtonDownFcn' — Callback function'' (default) | function handleCallback function, specified as the comma-separated pair consisting of
'ButtonDownFcn' and a function handle that
executes when you click the camera.
'Parent' — Output axesaxes handleOutput axes, specified as the comma-separated pair consisting of 'Parent'
and an axes handle. By default, plotCamera uses the
current axes handle. To return the current axes, use the
gca function.
cam — Camera visualization objectCamera object | row vector of Camera objectsCamera visualization object, returned as one of these options.
Camera object — The function returns this option when plotting
a single camera. Name-value pair arguments or
cameraTable input elements set the
corresponding Camera object
properties.
Row vector of Camera objects — The function returns this
option when plotting multiple cameras. The
nth -row values of the
cameraTable input set the properties
for the nth Camera object
in this vector.
Camera objects are created using the
vision.graphics.Camera class.
You have a modified version of this example. Do you want to open this example with your edits?