pysdic.Camera.visualize_projected_mesh#

Camera.visualize_projected_mesh(mesh, vertices_color='black', vertices_size=5, vertices_opacity=1.0, edges_color='black', edges_width=1, edges_opacity=1.0, faces_color='red', faces_opacity=0.5, image=None, clip_sensor=True, show_pixel_grid=False, show_vertices=True, show_edges=True, show_faces=True, title=None)[source]#

Visualize the projected 2D mesh of a Mesh on a 2D plot using matplotlib.

See also

Parameters:
  • mesh (Mesh) – The 3D mesh to visualize.

  • vertices_color (str, optional) – The color of the mesh vertices (default is "black").

  • vertices_size (int, optional) – The size of the mesh vertices (default is 5).

  • vertices_opacity (float, optional) – The opacity of the mesh vertices (default is 1.0).

  • edges_color (str, optional) – The color of the mesh edges (default is "black").

  • edges_width (int, optional) – The width of the mesh edges (default is 1).

  • edges_opacity (float, optional) – The opacity of the mesh edges (default is 1.0).

  • faces_color (str, optional) – The color of the mesh faces (default is "red").

  • faces_opacity (float, optional) – The opacity of the mesh faces (default is 0.5).

  • image (Optional[Union[numpy.ndarray, Image]], optional) – An image to display as the background (default is None).

  • clip_sensor (bool, optional) – Whether to clip points outside the sensor dimensions (default is True).

  • show_pixel_grid (bool, optional) – Whether to show the pixel grid on the image (default is False).

  • show_vertices (bool, optional) – Whether to show the mesh vertices (default is True).

  • show_edges (bool, optional) – Whether to show the mesh edges (default is True).

  • show_faces (bool, optional) – Whether to show the mesh faces (default is True).

  • title (Optional[str], optional) – An optional title for the plot. Default is None with default title ‘Projected Mesh on Image Plane’.

Return type:

None

Examples

Visualize a projected Mesh using a simple camera:

import numpy
from pysdic import Camera
from pycvcam import Cv2Extrinsic, Cv2Intrinsic
from pysdic import Mesh

rotation_vector = numpy.array([0.1, 0.2, 0.3])
translation_vector = numpy.array([12.0, 34.0, 56.0])

extrinsic = Cv2Extrinsic.from_rt(rotation_vector, translation_vector)

intrinsic = Cv2Intrinsic.from_matrix(
    numpy.array([[1000, 0, 320],
                [0, 1000, 240],
                [0, 0, 1]])
)

camera = Camera(
    sensor_height=480,
    sensor_width=640,
    intrinsic=intrinsic,
    extrinsic=extrinsic,
)

# Define a simple triangle mesh
vertices = numpy.array([
    [0, 0, 1000],
    [100, 0, 1000],
    [50, 100, 1000],
    [0, 100, 1000]
])
connectivity = numpy.array([
    [0, 1, 2],
    [0, 2, 3]
])
mesh = Mesh(vertices=vertices, connectivity=connectivity)

# Visualize the projected mesh
camera.visualize_projected_mesh(mesh=mesh, faces_color="blue", edges_color="black", vertices_color="red")
Visualize Projected Mesh Example

Example of projected mesh visualization. This figure shows the 2D projection of the 3D mesh onto the image plane.#