Source code for sym.ops.orthographic_camera_cal.camera_ops

# -----------------------------------------------------------------------------
# This file was autogenerated by symforce from template:
#     cam_package/ops/CLASS/camera_ops.py.jinja
# Do NOT modify by hand.
# -----------------------------------------------------------------------------

# ruff: noqa: PLR0915, F401, PLW0211, PLR0914

import math
import typing as T

import numpy

import sym


[docs]class CameraOps(object): """ Python CameraOps implementation for :py:class:`symforce.cam.orthographic_camera_cal.OrthographicCameraCal`. """
[docs] @staticmethod def focal_length(self): # type: (sym.OrthographicCameraCal) -> numpy.ndarray """ Return the focal length. """ # Total ops: 0 # Input arrays _self = self.data # Intermediate terms (0) # Output terms _focal_length = numpy.zeros(2) _focal_length[0] = _self[0] _focal_length[1] = _self[1] return _focal_length
[docs] @staticmethod def principal_point(self): # type: (sym.OrthographicCameraCal) -> numpy.ndarray """ Return the principal point. """ # Total ops: 0 # Input arrays _self = self.data # Intermediate terms (0) # Output terms _principal_point = numpy.zeros(2) _principal_point[0] = _self[2] _principal_point[1] = _self[3] return _principal_point
[docs] @staticmethod def pixel_from_camera_point(self, point, epsilon): # type: (sym.OrthographicCameraCal, numpy.ndarray, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. Returns: pixel: (x, y) coordinate in pixels if valid is_valid: 1 if the operation is within bounds else 0 """ # Total ops: 6 # Input arrays _self = self.data if point.shape == (3,): point = point.reshape((3, 1)) elif point.shape != (3, 1): raise IndexError( "point is expected to have shape (3, 1) or (3,); instead had shape {}".format( point.shape ) ) # Intermediate terms (0) # Output terms _pixel = numpy.zeros(2) _pixel[0] = _self[0] * point[0, 0] + _self[2] _pixel[1] = _self[1] * point[1, 0] + _self[3] _is_valid = max(0, (0.0 if point[2, 0] == 0 else math.copysign(1, point[2, 0]))) return _pixel, _is_valid
[docs] @staticmethod def pixel_from_camera_point_with_jacobians(self, point, epsilon): # type: (sym.OrthographicCameraCal, numpy.ndarray, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. Returns: pixel: (x, y) coordinate in pixels if valid is_valid: 1 if the operation is within bounds else 0 pixel_D_cal: Derivative of pixel with respect to intrinsic calibration parameters pixel_D_point: Derivative of pixel with respect to point """ # Total ops: 6 # Input arrays _self = self.data if point.shape == (3,): point = point.reshape((3, 1)) elif point.shape != (3, 1): raise IndexError( "point is expected to have shape (3, 1) or (3,); instead had shape {}".format( point.shape ) ) # Intermediate terms (0) # Output terms _pixel = numpy.zeros(2) _pixel[0] = _self[0] * point[0, 0] + _self[2] _pixel[1] = _self[1] * point[1, 0] + _self[3] _is_valid = max(0, (0.0 if point[2, 0] == 0 else math.copysign(1, point[2, 0]))) _pixel_D_cal = numpy.zeros((2, 4)) _pixel_D_cal[0, 0] = point[0, 0] _pixel_D_cal[1, 0] = 0 _pixel_D_cal[0, 1] = 0 _pixel_D_cal[1, 1] = point[1, 0] _pixel_D_cal[0, 2] = 1 _pixel_D_cal[1, 2] = 0 _pixel_D_cal[0, 3] = 0 _pixel_D_cal[1, 3] = 1 _pixel_D_point = numpy.zeros((2, 3)) _pixel_D_point[0, 0] = _self[0] _pixel_D_point[1, 0] = 0 _pixel_D_point[0, 1] = 0 _pixel_D_point[1, 1] = _self[1] _pixel_D_point[0, 2] = 0 _pixel_D_point[1, 2] = 0 return _pixel, _is_valid, _pixel_D_cal, _pixel_D_point