Comprehensive guide to implementing a CustomRGBDStream with the ImFusion RGB-D Plugin.
Comprehensive guide to implementing a CustomRGBDStream with the ImFusion RGB-D Plugin.
This page provides step-by-step instructions and code snippets for implementing your own RGBDStream subclass to interface with custom or unsupported RGB-D sensors. The example below demonstrates how to implement the required methods for device enumeration, format selection, calibration, and frame acquisition.
Overview
To integrate a new RGB-D sensor, derive a class from RGBDStream and implement all required virtual methods. This enables your sensor to be used seamlessly with ImFusion's algorithms and visualization tools.
Implementation Steps
Class Definition
Start by defining your class and inheriting from RGBDStream:
{
public:
CustomRGBDStream();
~CustomRGBDStream() override;
bool depthFormat(FrameInfo& format) const override;
bool colorFormat(FrameInfo& format) const override;
bool setDepthFormat(const FrameInfo& format) override;
bool setColorFormat(const FrameInfo& format) override;
bool supportsColor() const override;
int depthImageWidth() const override;
int depthImageHeight() const override;
int colorImageWidth() const override;
int colorImageHeight() const override;
bool depthK(mat3& K)
const override;
bool depthDist(Eigen::Matrix<double, 5, 1>& dist)
const override;
bool colorK(mat3& K)
const override;
bool colorDist(Eigen::Matrix<double, 5, 1>& dist)
const override;
protected:
private:
FrameInfo m_colorFormat;
FrameInfo m_depthFormat;
mat3 m_depthK;
vec5 m_depthDist;
mat3 m_colorK;
vec5 m_colorDist;
mat4 m_depthToColorT;
int m_frame = 0;
bool m_running = false;
};
Base class for RGB-D streams.
Definition RGBDStream.h:26
virtual bool depthToColorT(mat4 &T) const
Retrieve depth to color camera coordinate transformation if available.
Definition RGBDStream.h:153
virtual bool defaultDepthResolution(int &width, int &height)
Returns default depth resolution.
Definition RGBDStream.h:194
virtual bool colorK(mat3 &K) const
Retrieve color camera intrinsics if available.
Definition RGBDStream.h:147
virtual bool depthDist(Eigen::Matrix< double, 5, 1 > &dist) const
Retrieve depth camera distortion parameters if available.
Definition RGBDStream.h:140
virtual bool defaultColorResolution(int &width, int &height)
Returns default color resolution.
Definition RGBDStream.h:192
virtual bool colorDist(Eigen::Matrix< double, 5, 1 > &dist) const
Retrieve color camera distortion parameters if available.
Definition RGBDStream.h:150
virtual bool depthK(mat3 &K) const
Retrieve depth camera intrinsics if available.
Definition RGBDStream.h:137
virtual bool openImpl()=0
Open stream.
virtual std::string uuid()=0
Unique identifier for stream.
virtual std::optional< WorkContinuation > doWork()=0
Create one StreamData and publish it (this function will be called at the desired frame rate) If this...
virtual bool stopImpl()=0
Stop stream.
virtual bool closeImpl()=0
Close stream.
virtual bool startImpl()=0
Start stream.
Device Enumeration
Implement a static method to enumerate available devices:
Format Support
Report supported formats and allow selection:
{
return true;
}
{
return true;
}
bool CustomRGBDStream::setDepthFormat(const FrameInfo& format)
{
return format == m_depthFormat;
}
bool CustomRGBDStream::setColorFormat(const FrameInfo& format)
{
return format == m_colorFormat;
}
Calibration and Metadata
Implement methods to provide camera intrinsics, distortion, and transformation:
bool CustomRGBDStream::depthK(mat3& K) const { K = m_depthK; return true; }
bool CustomRGBDStream::colorK(mat3& K) const { K = m_colorK; return true; }
bool CustomRGBDStream::depthDist(Eigen::Matrix<double, 5, 1>& dist) const { dist = m_depthDist; return true; }
bool CustomRGBDStream::colorDist(Eigen::Matrix<double, 5, 1>& dist) const { dist = m_colorDist; return true; }
bool CustomRGBDStream::depthToColorT(mat4& T) const { T = m_depthToColorT; return true; }
Lifecycle Methods
Implement open/close/start/stop to manage device resources:
bool CustomRGBDStream::openImpl()
{
return true;
}
bool CustomRGBDStream::closeImpl()
{
return true;
}
bool CustomRGBDStream::startImpl()
{
m_running = true;
return true;
}
bool CustomRGBDStream::stopImpl()
{
m_running = false;
return true;
}
Frame Acquisition
Implement the main frame acquisition loop in doWork():
{
RGBDFrame frame(this, m_colorImg.get(), m_depthImg.get(), nullptr, nullptr);
frame.setTimestampArrival(...);
frame.setTimestampColor(...);
frame.setTimestampDepth(...);
frame.components().add<RGBDDataComponent>(getRGBDDataComponentCopy());
signalNewData.emitSignal(frame);
m_frame++;
return WorkContinuation{std::nullopt};
}
Default Resolutions
Implement default resolution queries:
bool CustomRGBDStream::defaultColorResolution(int& width, int& height)
{
width = m_colorFormat.width;
height = m_colorFormat.height;
return true;
}
bool CustomRGBDStream::defaultDepthResolution(int& width, int& height)
{
width = m_depthFormat.width;
height = m_depthFormat.height;
return true;
}
Tips
- Always provide accurate calibration and metadata for best reconstruction results.
- Use the RGBDDataComponent to store sensor-specific information.
- Handle errors and edge cases in all lifecycle methods.
- See also
- CustomRGBDStream Class
-
RGBDStream Base Class