ImFusion C++ SDK 4.5.0
ImFusion::OpenCV Namespace Reference

Conversion between ImFusion and OpenCV image containers and primitives. More...

Detailed Description

Conversion between ImFusion and OpenCV image containers and primitives.

Functions

bool convert (MemImage *imgIn, cv::Mat &matOut, bool container=true)
 Convert 2D image to OpenCV, possibly in container mode Warning: Container mode does not support correctly colored images (RGB vs BGR).
cv::Mat convert (MemImage *img, bool container=true)
std::unique_ptr< TypedImage< double > > convert (cv::Mat &matIn)
std::unique_ptr< MemImageconvert (cv::Mat &matIn, std::optional< PixelType > targetType, bool convertBGR2RGB=true)
 Converts an OpenCV image to a MemImage.
std::optional< mat4 > convert (const cv::Mat &rotation, const cv::Mat &translation)
 Converts an OpenCV pose representation (rotation and translation) into a homogeneous SE(3) transform (4x4).
bool convert (const mat4 &se3Transform, cv::Mat &rvecOut, cv::Mat &tvecOut)
 Converts a homogeneous SE(3) transform (4x4) into OpenCV pose parameters (Rodrigues rvec and translation tvec).
int type (const Image *desc)
 Get OpenCV data type from ImFusion type and channels.
std::vector< cv::Point2f > convertToPoint2fVector (const std::vector< vec2f > &p)
std::vector< cv::Point2d > convertToPoint2dVector (const std::vector< vec2f > &p)
std::vector< cv::Point2f > convertToPoint2fVector (const std::vector< vec2 > &p)
std::vector< cv::Point2d > convertToPoint2dVector (const std::vector< vec2 > &p)
std::vector< cv::Point3f > convertToPoint3fVector (const std::vector< vec3f > &p)
std::vector< cv::Point3d > convertToPoint3dVector (const std::vector< vec3f > &p)
std::vector< cv::Point3f > convertToPoint3fVector (const std::vector< vec3 > &p)
std::vector< cv::Point3d > convertToPoint3dVector (const std::vector< vec3 > &p)
std::vector< vec2 > convertFromPoint2fVector (const std::vector< cv::Point2f > &p)
std::vector< vec2 > convertFromPoint2dVector (const std::vector< cv::Point2d > &p)
std::vector< vec3 > convertFromPoint3fVector (const std::vector< cv::Point3f > &p)
std::vector< vec3 > convertFromPoint3dVector (const std::vector< cv::Point3d > &p)
std::shared_ptr< GlDenseDeformationconvertOpenCVDistortionToDeformation (const Image &imgDesc, const std::array< double, 5 > &distCoeffs, const mat3 &Kin, const mat3 &Kout, bool rescaleByExtent=true, bool flipY=false)
 Converts OpenCV undistort map to GlDenseDeformation.
std::shared_ptr< GlDenseDeformationconvertOpenCVDistortionToInverseDeformation (int width, int height, const std::array< double, 5 > &distCoeffs, const mat3 &Kin, bool flipY=false)
 Obtains a deformation field to model camera distortion using OpenCV.

Function Documentation

◆ convert() [1/3]

std::unique_ptr< MemImage > ImFusion::OpenCV::convert ( cv::Mat & matIn,
std::optional< PixelType > targetType,
bool convertBGR2RGB = true )

Converts an OpenCV image to a MemImage.

Parameters
matInThe input image
targetTypeThe PixelType the returned image should have, if not given a target format is chosen that matches the pixel format of matIn. (default is std::nullopt)
convertBGR2RGBOnly for three-channel color images: whether to convert the OpenCV-default BGR format to the RGB format used in MemImage (default is true)
Returns
a new MemImage

◆ convert() [2/3]

std::optional< mat4 > ImFusion::OpenCV::convert ( const cv::Mat & rotation,
const cv::Mat & translation )

Converts an OpenCV pose representation (rotation and translation) into a homogeneous SE(3) transform (4x4).

This function accepts a rotation either as a 3x3 rotation matrix \(R\) or as a Rodrigues rotation vector \(\omega\) (3x1 or 1x3). The translation must be a 3-element vector (3x1 or 1x3).

Note
Input matrices must be single-channel and of floating-point type (CV_32F or CV_64F). Conversion between float and double is handled internally by OpenCV/Eigen conversion utilities, but non-floating types are rejected.
If rotation is provided as a Rodrigues vector, it is converted to a 3x3 rotation matrix via cv::Rodrigues().
If translation is provided as a row vector (1x3), it is transposed internally to match a column vector.
Parameters
rotationRotation as either:
  • 3x3 matrix or
  • 3-element vector (shape 3x1 or 1x3). Must be single-channel CV_32F or CV_64F.
translationTranslation vector (shape 3x1 or 1x3). Must be single-channel CV_32F or CV_64F.
Returns
A 4x4 homogeneous transform on success; std::nullopt on invalid input (wrong type/shape/empty).

◆ convert() [3/3]

bool ImFusion::OpenCV::convert ( const mat4 & se3Transform,
cv::Mat & rvecOut,
cv::Mat & tvecOut )

Converts a homogeneous SE(3) transform (4x4) into OpenCV pose parameters (Rodrigues rvec and translation tvec).

Note
The routine validates that the rotation block is (approximately) a proper rotation matrix by checking:
  • \(\det(R) \approx 1\)
  • \(R R^T \approx I\)
Parameters
se3TransformHomogeneous 4x4 transform. The top-left 3x3 block is interpreted as rotation, and the top-right 3x1 block as translation.
rvecOutOutput Rodrigues rotation vector, a 3x1 CV_64F matrix
tvecOutOutput translation vector, a 3x1 CV_64F matrix.
Returns
true on success, false if the rotation is not orthonormal and positive-definite.

◆ convertOpenCVDistortionToDeformation()

std::shared_ptr< GlDenseDeformation > ImFusion::OpenCV::convertOpenCVDistortionToDeformation ( const Image & imgDesc,
const std::array< double, 5 > & distCoeffs,
const mat3 & Kin,
const mat3 & Kout,
bool rescaleByExtent = true,
bool flipY = false )

Converts OpenCV undistort map to GlDenseDeformation.

See also
cv::initUndistortRectifyMap If
Parameters
rescaleByExtentis false, output deformation is in pixel coordinates. Otherwise output deformation is in pixel coordinates component wise divided by extent of
imgDesc.
flipYdetermins whether to flip the Y coordinate from OpenCV representation

◆ convertOpenCVDistortionToInverseDeformation()

std::shared_ptr< GlDenseDeformation > ImFusion::OpenCV::convertOpenCVDistortionToInverseDeformation ( int width,
int height,
const std::array< double, 5 > & distCoeffs,
const mat3 & Kin,
bool flipY = false )

Obtains a deformation field to model camera distortion using OpenCV.

Parameters
distCoeffsare OpenCV-style distortion coefficients
Kinis the camera matrix (onto pixel coordinates).
flipYdetermins whether to flip the Y coordinate from OpenCV representation
See also
cv::initUndistortRectifyMap Warning: output deformation is in pixel coordinates.
Search Tab / S to search, Esc to close