Guide to 3D reconstruction from a sequence of stereo images using the StereoReconstructionAlgorithm class.
Guide to 3D reconstruction from a sequence of stereo images using the StereoReconstructionAlgorithm class.
Stereo Reconstruction Overview
Stereo reconstruction is a computer vision technique that estimates the 3D structure of a scene from two images taken from different viewpoints. By analyzing the disparity (difference in pixel positions) between corresponding points in stereo images, the algorithm can compute depth information and generate 3D reconstruction.
The StereoReconstructionAlgorithm class provides a high-level interface for stereo reconstruction, while the underlying StereoReconstruction class handles the core reconstruction logic.
Basic Stereo Reconstruction Usage
Basic Stereo Reconstruction
The following example demonstrates basic usage of the StereoReconstructionAlgorithm where we assume the input is
- Left and right stereo images given as
leftImages, rightImages of type std::unique_ptr<SharedImageSet>.
- Left and right intrinsic matrices given as
leftK and rightK of type Eigen::Matrix3d
- Transformation of right camera w.r.t. the left camera given as
registration of type Eigen::Matrix4d
#include <ImFusion/Base/SharedImageSet.h>
#include <ImFusion/Base/DataList.h>
#include <ImFusion/Vision/CameraCalibrationDataComponent.h>
#include <ImFusion/Vision/StereoReconstructionAlgorithm.h>
leftCalib.p_K = leftK;
leftCalib.p_distortion = dist;
leftCalib.p_camToWorldT = Eigen::Matrix4d::Identity();
rightCalib.p_K = rightK;
rightCalib.p_distortion = dist;
rightCalib.p_camToWorldT = registration;
auto stereoSet = StereoSharedImageSet::create(std::move(leftImages), std::move(rightImages));
stereoReconstructor.p_stereoReconstructionName = "Stereo RAFT";
stereoReconstructor.p_exportRectifiedImages = true;
stereoReconstructor.p_exportPointClouds = true;
stereoReconstructor.compute();
for (auto& output : outputImages)
{
if (output)
{
if (output->name() == "Disparity")
disparityResult = std::move(output);
else if (output->name() == "Depth")
depthResult = std::move(output);
}
}
std::vector<std::unique_ptr<PointCloud>> pointCloudsResult;
if (stereoReconstructor.p_exportPointClouds) {
for (auto& pc : pointClouds)
{
if (pc)
}
}
A data component storing mainly the intrinsic calibration of a pinhole camera Information such as ima...
Definition CameraCalibrationDataComponent.h:22
@ POINTSET
Set of points.
Definition Data.h:40
Wrapper class to store a list of owned Data instances.
Definition OwningDataList.h:24
std::vector< std::unique_ptr< SharedImageSet > > extractAllImages(Data::Kind kind=Data::UNKNOWN, Data::Modality modality=Data::NA)
Extract all SharedImageSet instances of given kind and modality.
Data structure for point clouds.
Definition PointCloud.h:24
This algorithm performs 3D reconstruction from a pair of stereo images.
Definition StereoReconstructionAlgorithm.h:30
T emplace_back(T... args)
Namespace of the ImFusion SDK.
Definition Assert.h:7
- See also
- StereoReconstructionAlgorithm
Custom Models
StereoReconstruction allow running your custom models through our machine learning engines.
This is done by tracing or scripting your Torch or exporting your ONNX model and linking it through a configuration file.
Here is an example configuration file in .yaml format for StereoReconstruction:
Version: '8.0'
Name: CustomModel
Description: Stereo Reconstruction
Name: torch
DisableJITRecompile: true
ModelFile: <path_to_model_file>
Verbose: true
InputFields: [LeftImage, RightImage]
OutputFields: [Disparity]
PreprocessingInputFields: [FirstImage, SecondImage]
PreProcessing:
- MakeFloat: {}
Sampling:
- SkipUnpadding: true
Base class and interface for images.
Definition Image.h:29
Generic interface for machine learning models serialized by specific frameworks (PyTorch,...
Definition Engine.h:47
PredictionOutput
Types of prediction output.
Definition MLCommon.h:56
@ NeuralNetwork
Neural network (standard value)
Definition MLCommon.h:42
@ ForceCPU
Force computation on the CPU.
Definition MLCommon.h:20
We require InputFields and OutputFields to have exactly the same names as mentioned above. In our current release, we only support the Depth output to be exposed to the user, returned as the first element by the model. Any additional outputs should still be appended in OutputFields and PredictionOutput with its return type but they will be discarded.
For further information on the machine learning configuration files, please refer to the Machine Learning Model page in our user documentation.