pysdic.compute_projected_bounding_box#

compute_projected_bounding_box(mesh, camera, *, warp_by=None, margin=0.0)[source]#

Compute the bounding box of the vertices of a mesh projected on the sensor of a camera.

The vertices of the (deformed) mesh are projected on the sensor (see pysdic.Camera.project()), and the bounding box of their finite image points is extended by margin pixels on each side:

\[x_{\min} = \min_k x_k - m, \quad y_{\min} = \min_k y_k - m, \quad x_{\max} = \max_k x_k + m, \quad y_{\max} = \max_k y_k + m\]

with \(x\) along the columns and \(y\) along the rows of the image. Only one projection of the vertices is needed: it is a fast way to restrict a computation on the pixels (e.g. pysdic.generate_synthetic_image()) to the region of the mesh.

Note

The box contains the projection of the vertices, not always the projection of the whole surface: the distortion and the curved (e.g. quadratic) elements can move a point of an element out of the box of its vertices. Use margin to cover these cases. The box is not clipped to the sensor. The projection of the vertices behind the camera is not meaningful.

See also

compute_projected_roi() for the same box in integer pixels, clipped to the sensor, in the ROI format of pysdic.Image.

Parameters:
  • mesh (pysdic.Mesh) – The mesh, of dimension \(E\) equal to the input dimension of the camera (the element type is not used).

  • camera (Union[pysdic.Camera, pysdic.View]) – The camera (or a view, whose camera is used).

  • warp_by (Optional[Union[str, ArrayLike]], optional) – The displacement of the vertices (name of a vertex property or array of shape \((N_v, E)\)), e.g. the displacement of a frame of an analysis.

  • margin (Real, optional (default: 0.0)) – The margin in pixels added on each side of the box (\(\geq 0\)).

Returns:

The box (x_min, y_min, x_max, y_max) in image points, or None if no vertex has a finite projection.

Return type:

Optional[Tuple[float, float, float, float]]

Raises:
  • TypeError – If an input has a wrong type.

  • ValueError – If the dimension of the mesh is not the input dimension of the camera, or if margin is negative or not finite.

Examples

1from pysdic import compute_projected_bounding_box
2
3x_min, y_min, x_max, y_max = compute_projected_bounding_box(mesh, camera, margin=10)