Monado OpenXR Runtime
t_file.cpp File Reference

Handling of files and calibration data. More...

#include "tracking/t_calibration_opencv.hpp"
#include "util/u_misc.h"
#include "util/u_logging.h"
#include "util/u_json.hpp"
#include "os/os_time.h"
Include dependency graph for t_file.cpp:

Macros

#define CALIB_TRACE(...)   U_LOG_IFL_T(debug_get_log_option_calib_log(), __VA_ARGS__)
 
#define CALIB_DEBUG(...)   U_LOG_IFL_D(debug_get_log_option_calib_log(), __VA_ARGS__)
 
#define CALIB_INFO(...)   U_LOG_IFL_I(debug_get_log_option_calib_log(), __VA_ARGS__)
 
#define CALIB_WARN(...)   U_LOG_IFL_W(debug_get_log_option_calib_log(), __VA_ARGS__)
 
#define CALIB_ERROR(...)   U_LOG_IFL_E(debug_get_log_option_calib_log(), __VA_ARGS__)
 
#define CALIB_ASSERT(predicate, ...)
 
#define CALIB_ASSERT_(predicate)   CALIB_ASSERT(predicate, "Assertion failed " #predicate)
 
#define CALIB_ASSERTR(predicate, ...)
 
#define COPY(TO, FROM)
 
#define PINHOLE_RADTAN5   "pinhole_radtan5"
 
#define FISHEYE_EQUIDISTANT4   "fisheye_equidistant4"
 

Functions

static bool read_cv_mat (FILE *f, cv::Mat *m, const char *name)
 
static bool write_cv_mat (FILE *f, cv::Mat *m)
 
RemapPair xrt::auxiliary::tracking::calibration_get_undistort_map (t_camera_calibration &calib, cv::InputArray rectify_transform_optional=cv::noArray(), cv::Mat new_camera_matrix_optional=cv::Mat())
 Prepare undistortion/normalization remap structures for a rectilinear or fisheye image. More...
 
bool t_stereo_camera_calibration_load_v1 (FILE *calib_file, struct t_stereo_camera_calibration **out_data)
 
static bool t_stereo_camera_calibration_load_path_v1 (const char *calib_path, struct t_stereo_camera_calibration **out_data)
 
static bool load_mat_field (const JSONNode &jn, int rows, int cols, cv::Mat_< double > &out_mat)
 Fills out_mat from a json array stored in jn. More...
 
template<int rows, int cols>
static XRT_MAYBE_UNUSED bool load_mat_field (const JSONNode &jn, double(&out_arr)[rows][cols])
 Overload of load_mat_field that saves the result into a 2D C-array. More...
 
template<int dim>
static XRT_MAYBE_UNUSED bool load_mat_field (const JSONNode &jn, double(&out_arr)[dim])
 Overload of load_mat_field that saves the result into a 1D C-array. More...
 
static bool t_camera_calibration_load_v2 (cJSON *cjson_cam, t_camera_calibration *cc)
 
bool t_stereo_camera_calibration_from_json_v2 (cJSON *cjson, struct t_stereo_camera_calibration **out_stereo)
 
static bool t_stereo_camera_calibration_load_path_v2 (const char *calib_path, struct t_stereo_camera_calibration **out_stereo)
 
bool t_stereo_camera_calibration_save_v1 (FILE *calib_file, struct t_stereo_camera_calibration *data)
 
static bool t_stereo_camera_calibration_save_path_v1 (const char *calib_path, struct t_stereo_camera_calibration *data)
 
static JSONBuilderoperator<< (JSONBuilder &jb, const cv::Mat_< double > &mat)
 Writes mat data into a jb as a json array. More...
 
bool t_stereo_camera_calibration_to_json_v2 (cJSON **out_cjson, struct t_stereo_camera_calibration *data)
 
static bool t_stereo_camera_calibration_save_path_v2 (const char *calib_path, struct t_stereo_camera_calibration *data)
 
static bool has_json_extension (const char *filename)
 
bool t_stereo_camera_calibration_load (const char *calib_path, struct t_stereo_camera_calibration **out_data)
 
