13 const std::optional<CalibrationBounds>& bounds)
14 -> std::pair<CameraMatrix, bool> {
15 if (!bounds.has_value()) {
19 const auto& b = bounds.value();
21 bool modified =
false;
23 const auto enforce_min_focal = [&modified](
double value,
double min_val) {
24 if (!std::isfinite(value) || value < min_val) {
31 const auto midpoint = [](
double min_val,
double max_val) {
return 0.5 * (min_val + max_val); };
33 const auto adjust_principal_point = [&modified, &midpoint](
double value,
double min_val,
35 if (!std::isfinite(value)) {
37 return midpoint(min_val, max_val);
39 if (value < min_val || value > max_val) {
41 return midpoint(min_val, max_val);
46 adjusted.
fx = enforce_min_focal(adjusted.
fx, b.fx_min);
47 adjusted.
fy = enforce_min_focal(adjusted.
fy, b.fy_min);
48 adjusted.
cx = adjust_principal_point(adjusted.
cx, b.cx_min, b.cx_max);
49 adjusted.
cy = adjust_principal_point(adjusted.
cy, b.cy_min, b.cy_max);
51 const double skew_min = std::min(b.skew_min, b.skew_max);
52 const double skew_max = std::max(b.skew_min, b.skew_max);
53 if (!std::isfinite(adjusted.
skew) || adjusted.
skew < skew_min || adjusted.
skew > skew_max) {
55 adjusted.
skew = std::clamp(0.0, skew_min, skew_max);
57 return {adjusted, modified};