From 02ecb3c22781916c12274cdef35844e01032e343 Mon Sep 17 00:00:00 2001 From: thatcomputerguy0101 Date: Sat, 19 Sep 2026 13:21:47 -0400 Subject: [PATCH] Convert levels to weights in compute_uncertainty --- src/mrcal_jni.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/mrcal_jni.cpp b/src/mrcal_jni.cpp index d41089d..0370b68 100644 --- a/src/mrcal_jni.cpp +++ b/src/mrcal_jni.cpp @@ -68,6 +68,23 @@ constexpr std::string jni_make_method_sig(std::string_view retval, return result; } +/** + * Converts decimation levels to point weights using `weight=0.5^level`. + * Negative weights correspond to ignored points. + * + * @param observations Input as [x, y, level], output as [x, y, weight] + */ +static void levels_to_weights(std::span observations) { + for (auto &o : observations) { + double &level = o.z; + if (level < 0) { + o.z = -1; + } else { + o.z = std::pow(0.5, level); + } + } +} + /** * Finds a class and keeps it as a global reference. * @@ -206,15 +223,7 @@ Java_org_photonvision_mrcal_MrCalJNI_mrcal_1calibrate_1camera total_frames_rt_toref.push_back(seed_pose); } - // Convert detection level to weights - for (auto &o : observations) { - double &level = o.z; - if (level < 0) { - o.z = -1; - } else { - o.z = std::pow(0.5, level); - } - } + levels_to_weights(observations); auto statsptr = mrcal_main(observations, total_frames_rt_toref, boardSize, static_cast(boardSpacing), imagerSize, @@ -355,6 +364,8 @@ Java_org_photonvision_mrcal_MrCalJNI_compute_1uncertainty cv::Size calobjectSize(boardWidth, boardHeight); cv::Size sampleRes(sampleGridWidth, sampleGridHeight); + levels_to_weights(observations.asSpan()); + std::vector result; try { result = compute_uncertainty(