pysdic.View.image_project#
- View.image_project(world_points, *, dx=False, dextrinsic=False, ddistortion=False, dintrinsic=False)[source]#
Project world points to the values (gray levels or colors) of the image, using the camera’s transformations and the interpolation functions of the image.
The world points are projected with
pysdic.Camera.project(), then the image (and its gradient if a Jacobian is requested) is evaluated at the image points with a single call ofpysdic.Image.evaluate_at_image_points().Note
Points projected out of the ROI of the image get the
default_valueof the image (NaN by default), as their Jacobians.Important
As for
pysdic.Camera.project(), the blocks ofjacobian_dpthat are not requested are filled with NaN. If no Jacobian with respect to the parameters is requested,jacobian_dpand its blocks are None.- Parameters:
world_points (Union[ArrayLike,
pysdic.PointCloud,pysdic.Mesh]) – The world points with shape \((\dots, E)\), with \(E\) the input dimension of the camera. For a point cloud or a mesh, the coordinates of the points or vertices are used.dx (bool, optional (default:
False)) – If True, compute the Jacobian of the values with respect to the world points.dextrinsic (bool, optional (default:
False)) – If True, compute the Jacobian of the values with respect to the extrinsic parameters.ddistortion (bool, optional (default:
False)) – If True, compute the Jacobian of the values with respect to the distortion parameters.dintrinsic (bool, optional (default:
False)) – If True, compute the Jacobian of the values with respect to the intrinsic parameters.
- Returns:
The projection result:
gray_levels(orx): shape \((\dots, C)\), the image values.image_points: shape \((\dots, 2)\), the image points \((x, y)\).jacobian_dx: shape \((\dots, C, E)\) ifdxis True.jacobian_dextrinsic: shape \((\dots, C, N_e)\).jacobian_ddistortion: shape \((\dots, C, N_d)\).jacobian_dintrinsic: shape \((\dots, C, N_i)\).jacobian_dp: shape \((\dots, C, N_e + N_d + N_i)\), the three blocks above in this order.
- Return type:
- Raises:
ValueError – If the interpolation function of the image is not constructed.
Examples
Lets create a simple view and project some 3D points:
import numpy from pysdic import Camera, Image, View, PerspectiveExtrinsic, PinholeIntrinsic extrinsic = PerspectiveExtrinsic.from_rt(rvec=[0.1, 0.2, 0.3], tvec=[12.0, 34.0, 56.0]) intrinsic = PinholeIntrinsic.from_matrix([[1000.0, 0.0, 320.0], [0.0, 1000.0, 240.0], [0.0, 0.0, 1.0]]) camera = Camera(480, 640, intrinsic=intrinsic, extrinsic=extrinsic) image = Image.from_array(numpy.zeros((480, 640), dtype=numpy.uint8)) view = View(camera, image) world_points = numpy.array([ [0, 0, 1000], [100, 0, 1000], [0, 100, 1000], [100, 100, 1000] ]) result = view.image_project(world_points, dx=True, dintrinsic=True, dextrinsic=True) result.gray_levels # shape (4, 1) result.jacobian_dx # shape (4, 1, 3) result.jacobian_dintrinsic # shape (4, 1, N_i) result.jacobian_dextrinsic # shape (4, 1, N_e)