fiftyone.core.camera#
Camera calibration data model for multi-sensor geometry workflows.
This module provides first-class data models for camera intrinsics and static transforms (poses), enabling 3D-to-2D projection, 2D-to-3D unprojection, and multi-sensor fusion workflows.
Key classes:
CameraIntrinsics: Base class for camera intrinsic parametersPinholeCameraIntrinsics: Pinhole model (no distortion)OpenCVCameraIntrinsics: OpenCV model with radial/tangential distortionOpenCVFisheyeCameraIntrinsics: Fisheye model with equidistant projectionStaticTransform: Rigid 6-DOF transformation (rotation + translation)CameraProjector: Utility for projecting/unprojecting points
For low-level transformation utilities (quaternion math, coordinate system
conversions, matrix operations), see fiftyone.utils.transforms.
Data:
Supported 3D camera axis conventions |
|
Default target frame for static transforms |
Classes:
Abstract base class for camera projection models. |
|
Standard OpenCV camera model with radial and tangential distortion. |
|
OpenCV fisheye camera model with equidistant projection. |
|
|
Base class for camera intrinsics. |
|
Pinhole camera model with no distortion. |
|
OpenCV Brown-Conrady camera model with radial and tangential distortion. |
|
OpenCV fisheye camera model with equidistant projection. |
|
Represents a rigid 3D transformation (6-DOF pose). |
|
Reference to dataset-level camera intrinsics. |
|
Reference to dataset-level static transform. |
|
Utility class for projecting points between 3D and 2D. |
- fiftyone.core.camera.CAMERA_CONVENTION_OPENCV = 'opencv'#
Supported 3D camera axis conventions
- fiftyone.core.camera.DEFAULT_TRANSFORM_TARGET_FRAME = 'world'#
Default target frame for static transforms
- class fiftyone.core.camera.ProjectionModel#
Bases:
ABCAbstract base class for camera projection models.
Encapsulates projection and undistortion operations for different camera models.
Methods:
project(points, K, distortion)Project 3D points to 2D image coordinates.
undistort(points, K, distortion)Undistort 2D image points, returning normalized coordinates.
undistort_image(image, K, distortion[, ...])Undistort an image using this projection model.
- abstractmethod project(points: ndarray, K: ndarray, distortion: ndarray | None) ndarray#
Project 3D points to 2D image coordinates.
- Parameters:
points – (N, 3) array of 3D points in camera frame
K – (3, 3) intrinsic matrix
distortion – distortion coefficients, or None
- Returns:
(N, 2) array of 2D pixel coordinates
- abstractmethod undistort(points: ndarray, K: ndarray, distortion: ndarray | None) ndarray#
Undistort 2D image points, returning normalized coordinates.
- Parameters:
points – (N, 2) array of 2D pixel coordinates
K – (3, 3) intrinsic matrix
distortion – distortion coefficients, or None
- Returns:
(N, 2) array of normalized coordinates (z=1 plane in camera frame)
- class fiftyone.core.camera.OpenCVProjectionModel#
Bases:
ProjectionModelStandard OpenCV camera model with radial and tangential distortion.
Methods:
project(points, K, distortion)Project points using OpenCV's standard camera model.
undistort(points, K, distortion)Undistort points using OpenCV's standard camera model.
undistort_image(image, K, distortion[, ...])Undistort an image using this projection model.
- project(points: ndarray, K: ndarray, distortion: ndarray | None) ndarray#
Project points using OpenCV’s standard camera model.
- class fiftyone.core.camera.FisheyeProjectionModel#
Bases:
ProjectionModelOpenCV fisheye camera model with equidistant projection.
Methods:
project(points, K, distortion)Project points using OpenCV's fisheye camera model.
undistort(points, K, distortion)Undistort points using OpenCV's fisheye camera model.
undistort_image(image, K, distortion[, ...])Undistort an image using this projection model.
- project(points: ndarray, K: ndarray, distortion: ndarray | None) ndarray#
Project points using OpenCV’s fisheye camera model.
- class fiftyone.core.camera.CameraIntrinsics(*args, **kwargs)#
Bases:
DynamicEmbeddedDocumentBase class for camera intrinsics.
All camera intrinsics models share the following parameters:
- Parameters:
fx – focal length in pixels (x-axis)
fy – focal length in pixels (y-axis)
cx – principal point x-coordinate in pixels
cy – principal point y-coordinate in pixels
skew (0.0) – skew coefficient (typically 0 for modern cameras)
- intrinsic_matrix#
the 3x3 intrinsic matrix K
Example:
import fiftyone as fo intrinsics = fo.PinholeCameraIntrinsics( fx=1000.0, fy=1000.0, cx=960.0, cy=540.0, ) # Access the 3x3 intrinsic matrix K = intrinsics.intrinsic_matrix
Attributes:
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
Returns the 3x3 intrinsic matrix K.
An ordered tuple of the public fields of this document.
Methods:
from_matrix(matrix, **kwargs)Creates a CameraIntrinsics instance from a 3x3 intrinsic matrix.
Returns the distortion coefficients for this camera model.
Returns the ProjectionModel instance for this camera model.
camera_matrix_3x4([transform])Returns the 3x4 camera projection matrix P = K @ [R|t].
undistort_image(image[, alpha, new_size])Undistort an image using this camera's intrinsics and distortion.
clean()Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
clear_field(field_name)Clears the field from the document.
copy()Returns a deep copy of the document.
fancy_repr([class_name, select_fields, ...])Generates a customizable string representation of the document.
field_to_mongo(field_name)field_to_python(field_name, value)from_dict(d[, extended])Loads the document from a BSON/JSON dictionary.
from_json(s)Loads the document from a JSON string.
get_field(field_name)Gets the field of the document.
Get text score from text query
has_field(field_name)Determines whether the document has a field of the given name.
Returns an iterator over the
(name, value)pairs of the public fields of the document.merge(doc[, merge_lists, merge_dicts, overwrite])Merges the contents of the given document into this document.
set_field(field_name, value[, create])Sets the value of a field of the document.
to_dict([extended])Serializes this document to a BSON/JSON dictionary.
to_json([pretty_print])Serializes the document to a JSON string.
to_mongo(*args, **kwargs)Return as SON data ready for use with MongoDB.
validate([clean])Ensure that all fields' values are valid and that required fields are present.
Classes:
alias of
DocumentMetaclass- fx#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- fy#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- cx#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- cy#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- skew#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- property intrinsic_matrix: ndarray#
Returns the 3x3 intrinsic matrix K.
The matrix has the form:
[[fx, s, cx], [ 0, fy, cy], [ 0, 0, 1]]
- Returns:
a (3, 3) numpy array
- classmethod from_matrix(matrix: ndarray, **kwargs) CameraIntrinsics#
Creates a CameraIntrinsics instance from a 3x3 intrinsic matrix.
- Parameters:
matrix – a (3, 3) intrinsic matrix K
**kwargs – additional fields to set on the instance
- Returns:
a
CameraIntrinsicsinstance
- get_distortion_coeffs() ndarray | None#
Returns the distortion coefficients for this camera model.
- Returns:
a numpy array of distortion coefficients, or None if no distortion
- get_projection_model() ProjectionModel#
Returns the ProjectionModel instance for this camera model.
- Returns:
a
ProjectionModelinstance
- camera_matrix_3x4(transform: StaticTransform | None = None) ndarray#
Returns the 3x4 camera projection matrix P = K @ [R|t].
Note: This matrix is only valid when distortion is zero or has been pre-corrected in the image.
- Parameters:
transform – optional transform defining the world-to-camera transformation (i.e., source_frame=world, target_frame=camera). If your transform is camera-to-world, call
transform.inverse()first.- Returns:
a (3, 4) numpy array
- undistort_image(image: ndarray, alpha: float = 0.0, new_size: Tuple[int, int] | None = None) ndarray#
Undistort an image using this camera’s intrinsics and distortion.
Removes lens distortion from an image, producing a rectified image that follows the pinhole camera model.
- Parameters:
image – input distorted image as a numpy array with shape (H, W) for grayscale or (H, W, C) for color images
alpha –
free scaling parameter between 0 and 1:
0: returns undistorted image with all pixels valid (cropped to remove black borders)
1: retains all source image pixels (may have black borders where no source data exists)
Intermediate values blend between the two extremes
new_size – optional output image size as (width, height). If None, uses the input image size
- Returns:
undistorted image as a numpy array with the same dtype as input
Example:
import fiftyone as fo import cv2 intrinsics = fo.OpenCVCameraIntrinsics( fx=1000.0, fy=1000.0, cx=960.0, cy=540.0, k1=-0.1, k2=0.05, ) distorted = cv2.imread("distorted.jpg") rectified = intrinsics.undistort_image(distorted) # Keep all pixels (with black borders) rectified_full = intrinsics.undistort_image(distorted, alpha=1.0)
- STRICT = False#
- clean()#
Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clear_field(field_name)#
Clears the field from the document.
- Parameters:
field_name – the field name
- Raises:
ValueError – if the field does not exist
- copy()#
Returns a deep copy of the document.
- Returns:
a
SerializableDocument
- fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)#
Generates a customizable string representation of the document.
- Parameters:
class_name (None) – optional class name to use
select_fields (None) – iterable of field names to restrict to
exclude_fields (None) – iterable of field names to exclude
**kwargs – additional key-value pairs to include in the string representation
- Returns:
a string representation of the document
- property field_names#
An ordered tuple of the public fields of this document.
- field_to_mongo(field_name)#
- field_to_python(field_name, value)#
- classmethod from_dict(d, extended=False)#
Loads the document from a BSON/JSON dictionary.
- Parameters:
d – a dictionary
extended (False) – whether the input dictionary may contain serialized extended JSON constructs
- Returns:
a
SerializableDocument
- classmethod from_json(s)#
Loads the document from a JSON string.
- Returns:
a
SerializableDocument
- get_field(field_name)#
Gets the field of the document.
- Parameters:
field_name – the field name
- Returns:
the field value
- Raises:
AttributeError – if the field does not exist
- get_text_score()#
Get text score from text query
- has_field(field_name)#
Determines whether the document has a field of the given name.
- Parameters:
field_name – the field name
- Returns:
True/False
- iter_fields()#
Returns an iterator over the
(name, value)pairs of the public fields of the document.- Returns:
an iterator that emits
(name, value)tuples
- merge(doc, merge_lists=True, merge_dicts=True, overwrite=True)#
Merges the contents of the given document into this document.
- Parameters:
doc – a
SerializableDocumentof same type as this documentmerge_lists (True) – whether to merge the elements of top-level list fields rather than treating the list as a single value
merge_dicts (True) – whether to recursively merge the contents of top-level dict fields rather than treating the dict as a single value
overwrite (True) – whether to overwrite (True) or skip (False) existing fields
- my_metaclass#
alias of
DocumentMetaclass
- set_field(field_name, value, create=True)#
Sets the value of a field of the document.
- Parameters:
field_name – the field name
value – the field value
create (True) – whether to create the field if it does not exist
- Raises:
ValueError – if
field_nameis not an allowed field name or does not exist andcreate == False
- to_dict(extended=False)#
Serializes this document to a BSON/JSON dictionary.
- Parameters:
extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format
- Returns:
a dict
- to_json(pretty_print=False)#
Serializes the document to a JSON string.
- Parameters:
pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations
- Returns:
a JSON string
- to_mongo(*args, **kwargs)#
Return as SON data ready for use with MongoDB.
- validate(clean=True)#
Ensure that all fields’ values are valid and that required fields are present.
Raises
ValidationErrorif any of the fields’ values are found to be invalid.
- class fiftyone.core.camera.PinholeCameraIntrinsics(*args, **kwargs)#
Bases:
CameraIntrinsicsPinhole camera model with no distortion.
- Parameters:
fx – focal length in pixels (x-axis)
fy – focal length in pixels (y-axis)
cx – principal point x-coordinate in pixels
cy – principal point y-coordinate in pixels
skew (0.0) – skew coefficient (typically 0 for modern cameras)
Example:
import fiftyone as fo intrinsics = fo.PinholeCameraIntrinsics( fx=1000.0, fy=1000.0, cx=960.0, cy=540.0, )
Attributes:
A floating point number field.
A floating point number field.
An ordered tuple of the public fields of this document.
A floating point number field.
A floating point number field.
Returns the 3x3 intrinsic matrix K.
A floating point number field.
Methods:
camera_matrix_3x4([transform])Returns the 3x4 camera projection matrix P = K @ [R|t].
clean()Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
clear_field(field_name)Clears the field from the document.
copy()Returns a deep copy of the document.
fancy_repr([class_name, select_fields, ...])Generates a customizable string representation of the document.
field_to_mongo(field_name)field_to_python(field_name, value)from_dict(d[, extended])Loads the document from a BSON/JSON dictionary.
from_json(s)Loads the document from a JSON string.
from_matrix(matrix, **kwargs)Creates a CameraIntrinsics instance from a 3x3 intrinsic matrix.
Returns the distortion coefficients for this camera model.
get_field(field_name)Gets the field of the document.
Returns the ProjectionModel instance for this camera model.
Get text score from text query
has_field(field_name)Determines whether the document has a field of the given name.
Returns an iterator over the
(name, value)pairs of the public fields of the document.merge(doc[, merge_lists, merge_dicts, overwrite])Merges the contents of the given document into this document.
set_field(field_name, value[, create])Sets the value of a field of the document.
to_dict([extended])Serializes this document to a BSON/JSON dictionary.
to_json([pretty_print])Serializes the document to a JSON string.
to_mongo(*args, **kwargs)Return as SON data ready for use with MongoDB.
undistort_image(image[, alpha, new_size])Undistort an image using this camera's intrinsics and distortion.
validate([clean])Ensure that all fields' values are valid and that required fields are present.
Classes:
alias of
DocumentMetaclass- STRICT = False#
- camera_matrix_3x4(transform: StaticTransform | None = None) ndarray#
Returns the 3x4 camera projection matrix P = K @ [R|t].
Note: This matrix is only valid when distortion is zero or has been pre-corrected in the image.
- Parameters:
transform – optional transform defining the world-to-camera transformation (i.e., source_frame=world, target_frame=camera). If your transform is camera-to-world, call
transform.inverse()first.- Returns:
a (3, 4) numpy array
- clean()#
Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clear_field(field_name)#
Clears the field from the document.
- Parameters:
field_name – the field name
- Raises:
ValueError – if the field does not exist
- copy()#
Returns a deep copy of the document.
- Returns:
a
SerializableDocument
- cx#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- cy#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)#
Generates a customizable string representation of the document.
- Parameters:
class_name (None) – optional class name to use
select_fields (None) – iterable of field names to restrict to
exclude_fields (None) – iterable of field names to exclude
**kwargs – additional key-value pairs to include in the string representation
- Returns:
a string representation of the document
- property field_names#
An ordered tuple of the public fields of this document.
- field_to_mongo(field_name)#
- field_to_python(field_name, value)#
- classmethod from_dict(d, extended=False)#
Loads the document from a BSON/JSON dictionary.
- Parameters:
d – a dictionary
extended (False) – whether the input dictionary may contain serialized extended JSON constructs
- Returns:
a
SerializableDocument
- classmethod from_json(s)#
Loads the document from a JSON string.
- Returns:
a
SerializableDocument
- classmethod from_matrix(matrix: ndarray, **kwargs) CameraIntrinsics#
Creates a CameraIntrinsics instance from a 3x3 intrinsic matrix.
- Parameters:
matrix – a (3, 3) intrinsic matrix K
**kwargs – additional fields to set on the instance
- Returns:
a
CameraIntrinsicsinstance
- fx#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- fy#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- get_distortion_coeffs() ndarray | None#
Returns the distortion coefficients for this camera model.
- Returns:
a numpy array of distortion coefficients, or None if no distortion
- get_field(field_name)#
Gets the field of the document.
- Parameters:
field_name – the field name
- Returns:
the field value
- Raises:
AttributeError – if the field does not exist
- get_projection_model() ProjectionModel#
Returns the ProjectionModel instance for this camera model.
- Returns:
a
ProjectionModelinstance
- get_text_score()#
Get text score from text query
- has_field(field_name)#
Determines whether the document has a field of the given name.
- Parameters:
field_name – the field name
- Returns:
True/False
- property intrinsic_matrix: ndarray#
Returns the 3x3 intrinsic matrix K.
The matrix has the form:
[[fx, s, cx], [ 0, fy, cy], [ 0, 0, 1]]
- Returns:
a (3, 3) numpy array
- iter_fields()#
Returns an iterator over the
(name, value)pairs of the public fields of the document.- Returns:
an iterator that emits
(name, value)tuples
- merge(doc, merge_lists=True, merge_dicts=True, overwrite=True)#
Merges the contents of the given document into this document.
- Parameters:
doc – a
SerializableDocumentof same type as this documentmerge_lists (True) – whether to merge the elements of top-level list fields rather than treating the list as a single value
merge_dicts (True) – whether to recursively merge the contents of top-level dict fields rather than treating the dict as a single value
overwrite (True) – whether to overwrite (True) or skip (False) existing fields
- my_metaclass#
alias of
DocumentMetaclass
- set_field(field_name, value, create=True)#
Sets the value of a field of the document.
- Parameters:
field_name – the field name
value – the field value
create (True) – whether to create the field if it does not exist
- Raises:
ValueError – if
field_nameis not an allowed field name or does not exist andcreate == False
- skew#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- to_dict(extended=False)#
Serializes this document to a BSON/JSON dictionary.
- Parameters:
extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format
- Returns:
a dict
- to_json(pretty_print=False)#
Serializes the document to a JSON string.
- Parameters:
pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations
- Returns:
a JSON string
- to_mongo(*args, **kwargs)#
Return as SON data ready for use with MongoDB.
- undistort_image(image: ndarray, alpha: float = 0.0, new_size: Tuple[int, int] | None = None) ndarray#
Undistort an image using this camera’s intrinsics and distortion.
Removes lens distortion from an image, producing a rectified image that follows the pinhole camera model.
- Parameters:
image – input distorted image as a numpy array with shape (H, W) for grayscale or (H, W, C) for color images
alpha –
free scaling parameter between 0 and 1:
0: returns undistorted image with all pixels valid (cropped to remove black borders)
1: retains all source image pixels (may have black borders where no source data exists)
Intermediate values blend between the two extremes
new_size – optional output image size as (width, height). If None, uses the input image size
- Returns:
undistorted image as a numpy array with the same dtype as input
Example:
import fiftyone as fo import cv2 intrinsics = fo.OpenCVCameraIntrinsics( fx=1000.0, fy=1000.0, cx=960.0, cy=540.0, k1=-0.1, k2=0.05, ) distorted = cv2.imread("distorted.jpg") rectified = intrinsics.undistort_image(distorted) # Keep all pixels (with black borders) rectified_full = intrinsics.undistort_image(distorted, alpha=1.0)
- validate(clean=True)#
Ensure that all fields’ values are valid and that required fields are present.
Raises
ValidationErrorif any of the fields’ values are found to be invalid.
- class fiftyone.core.camera.OpenCVCameraIntrinsics(*args, **kwargs)#
Bases:
CameraIntrinsicsOpenCV Brown-Conrady camera model with radial and tangential distortion.
Distortion coefficients follow the OpenCV ordering: (k1, k2, p1, p2, k3, k4, k5, k6).
The radial distortion model is:
x_distorted = x * (1 + k1*r^2 + k2*r^4 + k3*r^6) / (1 + k4*r^2 + k5*r^4 + k6*r^6)
The tangential distortion model is:
x_distorted += 2*p1*x*y + p2*(r^2 + 2*x^2) y_distorted += p1*(r^2 + 2*y^2) + 2*p2*x*y
- Parameters:
fx – focal length in pixels (x-axis)
fy – focal length in pixels (y-axis)
cx – principal point x-coordinate in pixels
cy – principal point y-coordinate in pixels
skew (0.0) – skew coefficient
k1 (0.0) – radial distortion coefficient
k2 (0.0) – radial distortion coefficient
p1 (0.0) – tangential distortion coefficient
p2 (0.0) – tangential distortion coefficient
k3 (0.0) – radial distortion coefficient
k4 (0.0) – radial distortion coefficient (rational model)
k5 (0.0) – radial distortion coefficient (rational model)
k6 (0.0) – radial distortion coefficient (rational model)
Example:
import fiftyone as fo intrinsics = fo.OpenCVCameraIntrinsics( fx=1000.0, fy=1000.0, cx=960.0, cy=540.0, k1=-0.1, k2=0.05, p1=0.001, p2=-0.001, )
Attributes:
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
An ordered tuple of the public fields of this document.
A floating point number field.
A floating point number field.
Returns the 3x3 intrinsic matrix K.
A floating point number field.
Methods:
Returns the OpenCV distortion coefficients.
camera_matrix_3x4([transform])Returns the 3x4 camera projection matrix P = K @ [R|t].
clean()Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
clear_field(field_name)Clears the field from the document.
copy()Returns a deep copy of the document.
fancy_repr([class_name, select_fields, ...])Generates a customizable string representation of the document.
field_to_mongo(field_name)field_to_python(field_name, value)from_dict(d[, extended])Loads the document from a BSON/JSON dictionary.
from_json(s)Loads the document from a JSON string.
from_matrix(matrix, **kwargs)Creates a CameraIntrinsics instance from a 3x3 intrinsic matrix.
get_field(field_name)Gets the field of the document.
Returns the ProjectionModel instance for this camera model.
Get text score from text query
has_field(field_name)Determines whether the document has a field of the given name.
Returns an iterator over the
(name, value)pairs of the public fields of the document.merge(doc[, merge_lists, merge_dicts, overwrite])Merges the contents of the given document into this document.
set_field(field_name, value[, create])Sets the value of a field of the document.
to_dict([extended])Serializes this document to a BSON/JSON dictionary.
to_json([pretty_print])Serializes the document to a JSON string.
to_mongo(*args, **kwargs)Return as SON data ready for use with MongoDB.
undistort_image(image[, alpha, new_size])Undistort an image using this camera's intrinsics and distortion.
validate([clean])Ensure that all fields' values are valid and that required fields are present.
Classes:
alias of
DocumentMetaclass- k1#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- k2#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- p1#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- p2#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- k3#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- k4#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- k5#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- k6#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- get_distortion_coeffs() ndarray#
Returns the OpenCV distortion coefficients.
- Returns:
a (8,) numpy array with coefficients (k1, k2, p1, p2, k3, k4, k5, k6)
- STRICT = False#
- camera_matrix_3x4(transform: StaticTransform | None = None) ndarray#
Returns the 3x4 camera projection matrix P = K @ [R|t].
Note: This matrix is only valid when distortion is zero or has been pre-corrected in the image.
- Parameters:
transform – optional transform defining the world-to-camera transformation (i.e., source_frame=world, target_frame=camera). If your transform is camera-to-world, call
transform.inverse()first.- Returns:
a (3, 4) numpy array
- clean()#
Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clear_field(field_name)#
Clears the field from the document.
- Parameters:
field_name – the field name
- Raises:
ValueError – if the field does not exist
- copy()#
Returns a deep copy of the document.
- Returns:
a
SerializableDocument
- cx#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- cy#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)#
Generates a customizable string representation of the document.
- Parameters:
class_name (None) – optional class name to use
select_fields (None) – iterable of field names to restrict to
exclude_fields (None) – iterable of field names to exclude
**kwargs – additional key-value pairs to include in the string representation
- Returns:
a string representation of the document
- property field_names#
An ordered tuple of the public fields of this document.
- field_to_mongo(field_name)#
- field_to_python(field_name, value)#
- classmethod from_dict(d, extended=False)#
Loads the document from a BSON/JSON dictionary.
- Parameters:
d – a dictionary
extended (False) – whether the input dictionary may contain serialized extended JSON constructs
- Returns:
a
SerializableDocument
- classmethod from_json(s)#
Loads the document from a JSON string.
- Returns:
a
SerializableDocument
- classmethod from_matrix(matrix: ndarray, **kwargs) CameraIntrinsics#
Creates a CameraIntrinsics instance from a 3x3 intrinsic matrix.
- Parameters:
matrix – a (3, 3) intrinsic matrix K
**kwargs – additional fields to set on the instance
- Returns:
a
CameraIntrinsicsinstance
- fx#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- fy#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- get_field(field_name)#
Gets the field of the document.
- Parameters:
field_name – the field name
- Returns:
the field value
- Raises:
AttributeError – if the field does not exist
- get_projection_model() ProjectionModel#
Returns the ProjectionModel instance for this camera model.
- Returns:
a
ProjectionModelinstance
- get_text_score()#
Get text score from text query
- has_field(field_name)#
Determines whether the document has a field of the given name.
- Parameters:
field_name – the field name
- Returns:
True/False
- property intrinsic_matrix: ndarray#
Returns the 3x3 intrinsic matrix K.
The matrix has the form:
[[fx, s, cx], [ 0, fy, cy], [ 0, 0, 1]]
- Returns:
a (3, 3) numpy array
- iter_fields()#
Returns an iterator over the
(name, value)pairs of the public fields of the document.- Returns:
an iterator that emits
(name, value)tuples
- merge(doc, merge_lists=True, merge_dicts=True, overwrite=True)#
Merges the contents of the given document into this document.
- Parameters:
doc – a
SerializableDocumentof same type as this documentmerge_lists (True) – whether to merge the elements of top-level list fields rather than treating the list as a single value
merge_dicts (True) – whether to recursively merge the contents of top-level dict fields rather than treating the dict as a single value
overwrite (True) – whether to overwrite (True) or skip (False) existing fields
- my_metaclass#
alias of
DocumentMetaclass
- set_field(field_name, value, create=True)#
Sets the value of a field of the document.
- Parameters:
field_name – the field name
value – the field value
create (True) – whether to create the field if it does not exist
- Raises:
ValueError – if
field_nameis not an allowed field name or does not exist andcreate == False
- skew#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- to_dict(extended=False)#
Serializes this document to a BSON/JSON dictionary.
- Parameters:
extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format
- Returns:
a dict
- to_json(pretty_print=False)#
Serializes the document to a JSON string.
- Parameters:
pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations
- Returns:
a JSON string
- to_mongo(*args, **kwargs)#
Return as SON data ready for use with MongoDB.
- undistort_image(image: ndarray, alpha: float = 0.0, new_size: Tuple[int, int] | None = None) ndarray#
Undistort an image using this camera’s intrinsics and distortion.
Removes lens distortion from an image, producing a rectified image that follows the pinhole camera model.
- Parameters:
image – input distorted image as a numpy array with shape (H, W) for grayscale or (H, W, C) for color images
alpha –
free scaling parameter between 0 and 1:
0: returns undistorted image with all pixels valid (cropped to remove black borders)
1: retains all source image pixels (may have black borders where no source data exists)
Intermediate values blend between the two extremes
new_size – optional output image size as (width, height). If None, uses the input image size
- Returns:
undistorted image as a numpy array with the same dtype as input
Example:
import fiftyone as fo import cv2 intrinsics = fo.OpenCVCameraIntrinsics( fx=1000.0, fy=1000.0, cx=960.0, cy=540.0, k1=-0.1, k2=0.05, ) distorted = cv2.imread("distorted.jpg") rectified = intrinsics.undistort_image(distorted) # Keep all pixels (with black borders) rectified_full = intrinsics.undistort_image(distorted, alpha=1.0)
- validate(clean=True)#
Ensure that all fields’ values are valid and that required fields are present.
Raises
ValidationErrorif any of the fields’ values are found to be invalid.
- class fiftyone.core.camera.OpenCVFisheyeCameraIntrinsics(*args, **kwargs)#
Bases:
CameraIntrinsicsOpenCV fisheye camera model with equidistant projection.
Uses 4 distortion coefficients (k1, k2, k3, k4) for the fisheye model.
- Parameters:
fx – focal length in pixels (x-axis)
fy – focal length in pixels (y-axis)
cx – principal point x-coordinate in pixels
cy – principal point y-coordinate in pixels
skew (0.0) – skew coefficient
k1 (0.0) – fisheye distortion coefficient
k2 (0.0) – fisheye distortion coefficient
k3 (0.0) – fisheye distortion coefficient
k4 (0.0) – fisheye distortion coefficient
Example:
import fiftyone as fo intrinsics = fo.OpenCVFisheyeCameraIntrinsics( fx=500.0, fy=500.0, cx=640.0, cy=480.0, k1=0.1, k2=-0.05, )
Attributes:
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
A floating point number field.
An ordered tuple of the public fields of this document.
A floating point number field.
A floating point number field.
Returns the 3x3 intrinsic matrix K.
A floating point number field.
Methods:
Returns the fisheye distortion coefficients.
Returns the ProjectionModel instance for fisheye distortion.
camera_matrix_3x4([transform])Returns the 3x4 camera projection matrix P = K @ [R|t].
clean()Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
clear_field(field_name)Clears the field from the document.
copy()Returns a deep copy of the document.
fancy_repr([class_name, select_fields, ...])Generates a customizable string representation of the document.
field_to_mongo(field_name)field_to_python(field_name, value)from_dict(d[, extended])Loads the document from a BSON/JSON dictionary.
from_json(s)Loads the document from a JSON string.
from_matrix(matrix, **kwargs)Creates a CameraIntrinsics instance from a 3x3 intrinsic matrix.
get_field(field_name)Gets the field of the document.
Get text score from text query
has_field(field_name)Determines whether the document has a field of the given name.
Returns an iterator over the
(name, value)pairs of the public fields of the document.merge(doc[, merge_lists, merge_dicts, overwrite])Merges the contents of the given document into this document.
set_field(field_name, value[, create])Sets the value of a field of the document.
to_dict([extended])Serializes this document to a BSON/JSON dictionary.
to_json([pretty_print])Serializes the document to a JSON string.
to_mongo(*args, **kwargs)Return as SON data ready for use with MongoDB.
undistort_image(image[, alpha, new_size])Undistort an image using this camera's intrinsics and distortion.
validate([clean])Ensure that all fields' values are valid and that required fields are present.
Classes:
alias of
DocumentMetaclass- k1#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- k2#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- k3#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- k4#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- get_distortion_coeffs() ndarray#
Returns the fisheye distortion coefficients.
- Returns:
a (4,) numpy array with coefficients (k1, k2, k3, k4)
- get_projection_model() ProjectionModel#
Returns the ProjectionModel instance for fisheye distortion.
- Returns:
a
FisheyeProjectionModelinstance
- STRICT = False#
- camera_matrix_3x4(transform: StaticTransform | None = None) ndarray#
Returns the 3x4 camera projection matrix P = K @ [R|t].
Note: This matrix is only valid when distortion is zero or has been pre-corrected in the image.
- Parameters:
transform – optional transform defining the world-to-camera transformation (i.e., source_frame=world, target_frame=camera). If your transform is camera-to-world, call
transform.inverse()first.- Returns:
a (3, 4) numpy array
- clean()#
Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clear_field(field_name)#
Clears the field from the document.
- Parameters:
field_name – the field name
- Raises:
ValueError – if the field does not exist
- copy()#
Returns a deep copy of the document.
- Returns:
a
SerializableDocument
- cx#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- cy#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)#
Generates a customizable string representation of the document.
- Parameters:
class_name (None) – optional class name to use
select_fields (None) – iterable of field names to restrict to
exclude_fields (None) – iterable of field names to exclude
**kwargs – additional key-value pairs to include in the string representation
- Returns:
a string representation of the document
- property field_names#
An ordered tuple of the public fields of this document.
- field_to_mongo(field_name)#
- field_to_python(field_name, value)#
- classmethod from_dict(d, extended=False)#
Loads the document from a BSON/JSON dictionary.
- Parameters:
d – a dictionary
extended (False) – whether the input dictionary may contain serialized extended JSON constructs
- Returns:
a
SerializableDocument
- classmethod from_json(s)#
Loads the document from a JSON string.
- Returns:
a
SerializableDocument
- classmethod from_matrix(matrix: ndarray, **kwargs) CameraIntrinsics#
Creates a CameraIntrinsics instance from a 3x3 intrinsic matrix.
- Parameters:
matrix – a (3, 3) intrinsic matrix K
**kwargs – additional fields to set on the instance
- Returns:
a
CameraIntrinsicsinstance
- fx#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- fy#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- get_field(field_name)#
Gets the field of the document.
- Parameters:
field_name – the field name
- Returns:
the field value
- Raises:
AttributeError – if the field does not exist
- get_text_score()#
Get text score from text query
- has_field(field_name)#
Determines whether the document has a field of the given name.
- Parameters:
field_name – the field name
- Returns:
True/False
- property intrinsic_matrix: ndarray#
Returns the 3x3 intrinsic matrix K.
The matrix has the form:
[[fx, s, cx], [ 0, fy, cy], [ 0, 0, 1]]
- Returns:
a (3, 3) numpy array
- iter_fields()#
Returns an iterator over the
(name, value)pairs of the public fields of the document.- Returns:
an iterator that emits
(name, value)tuples
- merge(doc, merge_lists=True, merge_dicts=True, overwrite=True)#
Merges the contents of the given document into this document.
- Parameters:
doc – a
SerializableDocumentof same type as this documentmerge_lists (True) – whether to merge the elements of top-level list fields rather than treating the list as a single value
merge_dicts (True) – whether to recursively merge the contents of top-level dict fields rather than treating the dict as a single value
overwrite (True) – whether to overwrite (True) or skip (False) existing fields
- my_metaclass#
alias of
DocumentMetaclass
- set_field(field_name, value, create=True)#
Sets the value of a field of the document.
- Parameters:
field_name – the field name
value – the field value
create (True) – whether to create the field if it does not exist
- Raises:
ValueError – if
field_nameis not an allowed field name or does not exist andcreate == False
- skew#
A floating point number field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- to_dict(extended=False)#
Serializes this document to a BSON/JSON dictionary.
- Parameters:
extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format
- Returns:
a dict
- to_json(pretty_print=False)#
Serializes the document to a JSON string.
- Parameters:
pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations
- Returns:
a JSON string
- to_mongo(*args, **kwargs)#
Return as SON data ready for use with MongoDB.
- undistort_image(image: ndarray, alpha: float = 0.0, new_size: Tuple[int, int] | None = None) ndarray#
Undistort an image using this camera’s intrinsics and distortion.
Removes lens distortion from an image, producing a rectified image that follows the pinhole camera model.
- Parameters:
image – input distorted image as a numpy array with shape (H, W) for grayscale or (H, W, C) for color images
alpha –
free scaling parameter between 0 and 1:
0: returns undistorted image with all pixels valid (cropped to remove black borders)
1: retains all source image pixels (may have black borders where no source data exists)
Intermediate values blend between the two extremes
new_size – optional output image size as (width, height). If None, uses the input image size
- Returns:
undistorted image as a numpy array with the same dtype as input
Example:
import fiftyone as fo import cv2 intrinsics = fo.OpenCVCameraIntrinsics( fx=1000.0, fy=1000.0, cx=960.0, cy=540.0, k1=-0.1, k2=0.05, ) distorted = cv2.imread("distorted.jpg") rectified = intrinsics.undistort_image(distorted) # Keep all pixels (with black borders) rectified_full = intrinsics.undistort_image(distorted, alpha=1.0)
- validate(clean=True)#
Ensure that all fields’ values are valid and that required fields are present.
Raises
ValidationErrorif any of the fields’ values are found to be invalid.
- class fiftyone.core.camera.StaticTransform(*args, **kwargs)#
Bases:
DynamicEmbeddedDocumentRepresents a rigid 3D transformation (6-DOF pose).
Stored as translation + quaternion for efficiency. Defines transformation from
source_frametotarget_frame:X_target = R @ X_source + t
The quaternion uses scalar-last convention [qx, qy, qz, qw], matching scipy and ROS conventions.
- Parameters:
source_frame – name of source coordinate frame (e.g., “camera_front”). This is a required argument.
translation ([0, 0, 0]) – 3-element list [tx, ty, tz] (position in target frame)
quaternion ([0, 0, 0, 1]) – unit quaternion [qx, qy, qz, qw] (scalar-last convention, defaults to identity rotation)
target_frame (None) – name of target coordinate frame (e.g., “ego”, “world”)
timestamp (None) – optional timestamp in nanoseconds for interpolation
covariance (None) – optional 6-element diagonal pose uncertainty [σx, σy, σz, σroll, σpitch, σyaw] where translations are in metric and rotations are in radians
- rotation_matrix#
the 3x3 rotation matrix R
- transform_matrix#
the 4x4 homogeneous transformation matrix
Example:
import fiftyone as fo # Camera to ego transformation transform = fo.StaticTransform( translation=[1.5, 0.0, 1.2], # identity rotation quaternion=[0.0, 0.0, 0.0, 1.0], source_frame="camera_front", target_frame="ego", ) # Access the 4x4 transformation matrix T = transform.transform_matrix
Attributes:
A list field that wraps a standard
Field, allowing multiple instances of the field to be stored as a list in the database.A list field that wraps a standard
Field, allowing multiple instances of the field to be stored as a list in the database.A unicode string field.
A unicode string field.
A 32 bit integer field.
A list field that wraps a standard
Field, allowing multiple instances of the field to be stored as a list in the database.Returns the 3x3 rotation matrix R.
Returns the 4x4 homogeneous transformation matrix.
An ordered tuple of the public fields of this document.
Methods:
validate([clean])Validates the transform data.
from_matrix(matrix[, source_frame, target_frame])Creates a StaticTransform instance from a 3x4 or 4x4 matrix.
inverse()Returns the inverse transformation.
compose(other)Composes this transform with another.
clean()Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
clear_field(field_name)Clears the field from the document.
copy()Returns a deep copy of the document.
fancy_repr([class_name, select_fields, ...])Generates a customizable string representation of the document.
field_to_mongo(field_name)field_to_python(field_name, value)from_dict(d[, extended])Loads the document from a BSON/JSON dictionary.
from_json(s)Loads the document from a JSON string.
get_field(field_name)Gets the field of the document.
Get text score from text query
has_field(field_name)Determines whether the document has a field of the given name.
Returns an iterator over the
(name, value)pairs of the public fields of the document.merge(doc[, merge_lists, merge_dicts, overwrite])Merges the contents of the given document into this document.
set_field(field_name, value[, create])Sets the value of a field of the document.
to_dict([extended])Serializes this document to a BSON/JSON dictionary.
to_json([pretty_print])Serializes the document to a JSON string.
to_mongo(*args, **kwargs)Return as SON data ready for use with MongoDB.
Classes:
alias of
DocumentMetaclass- translation#
A list field that wraps a standard
Field, allowing multiple instances of the field to be stored as a list in the database.If this field is not set, its default value is
[].- Parameters:
field (None) – an optional
Fieldinstance describing the type of the list elementsdescription (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- quaternion#
A list field that wraps a standard
Field, allowing multiple instances of the field to be stored as a list in the database.If this field is not set, its default value is
[].- Parameters:
field (None) – an optional
Fieldinstance describing the type of the list elementsdescription (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- source_frame#
A unicode string field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- target_frame#
A unicode string field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- timestamp#
A 32 bit integer field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- covariance#
A list field that wraps a standard
Field, allowing multiple instances of the field to be stored as a list in the database.If this field is not set, its default value is
[].- Parameters:
field (None) – an optional
Fieldinstance describing the type of the list elementsdescription (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- validate(clean=True)#
Validates the transform data.
This method is called by mongoengine during save/validation.
- property transform_matrix: ndarray#
Returns the 4x4 homogeneous transformation matrix.
The matrix has the form:
[[R, t], [0, 1]]
where R is the 3x3 rotation and t is the 3x1 translation.
- Returns:
a (4, 4) numpy array
- classmethod from_matrix(matrix: ndarray, source_frame: str | None = None, target_frame: str | None = None, **kwargs) StaticTransform#
Creates a StaticTransform instance from a 3x4 or 4x4 matrix.
- Parameters:
matrix – a (3, 4) or (4, 4) transformation matrix [R|t]
source_frame – name of source coordinate frame
target_frame – name of target coordinate frame
**kwargs – additional fields to set on the instance
- Returns:
a
StaticTransforminstance
- inverse() StaticTransform#
Returns the inverse transformation.
If this transform is source_frame -> target_frame, the inverse is target_frame -> source_frame.
- Returns:
a
StaticTransformrepresenting the inverse transform
- compose(other: StaticTransform) StaticTransform#
Composes this transform with another.
If self is A->B and other is B->C, the result is A->C.
- Mathematically:
X_C = T_BC @ X_B = T_BC @ (T_AB @ X_A) So T_AC = T_BC @ T_AB (other @ self)
- Parameters:
other – another
StaticTransformto compose with. The source_frame ofothershould match target_frame ofselffor the frames to chain correctly.- Returns:
a
StaticTransformrepresenting the composed transform- Raises:
ValueError – if the frames don’t chain (self.target_frame != other.source_frame when both are specified)
- STRICT = False#
- clean()#
Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clear_field(field_name)#
Clears the field from the document.
- Parameters:
field_name – the field name
- Raises:
ValueError – if the field does not exist
- copy()#
Returns a deep copy of the document.
- Returns:
a
SerializableDocument
- fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)#
Generates a customizable string representation of the document.
- Parameters:
class_name (None) – optional class name to use
select_fields (None) – iterable of field names to restrict to
exclude_fields (None) – iterable of field names to exclude
**kwargs – additional key-value pairs to include in the string representation
- Returns:
a string representation of the document
- property field_names#
An ordered tuple of the public fields of this document.
- field_to_mongo(field_name)#
- field_to_python(field_name, value)#
- classmethod from_dict(d, extended=False)#
Loads the document from a BSON/JSON dictionary.
- Parameters:
d – a dictionary
extended (False) – whether the input dictionary may contain serialized extended JSON constructs
- Returns:
a
SerializableDocument
- classmethod from_json(s)#
Loads the document from a JSON string.
- Returns:
a
SerializableDocument
- get_field(field_name)#
Gets the field of the document.
- Parameters:
field_name – the field name
- Returns:
the field value
- Raises:
AttributeError – if the field does not exist
- get_text_score()#
Get text score from text query
- has_field(field_name)#
Determines whether the document has a field of the given name.
- Parameters:
field_name – the field name
- Returns:
True/False
- iter_fields()#
Returns an iterator over the
(name, value)pairs of the public fields of the document.- Returns:
an iterator that emits
(name, value)tuples
- merge(doc, merge_lists=True, merge_dicts=True, overwrite=True)#
Merges the contents of the given document into this document.
- Parameters:
doc – a
SerializableDocumentof same type as this documentmerge_lists (True) – whether to merge the elements of top-level list fields rather than treating the list as a single value
merge_dicts (True) – whether to recursively merge the contents of top-level dict fields rather than treating the dict as a single value
overwrite (True) – whether to overwrite (True) or skip (False) existing fields
- my_metaclass#
alias of
DocumentMetaclass
- set_field(field_name, value, create=True)#
Sets the value of a field of the document.
- Parameters:
field_name – the field name
value – the field value
create (True) – whether to create the field if it does not exist
- Raises:
ValueError – if
field_nameis not an allowed field name or does not exist andcreate == False
- to_dict(extended=False)#
Serializes this document to a BSON/JSON dictionary.
- Parameters:
extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format
- Returns:
a dict
- to_json(pretty_print=False)#
Serializes the document to a JSON string.
- Parameters:
pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations
- Returns:
a JSON string
- to_mongo(*args, **kwargs)#
Return as SON data ready for use with MongoDB.
- class fiftyone.core.camera.CameraIntrinsicsRef(*args, **kwargs)#
Bases:
EmbeddedDocumentReference to dataset-level camera intrinsics.
Use this to reference intrinsics stored at the dataset level rather than embedding the full intrinsics data in each sample.
- Parameters:
ref – the sensor/camera name key in
dataset.camera_intrinsics
Example:
import fiftyone as fo # Reference dataset-level intrinsics (field name can be anything) sample["intrinsics"] = fo.CameraIntrinsicsRef(ref="camera_front")
Attributes:
A unicode string field.
An ordered tuple of the public fields of this document.
Methods:
clean()Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
clear_field(field_name)Clears the field from the document.
copy()Returns a deep copy of the document.
fancy_repr([class_name, select_fields, ...])Generates a customizable string representation of the document.
field_to_mongo(field_name)field_to_python(field_name, value)from_dict(d[, extended])Loads the document from a BSON/JSON dictionary.
from_json(s)Loads the document from a JSON string.
get_field(field_name)Gets the field of the document.
Get text score from text query
has_field(field_name)Determines whether the document has a field of the given name.
Returns an iterator over the
(name, value)pairs of the public fields of the document.merge(doc[, merge_lists, merge_dicts, overwrite])Merges the contents of the given document into this document.
set_field(field_name, value[, create])Sets the value of a field of the document.
to_dict([extended])Serializes this document to a BSON/JSON dictionary.
to_json([pretty_print])Serializes the document to a JSON string.
to_mongo(*args, **kwargs)Return as SON data ready for use with MongoDB.
validate([clean])Ensure that all fields' values are valid and that required fields are present.
Classes:
alias of
DocumentMetaclass- ref#
A unicode string field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- STRICT = False#
- clean()#
Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clear_field(field_name)#
Clears the field from the document.
- Parameters:
field_name – the field name
- Raises:
ValueError – if the field does not exist
- copy()#
Returns a deep copy of the document.
- Returns:
a
SerializableDocument
- fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)#
Generates a customizable string representation of the document.
- Parameters:
class_name (None) – optional class name to use
select_fields (None) – iterable of field names to restrict to
exclude_fields (None) – iterable of field names to exclude
**kwargs – additional key-value pairs to include in the string representation
- Returns:
a string representation of the document
- property field_names#
An ordered tuple of the public fields of this document.
- field_to_mongo(field_name)#
- field_to_python(field_name, value)#
- classmethod from_dict(d, extended=False)#
Loads the document from a BSON/JSON dictionary.
- Parameters:
d – a dictionary
extended (False) – whether the input dictionary may contain serialized extended JSON constructs
- Returns:
a
SerializableDocument
- classmethod from_json(s)#
Loads the document from a JSON string.
- Returns:
a
SerializableDocument
- get_field(field_name)#
Gets the field of the document.
- Parameters:
field_name – the field name
- Returns:
the field value
- Raises:
AttributeError – if the field does not exist
- get_text_score()#
Get text score from text query
- has_field(field_name)#
Determines whether the document has a field of the given name.
- Parameters:
field_name – the field name
- Returns:
True/False
- iter_fields()#
Returns an iterator over the
(name, value)pairs of the public fields of the document.- Returns:
an iterator that emits
(name, value)tuples
- merge(doc, merge_lists=True, merge_dicts=True, overwrite=True)#
Merges the contents of the given document into this document.
- Parameters:
doc – a
SerializableDocumentof same type as this documentmerge_lists (True) – whether to merge the elements of top-level list fields rather than treating the list as a single value
merge_dicts (True) – whether to recursively merge the contents of top-level dict fields rather than treating the dict as a single value
overwrite (True) – whether to overwrite (True) or skip (False) existing fields
- my_metaclass#
alias of
DocumentMetaclass
- set_field(field_name, value, create=True)#
Sets the value of a field of the document.
- Parameters:
field_name – the field name
value – the field value
create (True) – whether to create the field if it does not exist
- Raises:
ValueError – if
field_nameis not an allowed field name or does not exist andcreate == False
- to_dict(extended=False)#
Serializes this document to a BSON/JSON dictionary.
- Parameters:
extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format
- Returns:
a dict
- to_json(pretty_print=False)#
Serializes the document to a JSON string.
- Parameters:
pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations
- Returns:
a JSON string
- to_mongo(*args, **kwargs)#
Return as SON data ready for use with MongoDB.
- validate(clean=True)#
Ensure that all fields’ values are valid and that required fields are present.
Raises
ValidationErrorif any of the fields’ values are found to be invalid.
- class fiftyone.core.camera.StaticTransformRef(*args, **kwargs)#
Bases:
EmbeddedDocumentReference to dataset-level static transform.
Use this to reference transforms stored at the dataset level rather than embedding the full transform data in each sample.
- Parameters:
ref – the key in
dataset.static_transforms, either “source_frame::target_frame” or just “source_frame” (implies target is “world”)
Example:
import fiftyone as fo # Reference dataset-level transform (field name can be anything) sample["transform"] = [ fo.StaticTransformRef(ref="camera_front::ego"), ]
Attributes:
A unicode string field.
An ordered tuple of the public fields of this document.
Methods:
clean()Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
clear_field(field_name)Clears the field from the document.
copy()Returns a deep copy of the document.
fancy_repr([class_name, select_fields, ...])Generates a customizable string representation of the document.
field_to_mongo(field_name)field_to_python(field_name, value)from_dict(d[, extended])Loads the document from a BSON/JSON dictionary.
from_json(s)Loads the document from a JSON string.
get_field(field_name)Gets the field of the document.
Get text score from text query
has_field(field_name)Determines whether the document has a field of the given name.
Returns an iterator over the
(name, value)pairs of the public fields of the document.merge(doc[, merge_lists, merge_dicts, overwrite])Merges the contents of the given document into this document.
set_field(field_name, value[, create])Sets the value of a field of the document.
to_dict([extended])Serializes this document to a BSON/JSON dictionary.
to_json([pretty_print])Serializes the document to a JSON string.
to_mongo(*args, **kwargs)Return as SON data ready for use with MongoDB.
validate([clean])Ensure that all fields' values are valid and that required fields are present.
Classes:
alias of
DocumentMetaclass- ref#
A unicode string field.
- Parameters:
description (None) – an optional description
info (None) – an optional info dict
read_only (False) – whether the field is read-only
created_at (None) – the datetime the field was created
- STRICT = False#
- clean()#
Hook for doing document level data cleaning (usually validation or assignment) before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- clear_field(field_name)#
Clears the field from the document.
- Parameters:
field_name – the field name
- Raises:
ValueError – if the field does not exist
- copy()#
Returns a deep copy of the document.
- Returns:
a
SerializableDocument
- fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)#
Generates a customizable string representation of the document.
- Parameters:
class_name (None) – optional class name to use
select_fields (None) – iterable of field names to restrict to
exclude_fields (None) – iterable of field names to exclude
**kwargs – additional key-value pairs to include in the string representation
- Returns:
a string representation of the document
- property field_names#
An ordered tuple of the public fields of this document.
- field_to_mongo(field_name)#
- field_to_python(field_name, value)#
- classmethod from_dict(d, extended=False)#
Loads the document from a BSON/JSON dictionary.
- Parameters:
d – a dictionary
extended (False) – whether the input dictionary may contain serialized extended JSON constructs
- Returns:
a
SerializableDocument
- classmethod from_json(s)#
Loads the document from a JSON string.
- Returns:
a
SerializableDocument
- get_field(field_name)#
Gets the field of the document.
- Parameters:
field_name – the field name
- Returns:
the field value
- Raises:
AttributeError – if the field does not exist
- get_text_score()#
Get text score from text query
- has_field(field_name)#
Determines whether the document has a field of the given name.
- Parameters:
field_name – the field name
- Returns:
True/False
- iter_fields()#
Returns an iterator over the
(name, value)pairs of the public fields of the document.- Returns:
an iterator that emits
(name, value)tuples
- merge(doc, merge_lists=True, merge_dicts=True, overwrite=True)#
Merges the contents of the given document into this document.
- Parameters:
doc – a
SerializableDocumentof same type as this documentmerge_lists (True) – whether to merge the elements of top-level list fields rather than treating the list as a single value
merge_dicts (True) – whether to recursively merge the contents of top-level dict fields rather than treating the dict as a single value
overwrite (True) – whether to overwrite (True) or skip (False) existing fields
- my_metaclass#
alias of
DocumentMetaclass
- set_field(field_name, value, create=True)#
Sets the value of a field of the document.
- Parameters:
field_name – the field name
value – the field value
create (True) – whether to create the field if it does not exist
- Raises:
ValueError – if
field_nameis not an allowed field name or does not exist andcreate == False
- to_dict(extended=False)#
Serializes this document to a BSON/JSON dictionary.
- Parameters:
extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format
- Returns:
a dict
- to_json(pretty_print=False)#
Serializes the document to a JSON string.
- Parameters:
pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations
- Returns:
a JSON string
- to_mongo(*args, **kwargs)#
Return as SON data ready for use with MongoDB.
- validate(clean=True)#
Ensure that all fields’ values are valid and that required fields are present.
Raises
ValidationErrorif any of the fields’ values are found to be invalid.
- class fiftyone.core.camera.CameraProjector(intrinsics: CameraIntrinsics, camera_to_reference: StaticTransform | None = None, camera_convention: str = 'opencv')#
Bases:
objectUtility class for projecting points between 3D and 2D.
Combines camera intrinsics and optional transforms to perform projection and unprojection operations.
- Parameters:
intrinsics – a
CameraIntrinsicsinstancecamera_to_reference (None) –
optional
StaticTransformdefining the camera-to-reference transformation (i.e., the camera’s pose in the reference frame). If provided, 3D points passed toproject()are assumed to be in the reference frame (camera_to_reference.target_frame) and will be transformed to camera frame before projection.The transform should have:
source_frame: the camera/sensor name (e.g., “cam_front”)target_frame: the reference frame (e.g., “world”, “ego”)
camera_convention ("opencv") – 3D camera axis convention, either “opencv” (z-forward, x-right, y-down) or “opengl” (z-backward, x-right, y-up). Note: This only affects the 3D coordinate axes. Pixel coordinates always follow image-space convention with +x right, +y down, origin at top-left
Important
Transform direction: This class expects camera-to-reference transforms, NOT reference-to-camera. If you have a reference-to-camera transform (e.g., world-to-camera), invert it first:
projector = fo.CameraProjector(intrinsics, world_to_cam.inverse())
Or use the
from_reference_to_camera()constructor.Example:
import fiftyone as fo import numpy as np intrinsics = fo.PinholeCameraIntrinsics( fx=1000.0, fy=1000.0, cx=960.0, cy=540.0 ) # Project points already in camera frame projector = fo.CameraProjector(intrinsics) points_3d = np.array([[0, 0, 10], [1, 2, 10]]) points_2d = projector.project(points_3d, in_camera_frame=True) # Project world points using camera-to-world transform cam_to_world = fo.StaticTransform( translation=[0.0, 0.0, 0.0], quaternion=[0.0, 0.0, 0.0, 1.0], source_frame="camera", target_frame="world", ) projector = fo.CameraProjector(intrinsics, cam_to_world) world_points = np.array([[0, 0, 10]]) pixels = projector.project(world_points, in_camera_frame=False)
Methods:
from_reference_to_camera(intrinsics, ...[, ...])Creates a CameraProjector from reference-to-camera transform.
project(points_3d[, in_camera_frame])Projects 3D points to 2D image coordinates.
unproject(points_2d, depth[, in_camera_frame])Unprojects 2D image points to 3D given depth.
- classmethod from_reference_to_camera(intrinsics: CameraIntrinsics, reference_to_camera: StaticTransform, camera_convention: str = 'opencv') CameraProjector#
Creates a CameraProjector from reference-to-camera transform.
Use this constructor if your transform converts points FROM the reference frame TO the camera frame (e.g., world-to-camera). This is common when loading from some datasets or calibration tools.
This method automatically inverts the transform to the expected camera-to-reference format.
- Parameters:
intrinsics – a
CameraIntrinsicsinstancereference_to_camera – a
StaticTransformthat transforms points from the reference frame to the camera framecamera_convention – “opencv” or “opengl”
- Returns:
a
CameraProjectorinstance
Example:
# If you have world-to-camera transform: world_to_cam = fo.StaticTransform( translation=[...], quaternion=[...], source_frame="world", target_frame="camera", ) projector = fo.CameraProjector.from_reference_to_camera( intrinsics, world_to_cam )
- project(points_3d: ndarray, in_camera_frame: bool = False) ndarray#
Projects 3D points to 2D image coordinates.
- Parameters:
points_3d – (N, 3) array of 3D points
in_camera_frame – if True, points are already in camera frame; if False and camera_to_reference is provided, points are transformed from the reference frame to camera frame
- Returns:
(N, 2) array of 2D pixel coordinates
- unproject(points_2d: ndarray, depth: float | ndarray, in_camera_frame: bool = False) ndarray#
Unprojects 2D image points to 3D given depth.
Note: For monocular cameras, depth must be provided from an external source (e.g., stereo, LiDAR, depth sensor, or depth estimation).
The depth is interpreted as z-depth in the camera coordinate frame (not Euclidean distance from camera center).
- Parameters:
points_2d – (N, 2) array of 2D pixel coordinates
depth – scalar or (N,) array of z-depth values in camera frame
in_camera_frame – if True, returns points in camera frame; if False and camera_to_reference is provided, transforms to the reference frame
- Returns:
(N, 3) array of 3D points