How to draw a line through a camera defined by [location, orientation] from extrinsicsToCameraPose?
2 views (last 30 days)
Show older comments
I want to visualize the FOV of a camera on a matlab plot. I have the location and orientation of the camera from the extrinsicsToCameraPose function in the CV toolbox. Now, I am trying to draw a line depicting the principal axis of the Camera. How would I go about drawing that line in 3D?
I have the following code, currently. But, I know that I am not using the orientation correctly to calculate the Y and Z points on the line.
if (isVisualize)
cam = plotCamera('Location',location,'Orientation',orientation,'Size',25);
% cam = plotCamera('Location',location,'Orientation',orientation);
grid on
axis equal
axis manual
xlim([-1600,0]);
ylim([-600,200]);
zlim([0,200]);
hold on
plot3(0,0,0,'g*');
%According to 3D line equation
clX = linspace(-1400,200);
clY = (((clX - location(1))/orientation(1)) * (orientation(2))) + location(2);
clZ = (((clX - location(1))/orientation(1)) * (orientation(3))) + location(3);
line(clX, clY, clZ)
xlabel('X (mm)');
ylabel('Y (mm)');
zlabel('Z (mm)');
end
I believe I am missing something trivial here. I would like the lines to start at the camera and end at the plane z=0.
Eventually, I also want to draw lines coming out of the corners of the Camera to visualize the Vertical FOV and Horizontal FOV. If there's an easier way to do this, I'd really appreciate it.
The following is the current output. The green * signifies the origin. The line is obviously pointing in the wrong direction.

The MATLAB figure is attached too.
EDIT 1:
The following are the location and orientation.
>> location
location =
1.0e+03 *
-1.3975 -0.3178 0.0850
>> orientation
orientation =
-0.0103 -0.9999 0.0112
-0.2542 -0.0083 -0.9671
0.9671 -0.0128 -0.2541
The orientation and location are computed using the following function from the Computer Vision Toolbox.
camMatrix = cameraMatrix(cameraParams,rotationMatrix,translationVector);
[orientation,location] = extrinsicsToCameraPose(rotationMatrix,translationVector);
3 Comments
Joshua
on 27 Jun 2017
Amit,
Yes thank you it is helpful to see. I am not super familiar with the line equation you are using, but a possible mistake could be your indexing of the orientation matrix. Using single numbers to index a two dimansional matrix orders the columns first from top to bottom, and then moves right across each column. So here are the values you are getting in you line equation.
orientation(1)=-0.0103
orientation(2)=-0.2542
orientation(3)=0.9671
Are these the locations you were intending to access? If you happen to have the equation in variable form that would be great.
Answers (0)
See Also
Categories
Find more on Desktop in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!