Installation
First, follow the instructions in the Installation section to install retinify.
Then, install the Python bindings using:
pip install git+https://github.com/retinify/retinify-python.git
Writing Python code
The Python bindings of retinify are designed to use NumPy arrays as the primary input and output format.
Images loaded using libraries such as Pillow or opencv-python can be passed directly as numpy.ndarray objects.
To perform stereo matching with rectified stereo images, use the following code:
import numpy as np
from PIL import Image
from retinify import Pipeline
left = np.asarray(Image.open("path/to/left.png").convert("RGB"))
right = np.asarray(Image.open("path/to/right.png").convert("RGB"))
pipe = Pipeline()
pipe.initialize(image_width=left.shape[1],
image_height=left.shape[0])
pipe.execute(left, right)
disparity = pipe.retrieve_disparity()
When initializing the pipeline, you can provide calibration parameters to enable the following features:
- Distortion correction and rectification
- Depth and point cloud generation
To perform stereo matching with non-rectified stereo images, use the following code:
import numpy as np
from PIL import Image
from retinify import Pipeline, load_calibration_parameters, PixelFormat, DepthMode
left = np.asarray(Image.open("path/to/left.png").convert("RGB"))
right = np.asarray(Image.open("path/to/right.png").convert("RGB"))
calib_params = load_calibration_parameters("path/to/calib.json")
pipe = Pipeline()
pipe.initialize(image_width=left.shape[1],
image_height=left.shape[0],
pixel_format=PixelFormat.RGB8,
depth_mode=DepthMode.ACCURATE,
calibration_parameters=calib_params)
pipe.execute(left, right)
left_rectified = pipe.retrieve_rectified_left_image()
disparity = pipe.retrieve_disparity()
depth = pipe.retrieve_depth()
point_cloud = pipe.retrieve_point_cloud()