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(