Monado OpenXR Runtime
Loading...
Searching...
No Matches
camera_model.h
Go to the documentation of this file.
1// Copyright 2014-2015 Philipp Zabel
2// Copyright 2019-2023 Jan Schmidt
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Constellation tracker's camera model storage.
7 * @author Philipp Zabel <philipp.zabel@gmail.com>
8 * @author Jan Schmidt <jan@centricular.com>
9 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
10 * @ingroup tracking
11 */
12
13#pragma once
14
16
17#include <math.h>
18
19
21{
22 //! Distorted frame width
24 //! Distorted frame height
26 //! The extents of the true frame's undistorted field of view, in pinhole pixel coordinates.
28 //! See @ref left_pinhole
30 //! Valid pinhole y coordinates are [top_pinhole, bottom_pinhole].
32 //! See @ref top_pinhole
34
35 //! The true calibration of the camera
37 //! An identity calibration model
39};
40
41/*!
42 * Creates a camera model, computing a pinhole model (with the same focal lengths as the true calibration) whose
43 * image covers the whole undistorted field of view of the true image.
44 */
45static inline struct camera_model
47{
48 // Sample the whole border of the true image (corners included, so nothing a blob can land on gets cropped), and
49 // find the extents of the undistorted (normalized) points
50 const float w = (float)width_true;
51 const float h = (float)height_true;
52 const int steps = 64;
53 float min_x = INFINITY, min_y = INFINITY, max_x = -INFINITY, max_y = -INFINITY;
54 for (int i = 0; i <= steps; i++) {
55 const float tx = w * (float)i / (float)steps;
56 const float ty = h * (float)i / (float)steps;
57 const float border[4][2] = {{tx, 0.0f}, {tx, h}, {0.0f, ty}, {w, ty}};
58
59 for (int j = 0; j < 4; j++) {
60 float x, y;
61 t_camera_models_undistort(calib, border[j][0], border[j][1], &x, &y);
62 if (!isfinite(x) || !isfinite(y)) {
63 continue;
64 }
65 min_x = fminf(min_x, x);
66 max_x = fmaxf(max_x, x);
67 min_y = fminf(min_y, y);
68 max_y = fmaxf(max_y, y);
69 }
70 }
71
72 // Fall back to the true frame if nothing undistorted cleanly
73 float left_pinhole = 0.0f;
74 float right_pinhole = w;
75 float top_pinhole = 0.0f;
76 float bottom_pinhole = h;
77 struct t_camera_model_params calib_pinhole = *calib;
78 calib_pinhole.model = T_DISTORTION_PINHOLE;
79
80 // if we found valid stuff, map that in, will be bigger than the normal model cus distortion.
81 if (min_x <= max_x && min_y <= max_y) {
82 left_pinhole = min_x * calib->fx + calib->cx;
83 right_pinhole = max_x * calib->fx + calib->cx;
84 top_pinhole = min_y * calib->fy + calib->cy;
85 bottom_pinhole = max_y * calib->fy + calib->cy;
86 }
87
88 struct camera_model model = {
90 .height_true = height_true,
91 .left_pinhole = left_pinhole,
92 .right_pinhole = right_pinhole,
93 .top_pinhole = top_pinhole,
94 .bottom_pinhole = bottom_pinhole,
95 .calib_true = *calib,
96 .calib_pinhole = calib_pinhole,
97 };
98 return model;
99}
static struct camera_model camera_model_init(int width_true, int height_true, const struct t_camera_model_params *calib)
Creates a camera model, computing a pinhole model (with the same focal lengths as the true calibratio...
Definition camera_model.h:46
@ T_DISTORTION_PINHOLE
A perfect pinhole camera with no distortion.
Definition t_tracking.h:67
Definition camera_model.h:21
float left_pinhole
The extents of the true frame's undistorted field of view, in pinhole pixel coordinates.
Definition camera_model.h:27
struct t_camera_model_params calib_pinhole
An identity calibration model.
Definition camera_model.h:38
int height_true
Distorted frame height.
Definition camera_model.h:25
struct t_camera_model_params calib_true
The true calibration of the camera.
Definition camera_model.h:36
int width_true
Distorted frame width.
Definition camera_model.h:23
float bottom_pinhole
See top_pinhole.
Definition camera_model.h:33
float top_pinhole
Valid pinhole y coordinates are [top_pinhole, bottom_pinhole].
Definition camera_model.h:31
float right_pinhole
See left_pinhole.
Definition camera_model.h:29
Floating point calibration data for a single calibrated camera.
Definition t_camera_models.h:62
Camera (un)projection C API for various camera models.