Skip to content

Commit

Permalink
Update MrCalJNI.java
Browse files Browse the repository at this point in the history
  • Loading branch information
BytingBulldogs3539 committed May 5, 2024
1 parent 679a3e9 commit 6933270
Showing 1 changed file with 31 additions and 35 deletions.
66 changes: 31 additions & 35 deletions src/main/java/org/photonvision/mrcal/MrCalJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MatOfPoint2f> board_corners,
List<MatOfFloat> 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<MatOfPoint2f> board_corners,
List<MatOfFloat> 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);
}
}

0 comments on commit 6933270

Please sign in to comment.