ImFusion SDK 4.3
ImFusion::ProjectiveGeometry Namespace Reference

Collection of functions dealing with projective geometry. More...

Detailed Description

Collection of functions dealing with projective geometry.

Functions

void normalizePoints2D (const std::vector< vec2 > &ptsIn, std::vector< vec2 > &ptsOut, mat3 *T=0)
 Normalize points so that their centroid is at the origin and their average distance from the origin is sqrt(2)
 
void normalizePoints2D (const std::vector< vec3 > &ptsIn, std::vector< vec3 > &ptsOut, mat3 *T=0)
 Normalize points so that their centroid is at the origin and their average distance from the origin is sqrt(2)
 
void normalizePoints3D (const std::vector< vec4 > &ptsIn, std::vector< vec4 > &ptsOut, mat4 *T=0)
 Normalize points so that their centroid is at the origin and their average distance from the origin is sqrt(2)
 
bool computeHomography2D (const std::vector< vec3 > &x1, const std::vector< vec3 > &x2, mat3 &H)
 Compute homography H so that H*x1 = x2. x1 and x2 are vectors of points in homogeneous coordinates.
 
void computeProjectionMatrix (const vec3 &C, const vec3 &p1, const vec3 &p2, const vec3 &p3, const vec3 &p4, int w, int h, mat3 &K, mat3 &R, vec3 &t)
 Compute projection matrix for source-detector geometry p1, p2, p3 and p4 are the detector corner points in the order top-left, top-right, bottom-right and bottom-left as seen from the source.
 
bool computeProjectionMatrix (const std::vector< vec3 > &X, const std::vector< vec2 > &x, mat34 &P1, mat34 &P2, bool &P2IsAPossibleSolution)
 Estimate projection matrix from point correspondences.
 
