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.
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.
[Get or Set] The camera used by the view. |
|
[Get or Set] The image viewed by the camera. |
|
[Get] The shape of the image. |
|
[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.
|
Project 3D world points to 2D pixel points using the camera's intrinsic, extrinsic, and distortion parameters. |
|
Project 3D world points to 2D pixel points using the camera's intrinsic, extrinsic, and distortion parameters from a |
|
Project 3D world points to gray level or image values using the camera's intrinsic, extrinsic, distortion parameters and image interpolation function. |
|
Project 3D world points to gray level using the camera's intrinsic, extrinsic, distortion parameters and image interpolation function from a |
Visualize 2D Projections#
The View class provides a method to visualize the 2D projection of 3D points onto the image plane.
|
Visualize the projected 2D points of a |
|
Visualize the projected 2D mesh of a |