pysdic.Camera.project_points#

Camera.project_points(world_points, dx=False, dintrinsic=False, ddistortion=False, dextrinsic=False)[source]#

Project 3D world points to 2D images points using the camera’s intrinsic, extrinsic, and distortion parameters from an PointCloud instance.

This method is a convenience wrapper around project() that extracts the numpy array from the PointCloud instance.

See also

Parameters:
  • world_points (PointCloud) – An instance of PointCloud containing the 3D points in the world coordinate system.

  • dx (bool, optional) – If True, the function will also return the jacobian of the image points with respect to the world points. Default is False.

  • dintrinsic (bool, optional) – If True, the function will also return the jacobian of the image points with respect to the intrinsic parameters. Default is False.

  • ddistortion (bool, optional) – If True, the function will also return the jacobian of the image points with respect to the distortion parameters. Default is False.

  • dextrinsic (bool, optional) – If True, the function will also return the jacobian of the image points with respect to the extrinsic parameters. Default is False.

Returns:

A ProjectionResult object containing the projected image points and optionally the jacobians.

  • image_points: A 2D array of shape (\(N_p\), 2) representing the projected images points in the image coordinate system \((x, y)\).

  • jacobian_dx: (optional) A 3D array of shape (\(N_p\), 2, 3) representing the jacobian of the normalized points with respect to the world points if dx is True.

  • jacobian_dintrinsic: (optional) A 3D array of shape (\(N_p\), 2, \(N_{\text{intrinsic}}\)) representing the jacobian of the pixel points with respect to the intrinsic parameters if dintrinsic is True.

  • jacobian_ddistortion: (optional) A 3D array of shape (\(N_p\), 2, \(N_{\text{distortion}}\)) representing the jacobian of the pixel points with respect to the distortion parameters if ddistortion is True.

  • jacobian_dextrinsic: (optional) A 3D array of shape (\(N_p\), 2, \(N_{\text{extrinsic}}\)) representing the jacobian of the pixel points with respect to the extrinsic parameters if dextrinsic is True.

Return type:

ProjectionResult

Examples

Lets create a simple camera and project some 3D points from a PointCloud instance:

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

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 some 3D world points in a PointCloud instance
world_points_array = numpy.array([
    [0, 0, 1000],
    [100, 0, 1000],
    [0, 100, 1000],
    [100, 100, 1000]
])
world_points = PointCloud(points=world_points_array)

# Project the 3D points to 2D image points
projection_result = camera.project_points(world_points, dx=True, dintrinsic=True, dextrinsic=True)

Extracting the projected image points and jacobians:

image_points = projection_result.image_points # The projected 2D image points of shape (4, 2)
jacobian_dx = projection_result.jacobian_dx # The jacobian with respect to the world points of shape (4, 2, 3)
jacobian_dintrinsic = projection_result.jacobian_dintrinsic # The jacobian with respect to the intrinsic parameters of shape (4, 2, 4)
jacobian_dextrinsic = projection_result.jacobian_dextrinsic # The jacobian with respect to the extrinsic parameters of shape (4, 2, 6)