From 6933270476fd4ec285dc90783431685dc537da3b Mon Sep 17 00:00:00 2001 From: BytingBulldogs3539 Date: Sat, 4 May 2024 21:28:11 -0400 Subject: [PATCH] Update MrCalJNI.java --- .../java/org/photonvision/mrcal/MrCalJNI.java | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/photonvision/mrcal/MrCalJNI.java b/src/main/java/org/photonvision/mrcal/MrCalJNI.java index 2b51dbf..98c8feb 100644 --- a/src/main/java/org/photonvision/mrcal/MrCalJNI.java +++ b/src/main/java/org/photonvision/mrcal/MrCalJNI.java @@ -65,49 +65,45 @@ public static native MrCalResult mrcal_calibrate_camera( public static native boolean undistort_mrcal(long srcMat, long dstMat, long cameraMat, long distCoeffsMat, int lensModelOrdinal, int order, int Nx, int Ny, int fov_x_deg); - public static MrCalResult calibrateCamera( - List board_corners, - List board_corner_levels, - int boardWidth, int boardHeight, double boardSpacing, - int imageWidth, int imageHeight, double focalLen) { - double[] observations = new double[boardWidth * boardHeight * 3 * board_corners.size()]; - - if (board_corners.size() != board_corner_levels.size() && board_corners.size() == boardWidth*boardHeight) { - return new MrCalResult(false); - } + public static MrCalResult calibrateCamera( + List board_corners, + List board_corner_levels, + int boardWidth, int boardHeight, double boardSpacing, + int imageWidth, int imageHeight, double focalLen) { + double[] observations = new double[boardWidth * boardHeight * 3 * board_corners.size()]; - int i = 0; - for (int b = 0; b < board_corners.size(); b++) { - var board = board_corners.get(b); - var levels = board_corner_levels.get(b).toArray(); - var corners = board.toArray(); - - if (corners.length != levels.length && corners.length == boardWidth*boardHeight) { - return new MrCalResult(false); - } + if (!(board_corners.size() == board_corner_levels.size() && board_corners.size() == boardWidth * boardHeight)) { + return new MrCalResult(false); + } - // Assume that we're correct in terms of row/column major-ness (lol) - for (int c = 0; c < corners.length; c++) { + int i = 0; + for (int b = 0; b < board_corners.size(); b++) { + var board = board_corners.get(b); + var levels = board_corner_levels.get(b).toArray(); + var corners = board.toArray(); - var corner = corners[c]; - float level = levels[c]; + if (!(corners.length == levels.length && corners.length == boardWidth * boardHeight)) { + return new MrCalResult(false); + } - observations[i * 3 + 0] = corner.x; - observations[i * 3 + 1] = corner.y; - observations[i * 3 + 2] = level; + // Assume that we're correct in terms of row/column major-ness (lol) + for (int c = 0; c < corners.length; c++) { - i += 1; - } - } + var corner = corners[c]; + float level = levels[c]; - if (i * 3 != observations.length) + observations[i * 3 + 0] = corner.x; + observations[i * 3 + 1] = corner.y; + observations[i * 3 + 2] = level; - { - return new MrCalResult(false); + i += 1; } + } - return - - mrcal_calibrate_camera(observations, boardWidth, boardHeight, boardSpacing, imageWidth, imageHeight, focalLen); + if (i * 3 != observations.length){ + return new MrCalResult(false); } + + return mrcal_calibrate_camera(observations, boardWidth, boardHeight, boardSpacing, imageWidth, imageHeight, focalLen); + } }