Cal checkerboard object coords update (#181)

* WIP monkeying around with adding new targets.

* Added testcase to replicate large extrinsics result from calibration.

* Tweaked calibration pipline to return image with chessboard corner detection overlaid.

* Removed "bad" images from the cal, but that didn't seem to help...

* Added test logic to output the undistorted Mat for evaluating the quality of the calibration.

* Tweaked generation of chessboard points to be in a square pattern, not parallelogram.

* Spotless and removed bespoke test target in prep for PR.

* Revised to a double-for loop for less complex-looking logic

* #thanks spotless

al;ksgfjh akljghf ;lakdfdhg ksadfgh klasdfjhg kasdfjghj aklsjg two spaces

* Boop

* Reverting my changes in Calibrate3dPipeline.java to make this merge better with other PR's

* Derp changed the wrong one
This commit is contained in:
Chris Gerth
2020-12-20 19:39:21 -06:00
committed by GitHub
parent c7d092a775
commit 771f7442c9
31 changed files with 74 additions and 10 deletions

View File

@@ -32,6 +32,7 @@ import org.junit.jupiter.api.Test;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.frame.Frame;
import org.photonvision.vision.frame.FrameStaticProperties;
@@ -97,7 +98,7 @@ public class Calibrate3dPipeTest {
new Frame(
new CVMat(Imgcodecs.imread(file.getAbsolutePath())),
new FrameStaticProperties(640, 480, 60, new Rotation2d(), null)));
// TestUtils.showImage(output.outputFrame.image.getMat());
// TestUtils.showImage(output.outputFrame.image.getMat());
}
assertTrue(
@@ -128,4 +129,56 @@ public class Calibrate3dPipeTest {
System.out.println(
"Mean: " + Arrays.stream(calibration3dPipeline.perViewErrors()).average().toString());
}
@Test
public void calibrateSquaresTest() {
File dir = new File(TestUtils.getSquaresBoardImagesPath().toAbsolutePath().toString());
File[] directoryListing = dir.listFiles();
Calibrate3dPipeline calibration3dPipeline = new Calibrate3dPipeline(20);
calibration3dPipeline.getSettings().boardType = UICalibrationData.BoardType.CHESSBOARD;
calibration3dPipeline.getSettings().resolution = new Size(320, 240);
for (var file : directoryListing) {
if (file.isFile()) {
calibration3dPipeline.takeSnapshot();
var output =
calibration3dPipeline.run(
new Frame(
new CVMat(Imgcodecs.imread(file.getAbsolutePath())),
new FrameStaticProperties(320, 240, 67, new Rotation2d(), null)));
// TestUtils.showImage(output.outputFrame.image.getMat(), file.getName());
}
}
assertTrue(
calibration3dPipeline.foundCornersList.stream()
.map(Triple::getRight)
.allMatch(it -> it.width() > 0 && it.height() > 0));
var cal = calibration3dPipeline.tryCalibration();
calibration3dPipeline.finishCalibration();
for (var file : directoryListing) {
if (file.isFile()) {
Mat raw = Imgcodecs.imread(file.getAbsolutePath());
Mat undistorted = new Mat(new Size(600, 600), raw.type());
Imgproc.undistort(
raw, undistorted, cal.cameraIntrinsics.getAsMat(), cal.cameraExtrinsics.getAsMat());
TestUtils.showImage(undistorted, "undistorted " + file.getName(), 1);
}
}
assertNotNull(cal);
assertNotNull(cal.perViewErrors);
System.out.println("Per View Errors: " + Arrays.toString(cal.perViewErrors));
System.out.println("Camera Intrinsics : " + cal.cameraIntrinsics.toString());
System.out.println("Camera Extrinsics : " + cal.cameraExtrinsics.toString());
System.out.println("Standard Deviation: " + cal.standardDeviation);
System.out.println(
"Mean: " + Arrays.stream(calibration3dPipeline.perViewErrors()).average().toString());
}
}