retinify 0.1.7
Real-Time AI Stereo Vision Library
Loading...
Searching...
No Matches
C++ Docs

Installation

Please refer to the Installation section for details.

Learning by example

Example code is available in the following repository:
👉 https://github.com/retinify/retinify-opencv-example

Key classes

Retinify is written in C++ and defined under the retinify:: namespace.
The following classes form the core API:

Retinify does not use C++ exceptions; all operations report their results via retinify::Status.

Using retinify with CMake

To use retinify in your CMake project, find the package and link against the provided target:

find_package(retinify REQUIRED)
target_link_libraries(${PROJECT_NAME} retinify::retinify)

Note that retinify requires GCC 11 or later.

Writing C++ code

The code in this section uses OpenCV's cv::Mat for image data.

Note
Retinify does not define its own image class and does not depend on OpenCV.
Image data is provided via raw pointers and stride information, allowing arbitrary image representations.

To perform stereo matching with rectified stereo images, use the following code:

#include <retinify/retinify.hpp>
#include <opencv2/opencv.hpp>
// LOAD RECTIFIED STEREO INPUT IMAGES
cv::Mat leftImage = cv::imread("path/to/left.png");
cv::Mat rightImage = cv::imread("path/to/right.png");
// PREPARE OUTPUT BUFFERS
cv::Mat disparity = cv::Mat::zeros(leftImage.size(), CV_32FC1);
// CREATE THE STEREO MATCHING PIPELINE
// INITIALIZE THE PIPELINE
auto statusInitialize = pipeline.Initialize(static_cast<std::uint32_t>(leftImage.cols),
static_cast<std::uint32_t>(leftImage.rows));
if (!statusInitialize.IsOK())
{
return 1;
}
// EXECUTE STEREO MATCHING
auto statusExecute = pipeline.Execute(leftImage.ptr<std::uint8_t>(), leftImage.step[0],
rightImage.ptr<std::uint8_t>(), rightImage.step[0]);
if (!statusExecute.IsOK())
{
return 1;
}
// RETRIEVE DISPARITY
auto statusRetrieve = pipeline.RetrieveDisparity(disparity.ptr<float>(), disparity.step[0]);
if (!statusRetrieve.IsOK())
{
return 1;
}
A retinify::Pipeline provides an interface for running a stereo matching.
Definition pipeline.hpp:46
auto RetrieveDisparity(float *disparityData, std::size_t disparityStride) noexcept -> Status
Retrieves the computed disparity map.
auto Initialize(std::uint32_t imageWidth, std::uint32_t imageHeight, PixelFormat pixelFormat=PixelFormat::RGB8, DepthMode depthMode=DepthMode::ACCURATE, const CalibrationParameters &calibrationParameters=CalibrationParameters{}) noexcept -> Status
Initializes the stereo matching pipeline with the given image dimensions.
auto Execute(const std::uint8_t *leftImageData, std::size_t leftImageStride, const std::uint8_t *rightImageData, std::size_t rightImageStride) noexcept -> Status
Executes the stereo matching pipeline using the given left and right image data.

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:

#include <retinify/retinify.hpp>
#include <opencv2/opencv.hpp>
// LOAD NON-RECTIFIED STEREO INPUT IMAGES
cv::Mat leftImage = cv::imread("path/to/left.png");
cv::Mat rightImage = cv::imread("path/to/right.png");
// PREPARE OUTPUT BUFFERS
cv::Mat leftRectifiedImage = cv::Mat::zeros(leftImage.size(), leftImage.type());
cv::Mat disparity = cv::Mat::zeros(leftImage.size(), CV_32FC1);
cv::Mat depth = cv::Mat::zeros(leftImage.size(), CV_32FC1);
cv::Mat pointCloud = cv::Mat::zeros(leftImage.size(), CV_32FC3);
// LOAD CALIBRATION PARAMETERS
auto statusLoadCalib = retinify::LoadCalibrationParameters("path/to/calib.json", calibParams);
if (!statusLoadCalib.IsOK())
{
return 1;
}
// CREATE THE STEREO MATCHING PIPELINE
// INITIALIZE THE PIPELINE WITH CALIBRATION PARAMETERS
auto statusInitialize = pipeline.Initialize(static_cast<std::uint32_t>(leftImage.cols),
static_cast<std::uint32_t>(leftImage.rows),
calibParams);
if (!statusInitialize.IsOK())
{
return 1;
}
// EXECUTE STEREO MATCHING
auto statusExecute = pipeline.Execute(leftImage.ptr<std::uint8_t>(), leftImage.step[0],
rightImage.ptr<std::uint8_t>(), rightImage.step[0]);
if (!statusExecute.IsOK())
{
return 1;
}
// RETRIEVE RECTIFIED LEFT IMAGE
auto statusRetrieveLeftRectified = pipeline.RetrieveRectifiedLeftImage(leftRectifiedImage.ptr<std::uint8_t>(), leftRectifiedImage.step[0]);
if (!statusRetrieveLeftRectified.IsOK())
{
return 1;
}
// RETRIEVE DISPARITY
auto statusRetrieveDisparity = pipeline.RetrieveDisparity(disparity.ptr<float>(), disparity.step[0]);
if (!statusRetrieveDisparity.IsOK())
{
return 1;
}
// RETRIEVE DEPTH
auto statusRetrieveDepth = pipeline.RetrieveDepth(depth.ptr<float>(), depth.step[0]);
if (!statusRetrieveDepth.IsOK())
{
return 1;
}
// RETRIEVE POINT CLOUD
auto statusRetrievePointCloud = pipeline.RetrievePointCloud(pointCloud.ptr<float>(), pointCloud.step[0]);
if (!statusRetrievePointCloud.IsOK())
{
return 1;
}
auto RetrieveDepth(float *depthData, std::size_t depthStride) noexcept -> Status
Retrieves the computed depth map.
auto RetrieveRectifiedLeftImage(std::uint8_t *leftImageData, std::size_t leftImageStride) noexcept -> Status
Retrieves the rectified left image.
auto RetrievePointCloud(float *pointCloudData, std::size_t pointCloudStride) noexcept -> Status
Reprojects the computed disparity map to a 3D point cloud.
@ RGB8
8-bit 3ch, RGB format
@ ACCURATE
Most accurate, with slowest performance.
RETINIFY_API auto LoadCalibrationParameters(const char *filename, CalibrationParameters &parameters) noexcept -> Status
Load stereo calibration parameters.
Stereo camera calibration parameters.
Definition geometry.hpp:266