MATLAB Answers

How visualize camera field of view

64 views (last 30 days)
1) Is there a way to visualize field of view (fov) of a camera view using "plotCamera" command or any other built-in function in MATLAB? In essence, I want to plot a camera with a given pose and then visualize its fov: 60° horiz x 49.5° vert. (73° diagonal) using a pyramid.
2) Is there a way to use Simscape Multibody and get the simulated camera view when the pose and fov of a camera is defined? For example, I want to include a SolidWorks CAD model into simscape and demonstrated how it could be viewed using a particular camera place with different poses.
Your advice is highly appreciated. Many thanks in advance.


Sign in to comment.

Accepted Answer

Steve Miller
Steve Miller on 9 Mar 2018
For your first question, you could use a semitransparent solids to visualize field of view. That could be a solid pyramid or just a flat area (thin rectangle).
For your second question, you can define cameras within the Mechanics Explorer. The location and orientation of the camera can change during the animation of the simulation results, and those results can be exported to a video.
See Camera Manager in the documentation.
Below is an example of an animation exported from the Simscape Multibody Mechanics Explorer with a dynamic camera. The camera can also be configured to track the box, always keeping it in the center of the frame. This example is available on the File Exchange: Robot Arm with Conveyor Belts.


Randika Vithanage
Randika Vithanage on 12 Mar 2018
That helps. Many thanks Miller.
Aditya on 2 Sep 2020
Is there a command line API for the Camera Manager? It would be interesting to be able to set camera tracking based on a given test. I don't see any mention of this in the doc for 2019b or 2020a. Thanks.
Steve Miller
Steve Miller on 2 Sep 2020
There isn't a command line API for the Camera Manager.
Programmatically setting the camera is possible, but here is a workaround you can try...
  • Configure the Mechanics Explorer as you want it for test 1
  • Obtain the XML string that describes the configuration of the camera
camera_test1 = get_param(bdroot,'InternalSimMechanicsExplorerSettings');
  • Configure the Mechanics Explorer for the second test, and obtain that XML string
camera_test2 = get_param(bdroot,'InternalSimMechanicsExplorerSettings');
  • Save those to disk - you will need them for later sessions
save camera_setttings camera_test1 camera_test2
  • Close your model
  • Reopen your model
  • BEFORE you open the Mechanics Explorer, apply your camera setting
I have not found a way to programmatically apply visualization settings without closing the model first. I used this workaround to programmatically generate videos for various tests from different viewpoints. We are working on more options for configuring the camera.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!