transform.py

This module contains helper functions of fitting a cameratransform.Camera object and using it to transform image point to real-world points, and functions for extracting exif data, and estimating sensor size.

This module is a work in progress.

Functions

ct_assist.transform.fit(img: PIL.Image.Image, reference: numpy.ndarray, height: numpy.ndarray, STD: int, meta_data: dict = None, iters=10000.0, verbose=False, seed: int = None, multi: bool = False, max_height: int = 3, _depth=0) → cameratransform.camera.Camera[source]

Creates a trained CameraTransform.Camera object. See “https://cameratransform.readthedocs.io/en/latest/camera.html”.

Parameters
  • img (Image.Image) – Photograph in PIL image format

  • reference (np.ndarray) – Tuple with reference object (heads, feet), dim=(2, n, 2)

  • height (np.ndarray or float) – Height(s) of reference

  • STD (np.ndarray or float) – STD(s) of reference

  • meta_data (dict) – image meta data for intrinsic camera properties, defaults to None

  • iters (int) – Amount of iterations in Monte Carlo simulation, defaults to 1e4

  • verbose (bool) – If progress bar and trace should be printed, defaults to False

  • seed (int) – Random seed to be passed to numpy.random.seed (not recommended)

  • multi (bool) – If multiple object types are passed, changes STD, height, and reference shapes and types, defauls to False

  • max_height (int) – Maximum height for camera, defaults to 3 (meters)

Returns

image_coords transformed to real-world coordinates

Return type

np.ndarray

ct_assist.transform.fit_transform(img: PIL.Image.Image, reference: numpy.ndarray, height: numpy.ndarray, STD: int, image_coords: numpy.ndarray, meta_data: dict = None, z: float = 0.0, iters=10000.0, verbose=False, seed: int = None, multi: bool = False, max_height: int = 3) → numpy.ndarray[source]

Function composition for transforming image-coordinates to real-world coordinates using the other functions declared in transform.py.

Parameters
  • img (Image.Image) – Photograph in PIL image format

  • reference (np.ndarray) – Tuple with reference object (heads, feet), dim=(2, n, 2)

  • height (np.ndarray or float) – Height(s) of reference

  • STD (np.ndarray or float) – STD(s) of reference

  • image_coords (np.ndarray or list) – Coordinates to transform, [[x0, y0], [x1, y1], [x2, y2]]

  • meta_data (dict) – image meta data for intrinsic camera properties, defaults to None

  • iters (int) – Amount of iterations in Monte Carlo simulation, defaults to 1e4

  • verbose (bool) – If progress bar and trace should be printed, defaults to False

  • seed (int) – Random seed to be passed to numpy.random.seed (not recommended)

  • multi (bool) – If multiple object types are passed, changes STD, height, and reference shapes and types, defauls to False

Returns

image_coords transformed to real-world coordinates

Return type

np.ndarray

ct_assist.transform.get_Exif(img: PIL.Image.Image) → Tuple[float, Tuple[int, int], Tuple[float, float]][source]

Extracts or estimates image meta data for Camera intrinsic properties.

Extracts:
  • Focal length

  • Image size

  • Sensor size

Parameters

img (Image.Image) – Photograph in PIL image format

Returns

(focal length, image size, sensor size)

Return type

Tuple[float, Tuple[int, int], Tuple[float, float]]

ct_assist.transform.sensor_size_crop_factor(effective_f: float, actual_f: float) → Tuple[float, float][source]

Estimates sensor size based on effective and actual focal length, comparing to a standard 35 mm film camera.

Parameters
  • effective_f (float) – Effective focal length

  • actual_f (float) – Actual focal length

Returns

Sensor size

Return type

Tuple[float, float]

ct_assist.transform.sensor_size_look_up(model_name: str)[source]

Looks up the sensor size of the photographic device with name model_name.

Parameters

model_name (str) – Model name

ct_assist.transform.sensor_size_resolution(resolution: Tuple, image_size: Tuple[int, int]) → Tuple[float, float][source]

Estimates sensor size based on FocalPlaneXResolution and FocalPlaneYResolution and image size. Based on CameraTransform’s sensor size estimation.

Parameters
  • resolution (Tuple[FocalPlaneXResolution, FocalPlaneYResolution]) – (FocalPlaneXResolution, FocalPlaneYResolution)

  • image_size (Tuple[int, int]) – Image size in pixels, w * h

Returns

Sensor size

Return type

Tuple[float, float]