bool computeCameraPose (const std::vector< vec3 > &X, const std::vector< vec2 > &x, const mat3 &K, const vec5 &distCoeffs, mat4 &T, double *mre=nullptr, std::vector< vec2 > *reprojectedPoints=nullptr)
 Estimate camera pose (i.e.
 
bool computeProjectionMatrix (const std::vector< vec3 > &X, const std::vector< vec2 > &x, mat34 &P)
 Compute projection matrix from point correspondences.
 
bool computeProjective3D (const std::vector< vec4 > &x1, const std::vector< vec4 > &x2, mat4 &P)
 Compute general 3D projective transformation so that P*x1 = x2.
 
bool computeAffine3D (const std::vector< vec4 > &x1, const std::vector< vec4 > &x2, mat4 &T)
 Compute 3D affine transformation so that T*x1 = x2.
 
void normalizePoints (const std::vector< vec2 > &pts, mat3 &T)
 Compute normalizing transformation for 2D points so that they are centered on the origin and the average distance from the origin is sqrt(2)
 
void normalizePoints (const std::vector< vec3 > &pts, mat4 &T)
 Compute normalizing transformation for 3D points so that they are centered on the origin and the average distance from the origin is sqrt(2)
 
double computeReprojectionError (const mat34 &P, const std::vector< vec3 > &X, const std::vector< vec2 > &x)
 Compute reprojection error.
 
double computeReprojectionError (const mat3 &K, const std::vector< mat3 > &R, const std::vector< vec3 > &t, const std::vector< vec3 > &X, const std::vector< std::vector< vec2 > > &x, const Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > &vis)
 Compute reprojection error over a sequence.
 
double triangulatePoint (const std::vector< vec2 > &x, const std::vector< mat34 > &P, vec3 &X, bool nonLinearRefinement=true)
 Triangulate point given image measurements and projection matrices.
 
void convertComputerVisionToOpenGlProjectionMatrix (const mat3 &K, const mat3 &R, const vec3 &t, int width, int height, double near, double far, mat4 &PM, mat4 &MV, bool flipImageYAxis=false)
 Convert a projection matrix to OpenGL representation from OpenCV convention In OpenCV convention the y-axis is flipped compared to OpenGL, and pixel coordinates are used.
 
void convertOpenGlToComputerVisionProjectionMatrix (const mat4 &PM, int width, int height, mat34 &P)
 Convert an OpenGL projection matrix to computer vision representation.
 
void decomposeProjectionMatrix (const mat34 &P, mat3 &K, mat3 &R, vec3 &t, bool checkOpenCVConvention=true)
 Decompose projection matrix into K, R and t.
 
vec3 reproject (const mat4 &projMat, const vec2 &imgPoint2D, double physicalWidth, vec3 &sourceOut3D, vec3 &imgOut3D, vec3 &zDirOut, double &fac)
 Reprojects a point on the image plane using an OpenGL projection matrix.
 
vec3 reproject (const mat4 &projMat, const vec2 &imgPoint2D, double physicalWidth, vec3 &sourceOut3D, vec3 &imgOut3D)
 Reprojects a point on the image plane using an OpenGL projection matrix.
 
void unproject (const mat3 &invK, double dist, const vec2 &pt2d, vec3 &pt3d)
 Unprojects a point on the image plane, where dist corresponds to the distance of pt3d from the xy plane and invK is the inverse calibration matrix of the camera.
 
void projectPoint (const mat34 &P, vec4 &pt3d, vec3 &pt2d, const bool normalize=true)
 Projects a 3d point to 2d using a 3x4 projection matrix.
 
void projectPoint (const mat34 &P, vec3 &pt3d, vec3 &pt2d, const bool normalize=true)
 Projects an inhomogenous 3d point to 2d using a 3x4 projection matrix.
 
std::vector< vec2 > projectPoints (const std::vector< vec3 > &pts3d, const mat3 &K, const mat3 &R, const vec3 &t, const vec5 &distCoeffs)
 Projects a vector of inhomogenous 3d points to 2d using intrinsics and distortion parameters.
 

Function Documentation

◆ computeProjectionMatrix() [1/3]

void computeProjectionMatrix ( const vec3 & C,
const vec3 & p1,
const vec3 & p2,
const vec3 & p3,
const vec3 & p4,
int w,
int h,
mat3 & K,
mat3 & R,
vec3 & t )

Compute projection matrix for source-detector geometry p1, p2, p3 and p4 are the detector corner points in the order top-left, top-right, bottom-right and bottom-left as seen from the source.

I.e. the outer border of the image. The points are assumed to lie on a plane. C is the position of the source. w and h is the detector width and height in pixels. K, R and t contain the computed projection matrix components.

◆ computeProjectionMatrix() [2/3]

bool computeProjectionMatrix ( const std::vector< vec3 > & X,
const std::vector< vec2 > & x,
mat34 & P1,
mat34 & P2,
bool & P2IsAPossibleSolution )

Estimate projection matrix from point correspondences.

Parameters
X3D points
x2D points
P1projection matrix (a most probable solution)
P2projection matrix (another possible solution)
P2IsAPossibleSolutionflag specifying whether projection matrix P2 could be a correct solution
Returns
true if successful

◆ computeCameraPose()

bool computeCameraPose ( const std::vector< vec3 > & X,
const std::vector< vec2 > & x,
const mat3 & K,
const vec5 & distCoeffs,
mat4 & T,
double * mre = nullptr,
std::vector< vec2 > * reprojectedPoints = nullptr )

Estimate camera pose (i.e.

transformation from world to camera)

Parameters
X3D points
x2D points
Kintrinsic parameters
distCoeffsdistortion parameters
Toutput camera pose
mreoptional output reprojection error
reprojectedPointsoptional output reprojected points
Returns
true if successful

◆ computeProjectionMatrix() [3/3]

bool computeProjectionMatrix ( const std::vector< vec3 > & X,
const std::vector< vec2 > & x,
mat34 & P )

Compute projection matrix from point correspondences.

Parameters
X3D points
x2D points
Pprojection matrix
Returns
true if successful

◆ normalizePoints() [1/2]

void normalizePoints ( const std::vector< vec2 > & pts,
mat3 & T )

Compute normalizing transformation for 2D points so that they are centered on the origin and the average distance from the origin is sqrt(2)

Parameters
ptspts
Tnormalizing transformation

◆ normalizePoints() [2/2]

void normalizePoints ( const std::vector< vec3 > & pts,
mat4 & T )

Compute normalizing transformation for 3D points so that they are centered on the origin and the average distance from the origin is sqrt(2)

Parameters
ptspts
Tnormalizing transformation

◆ computeReprojectionError() [1/2]

double computeReprojectionError ( const mat34 & P,
const std::vector< vec3 > & X,
const std::vector< vec2 > & x )

Compute reprojection error.

Parameters
Pprojection matrix
X3D points
x2D points
Returns
mean reprojection error

◆ computeReprojectionError() [2/2]

double computeReprojectionError ( const mat3 & K,
const std::vector< mat3 > & R,
const std::vector< vec3 > & t,
const std::vector< vec3 > & X,
const std::vector< std::vector< vec2 > > & x,
const Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > & vis )

Compute reprojection error over a sequence.

Parameters
Kintrinsic parameters
Rrotation matrices
ttranslations
X3D points
x2D points
visvisibility matrix
Returns
mean reprojection error

◆ triangulatePoint()

double triangulatePoint ( const std::vector< vec2 > & x,
const std::vector< mat34 > & P,
vec3 & X,
bool nonLinearRefinement = true )

Triangulate point given image measurements and projection matrices.

Parameters
ximage points
Pprojection matrices
Xtriangulated point
nonLinearRefinementif true, triangulated point is refined using non-linear optimization after linear estimation
Returns
mean reprojection error of triangulated point

◆ convertComputerVisionToOpenGlProjectionMatrix()

void convertComputerVisionToOpenGlProjectionMatrix ( const mat3 & K,
const mat3 & R,
const vec3 & t,
int width,
int height,
double near,
double far,
mat4 & PM,
mat4 & MV,
bool flipImageYAxis = false )

Convert a projection matrix to OpenGL representation from OpenCV convention In OpenCV convention the y-axis is flipped compared to OpenGL, and pixel coordinates are used.

Note
We use OpenCV convention for K, R, t. I.e. this function assumes that (0,0) is the pixel center of the top-left corner pixel of the image. Consequently the corner of the image is at (-0.5,-0.5).

◆ convertOpenGlToComputerVisionProjectionMatrix()

void convertOpenGlToComputerVisionProjectionMatrix ( const mat4 & PM,
int width,
int height,
mat34 & P )

Convert an OpenGL projection matrix to computer vision representation.

Warning
due to the associated half-pixel shift, the resulting projection matrix has range so that (0,0) is the pixel center of the top-left corner of the image.

◆ decomposeProjectionMatrix()

void decomposeProjectionMatrix ( const mat34 & P,
mat3 & K,
mat3 & R,
vec3 & t,
bool checkOpenCVConvention = true )

Decompose projection matrix into K, R and t.

Parameters
PMatrix to be decomposed so that P = K * [R | t]
KK matrix of P
RR matrix of P
tt vector from P
checkOpenCVConventionIf set to true the function will check if the determinant of R is positive. This should be the case e.g. when P is given in openCV coordinate convention.

◆ reproject() [1/2]

vec3 reproject ( const mat4 & projMat,
const vec2 & imgPoint2D,
double physicalWidth,
vec3 & sourceOut3D,
vec3 & imgOut3D,
vec3 & zDirOut,
double & fac )

Reprojects a point on the image plane using an OpenGL projection matrix.

Parameters
projMatprojection matrix in OpenGL notation
imgPoint2Dpoint on the image plane in normalized 0..1 coordinates, i.e 0 and 1 denoting the image borders.
physicalWidthphysical width of the image in mm
sourceOut3D3D position of the source/focal point
imgOut3D3D position of the point on the image plane
zDirOut3D ray direction of the principle point
facscaling factor such that factorOut * returnvalue points to the same plane as zDirOut
Returns
normalized direction vector from source/focal to image point

◆ reproject() [2/2]

vec3 reproject ( const mat4 & projMat,
const vec2 & imgPoint2D,
double physicalWidth,
vec3 & sourceOut3D,
vec3 & imgOut3D )

Reprojects a point on the image plane using an OpenGL projection matrix.

Parameters
projMatprojection matrix in OpenGL notation
imgPoint2Dpoint on the image plane in normalized 0..1 coordinates
physicalWidthphysical width of the image in mm
sourceOut3D3D position of the source/focal point
imgOut3D3D position of the point on the image plane
Returns
normalized direction vector from source/focal to image point

◆ unproject()

void unproject ( const mat3 & invK,
double dist,
const vec2 & pt2d,
vec3 & pt3d )

Unprojects a point on the image plane, where dist corresponds to the distance of pt3d from the xy plane and invK is the inverse calibration matrix of the camera.

Parameters
invKinverse camera calibration matrix
distdistance of the unprojected point 3D point to the xy-plane
pt2dpoint on the image plane in pixel coordinates
pt3dpoint in the world space that gets mapped into the image plane

◆ projectPoint() [1/2]

void projectPoint ( const mat34 & P,
vec4 & pt3d,
vec3 & pt2d,
const bool normalize = true )
inline

Projects a 3d point to 2d using a 3x4 projection matrix.

Parameters
P3x4 projection matrix
pt3dHomogenous 3d point
[out]pt2dProjected Homogenous 2d point
normalizeNormalize 2d point

◆ projectPoint() [2/2]

void projectPoint ( const mat34 & P,
vec3 & pt3d,
vec3 & pt2d,
const bool normalize = true )
inline

Projects an inhomogenous 3d point to 2d using a 3x4 projection matrix.

Parameters
P3x4 projection matrix
pt3dInhomogenous 3d point
[out]pt2dProjected Homogenous 2d point
normalizeNormalize 2d point

◆ projectPoints()

std::vector< vec2 > projectPoints ( const std::vector< vec3 > & pts3d,
const mat3 & K,
const mat3 & R,
const vec3 & t,
const vec5 & distCoeffs )

Projects a vector of inhomogenous 3d points to 2d using intrinsics and distortion parameters.

Parameters
pts3dA vector of inhomogenous 3d points.
Kintrinsic parameters
Rrotation matrix of P
ttranslation vector from P
distCoeffsdistortion parameters of the camera distortion model (k1 k2 p1 p2 k3)
Returns
A vector of projected inhomogenous 2d points.
Search Tab / S to search, Esc to close