Monado OpenXR Runtime
t_camera_models.h File Reference

Simple, untemplated, C, float-only, camera (un)projection functions for various camera models. More...

#include "math/m_vec2.h"
#include "math/m_matrix_2x2.h"
#include "math/m_mathinclude.h"
#include "t_tracking.h"
#include <assert.h>
Include dependency graph for t_camera_models.h:

Go to the source code of this file.

Data Structures

struct  t_camera_calibration_kb4_params_float
 Floating point parameters for T_DISTORTION_FISHEYE_KB4. More...
 
struct  t_camera_calibration_rt8_params_float
 Floating point parameters for T_DISTORTION_OPENCV_RT8, also including metric_radius. More...
 
struct  t_camera_model_params
 Floating point calibration data for a single calibrated camera. More...
 

Functions

static float kb4_calc_r_theta (const struct t_camera_model_params *dist, const float theta, const float theta2)
 
static bool kb4_project (const struct t_camera_model_params *dist, const float x, const float y, const float z, float *out_x, float *out_y)
 
static float kb4_solve_theta (const struct t_camera_model_params *dist, const float *r_theta, float *d_func_d_theta)
 
static bool kb4_unproject (const struct t_camera_model_params *dist, const float x, const float y, float *out_x, float *out_y, float *out_z)
 
static void kb4_undistort (const struct t_camera_model_params *dist, const float x, const float y, float *out_x, float *out_y)
 
static bool rt8_project (const struct t_camera_model_params *dist, const float x, const float y, const float z, float *out_x, float *out_y)
 
static void rt8_distort (const struct t_camera_model_params *params, const struct xrt_vec2 *undist, struct xrt_vec2 *dist, struct xrt_matrix_2x2 *d_dist_d_undist)
 
static void rt8_undistort (const struct t_camera_model_params *hg_dist, const float u, const float v, float *out_x, float *out_y)
 
static bool rt8_unproject (const struct t_camera_model_params *hg_dist, const float u, const float v, float *out_x, float *out_y, float *out_z)
 
static void interpret_as_rt8 (const struct t_camera_calibration *cc, struct t_camera_model_params *out_params)
 
static void t_camera_model_params_from_t_camera_calibration (const struct t_camera_calibration *cc, struct t_camera_model_params *out_params)
 Takes a t_camera_calibration through cc, and returns a t_camera_model_params that shadows cc 's parameters through out_params. More...
 
static bool t_camera_models_unproject (const struct t_camera_model_params *dist, const float x, const float y, float *out_x, float *out_y, float *out_z)
 Takes a 2D image-space point through x and y, unprojects it to a normalized 3D direction, and returns the result through out_x, out_y and out_z. More...
 
static bool t_camera_models_unproject_and_flip (const struct t_camera_model_params *dist, const float x, const float y, float *out_x, float *out_y, float *out_z)
 Takes a 2D image-space point through x and y, unprojects it to a normalized 3D direction, flips its Y and Z values (performing a coordinate space transform from +Z forward -Y up to -Z forward +Y up) and returns the result through out_x, out_y and out_z. More...
 
static void t_camera_models_undistort (const struct t_camera_model_params *dist, const float x, const float y, float *out_x, float *out_y)
 Takes a distorted 2D point through x and y and computes the undistorted point into out_x and out_y. More...
 
static bool t_camera_models_project (const struct t_camera_model_params *dist, const float x, const float y, const float z, float *out_x, float *out_y)
 Takes a 3D point through x, y, and z, projects it into image space, and returns the result through out_x and out_y. More...
 
static bool t_camera_models_flip_and_project (const struct t_camera_model_params *dist, const float x, const float y, const float z, float *out_x, float *out_y)
 Takes a 3D point through x, y, and z, flips its Y and Z values (performing a coordinate space transform from -Z forward +Y up to +Z forward -Y up), projects it into image space, and returns the result through out_x and out_y. More...
 

Variables

static const float SQRT_EPSILON = 0.00316
 

Detailed Description

Simple, untemplated, C, float-only, camera (un)projection functions for various camera models.

Author
Moses Turner moses.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m

Some notes: These functions should return exactly the same values as basalt-headers, down to floating point bits.

They were mainly written as an expedient way to stop depending on OpenCV-based (un)projection code in Monado's hand tracking code, and to encourage compiler optimizations through inlining.

Current users:

  • Mercury hand tracking

Function Documentation

◆ kb4_unproject()

static bool kb4_unproject ( const struct t_camera_model_params dist,
const float  x,
const float  y,
float *  out_x,
float *  out_y,
float *  out_z 
)
inlinestatic
Todo:
I'm not 100% sure if kb4 is always non-injective. basalt-headers always returns true here, so it might be wrong too.

◆ rt8_undistort()

static void rt8_undistort ( const struct t_camera_model_params hg_dist,
const float  u,
const float  v,
float *  out_x,
float *  out_y 
)
inlinestatic
Todo:
Decide if besides rpmax, it could be useful to have an rppmax field. A good starting point to having this would be using the sqrt of the max rpp2 value computed in the optimization of computeRpmax().

Referenced by t_camera_models_undistort().

◆ t_camera_model_params_from_t_camera_calibration()

static void t_camera_model_params_from_t_camera_calibration ( const struct t_camera_calibration cc,
struct t_camera_model_params out_params 
)
inlinestatic

◆ t_camera_models_flip_and_project()

static bool t_camera_models_flip_and_project ( const struct t_camera_model_params dist,
const float  x,
const float  y,
const float  z,
float *  out_x,
float *  out_y 
)
inlinestatic

Takes a 3D point through x, y, and z, flips its Y and Z values (performing a coordinate space transform from -Z forward +Y up to +Z forward -Y up), projects it into image space, and returns the result through out_x and out_y.

References t_camera_models_project().

◆ t_camera_models_project()

static bool t_camera_models_project ( const struct t_camera_model_params dist,
const float  x,
const float  y,
const float  z,
float *  out_x,
float *  out_y 
)
inlinestatic

Takes a 3D point through x, y, and z, projects it into image space, and returns the result through out_x and out_y.

References T_DISTORTION_OPENCV_RADTAN_8.

Referenced by t_camera_models_flip_and_project().

◆ t_camera_models_undistort()

static void t_camera_models_undistort ( const struct t_camera_model_params dist,
const float  x,
const float  y,
float *  out_x,
float *  out_y 
)
inlinestatic

Takes a distorted 2D point through x and y and computes the undistorted point into out_x and out_y.

References rt8_undistort(), T_DISTORTION_FISHEYE_KB4, and T_DISTORTION_OPENCV_RADTAN_8.

◆ t_camera_models_unproject()

static bool t_camera_models_unproject ( const struct t_camera_model_params dist,
const float  x,
const float  y,
float *  out_x,
float *  out_y,
float *  out_z 
)
inlinestatic

Takes a 2D image-space point through x and y, unprojects it to a normalized 3D direction, and returns the result through out_x, out_y and out_z.

References T_DISTORTION_OPENCV_RADTAN_8.

Referenced by t_camera_models_unproject_and_flip().

◆ t_camera_models_unproject_and_flip()

static bool t_camera_models_unproject_and_flip ( const struct t_camera_model_params dist,
const float  x,
const float  y,
float *  out_x,
float *  out_y,
float *  out_z 
)
inlinestatic

Takes a 2D image-space point through x and y, unprojects it to a normalized 3D direction, flips its Y and Z values (performing a coordinate space transform from +Z forward -Y up to -Z forward +Y up) and returns the result through out_x, out_y and out_z.

References t_camera_models_unproject().