bool t_stereo_camera_calibration_save (const char *calib_path, struct t_stereo_camera_calibration *data)
 

Detailed Description

Macro Definition Documentation

◆ CALIB_ASSERT

#define CALIB_ASSERT (   predicate,
  ... 
)
Value:
do { \
bool p = predicate; \
if (!p) { \
U_LOG(U_LOGGING_ERROR, __VA_ARGS__); \
assert(false && "CALIB_ASSERT failed: " #predicate); \
exit(EXIT_FAILURE); \
} \
} while (false);
@ U_LOGGING_ERROR
Error messages: indicating a problem.
Definition: u_logging.h:45

◆ CALIB_ASSERTR

#define CALIB_ASSERTR (   predicate,
  ... 
)
Value:
if (!(predicate)) { \
U_LOG(U_LOGGING_ERROR, __VA_ARGS__); \
return false; \
}

◆ COPY

#define COPY (   TO,
  FROM 
)
Value:
do { \
CALIB_ASSERT(FROM.size() == TO.size(), "Sizes doesn't match for " #FROM); \
FROM.copyTo(TO); \
} while (false)

◆ PINHOLE_RADTAN5

#define PINHOLE_RADTAN5   "pinhole_radtan5"
Todo:
merge these with t_tracking.h

Function Documentation

◆ calibration_get_undistort_map()

RemapPair xrt::auxiliary::tracking::calibration_get_undistort_map ( t_camera_calibration calib,
cv::InputArray  rectify_transform_optional = cv::noArray(),
cv::Mat  new_camera_matrix_optional = cv::Mat() 
)

Prepare undistortion/normalization remap structures for a rectilinear or fisheye image.

Parameters
calibA single camera calibration structure.
rectify_transform_optionalA rectification transform to apply, if desired.
new_camera_matrix_optionalUnlike OpenCV, the default/empty matrix here uses the input camera matrix as your output camera matrix.
Todo:
Scale Our intrinsics if the frame size we request
Todo:
Scale Our intrinsics if the frame size we request

References xrt::auxiliary::tracking::calibration_get_undistort_map(), t_camera_calibration::distortion_model, t_camera_calibration::image_size_pixels, T_DISTORTION_FISHEYE_KB4, and T_DISTORTION_OPENCV_RADTAN_5.

Referenced by xrt::auxiliary::tracking::calibration_get_undistort_map().

◆ load_mat_field() [1/3]

template<int dim>
static XRT_MAYBE_UNUSED bool load_mat_field ( const JSONNode jn,
double(&)  out_arr[dim] 
)
static

Overload of load_mat_field that saves the result into a 1D C-array.

References load_mat_field().

◆ load_mat_field() [2/3]

template<int rows, int cols>
static XRT_MAYBE_UNUSED bool load_mat_field ( const JSONNode jn,
double(&)  out_arr[rows][cols] 
)
static

Overload of load_mat_field that saves the result into a 2D C-array.

References load_mat_field().

◆ load_mat_field() [3/3]

static bool load_mat_field ( const JSONNode jn,
int  rows,
int  cols,
cv::Mat_< double > &  out_mat 
)
static

Fills out_mat from a json array stored in jn.

Returns true if jn is a valid rows * cols matrix, false otherwise.

Referenced by load_mat_field().

◆ operator<<()

static JSONBuilder & operator<< ( JSONBuilder jb,
const cv::Mat_< double > &  mat 
)
static

Writes mat data into a jb as a json array.

◆ read_cv_mat()

static bool read_cv_mat ( FILE *  f,
cv::Mat *  m,
const char *  name 
)
static
Todo:
We may have written things other than CV_32F and CV_64F.

◆ t_stereo_camera_calibration_from_json_v2()

bool t_stereo_camera_calibration_from_json_v2 ( cJSON *  cjson,
struct t_stereo_camera_calibration **  out_stereo 
)
related
Todo:
At some point it'll make sense to support different distortion models per-camera, but right now we don't have any cameras like that and the way t_stereo_camera_calib_alloc and (Stereo)CameraCalibrationWrapper work makes it pretty annoying.