View#

View class#

class View(camera, image)[source]#

A view is a constructed by a camera and an image acquired by the camera.

If the sensor size of the camera changes, the image must be updated to reflect the new sensor dimensions.

Warning

  • If multiple views share the same camera, a change on the camera’s parameters will affect all views using that camera.

  • If multiple views share the same image, a change on the image will affect all views using that image.

  • An error will be raised if the image shape does not match the camera sensor size or if the camera sensor size or image shape change after the view creation.

See also

  • Camera for camera model and parameters.

  • Image for image representation and processing.

Parameters:
  • camera (Camera) – The camera that will be used to view the image.

  • image (Image) – The image that is viewed by the camera.

Instantiate a View object#

To instantiate a View object, you need to provide the camera (as a Camera object`) and the image (as a numpy.ndarray object).

Lets consider a simple OpenCV pinhole camera model without distortion. The intrinsic parameters can be defined from the camera matrix, and the extrinsic parameters from the rotation and translation vectors.

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

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,
    distortion=None,
    extrinsic=extrinsic,
)

The view can be instantiated with an image as follows:

import numpy
from pysdic import View, Image

image = Image.from_array(numpy.zeros((480, 640, 3), dtype=numpy.uint8))

view = View(
    camera=camera,
    image=image,
)

To load the extrinsic, intrinsic and distortion parameters from .json files, you can use the methods write_transform and read_transform from the package pycvcam (Artezaru/pycvcam).

Accessing View attributes#

You can access the view attributes such as camera and image.

View.camera

[Get or Set] The camera used by the view.

View.image

[Get or Set] The image viewed by the camera.

View.image_shape

[Get] The shape of the image.

View.camera_size

[Get] The size of the camera's sensor.

Manipulating View objects#

The view can be used to project 3D points into the 2D image plane.

View.project(world_points[, dx, dintrinsic, ...])

Project 3D world points to 2D pixel points using the camera's intrinsic, extrinsic, and distortion parameters.

View.project_points(world_points[, dx, ...])

Project 3D world points to 2D pixel points using the camera's intrinsic, extrinsic, and distortion parameters from a PointCloud instance.

View.image_project(world_points[, dx, ...])

Project 3D world points to gray level or image values using the camera's intrinsic, extrinsic, distortion parameters and image interpolation function.

View.image_project_points(world_points[, ...])

Project 3D world points to gray level using the camera's intrinsic, extrinsic, distortion parameters and image interpolation function from a PointCloud instance.

Visualize 2D Projections#

The View class provides a method to visualize the 2D projection of 3D points onto the image plane.

View.visualize_projected_point_cloud(point_cloud)

Visualize the projected 2D points of a pysdic.PointCloud on a 2D plot using matplotlib.

View.visualize_projected_mesh(mesh[, ...])

Visualize the projected 2D mesh of a pysdic.Mesh on a 2D plot using matplotlib.