use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkCenter.
@Test
void checkCenter() {
// It's not specified if the center should be undistorted or distorted. Just make it easier by
// using undistorted
CameraPinholeBrown intrinsic = loadDistortion(false);
LensDistortionBrown lensDistorted = new LensDistortionBrown(intrinsic);
for (ImageType type : types) {
ImageBase image = renderImage(intrinsic, type);
FiducialDetector detector = createDetector(type);
detector.setLensDistortion(lensDistorted, image.width, image.height);
// ShowImages.showBlocking(image, "asdfasdf", 5_000);
detect(detector, image);
assertTrue(detector.totalFound() >= 1);
assertTrue(detector.is3D());
for (int i = 0; i < detector.totalFound(); i++) {
Se3_F64 fidToCam = new Se3_F64();
Point2D_F64 found = new Point2D_F64();
detector.getFiducialToCamera(i, fidToCam);
detector.getCenter(i, found);
Point2D_F64 rendered = new Point2D_F64();
WorldToCameraToPixel worldToPixel = PerspectiveOps.createWorldToPixel(lensDistorted, fidToCam);
worldToPixel.transform(new Point3D_F64(0, 0, 0), rendered);
// see if the reprojected is near the pixel location
assertEquals(0.0, rendered.distance(found), pixelAndProjectedTol);
}
}
}
use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkSubImage.
@Test
void checkSubImage() {
CameraPinholeBrown intrinsic = loadDistortion(true);
LensDistortionBrown lensDistorted = new LensDistortionBrown(intrinsic);
for (ImageType type : types) {
ImageBase image = renderImage(intrinsic, type);
FiducialDetector detector = createDetector(type);
detector.setLensDistortion(lensDistorted, image.width, image.height);
detect(detector, image);
assertTrue(detector.totalFound() >= 1);
long[] foundID = new long[detector.totalFound()];
List<Se3_F64> foundPose = new ArrayList<>();
for (int i = 0; i < detector.totalFound(); i++) {
foundID[i] = detector.getId(i);
Se3_F64 pose = new Se3_F64();
detector.getFiducialToCamera(i, pose);
foundPose.add(pose);
}
// run it again with a sub-image
detect(detector, BoofTesting.createSubImageOf(image));
// see if it produced exactly the same results
assertEquals(foundID.length, detector.totalFound());
for (int i = 0; i < detector.totalFound(); i++) {
assertEquals(foundID[i], detector.getId(i));
Se3_F64 pose = new Se3_F64();
detector.getFiducialToCamera(i, pose);
assertEquals(0, pose.getT().distance(foundPose.get(i).T), 1e-8);
assertTrue(MatrixFeatures_DDRM.isIdentical(pose.getR(), foundPose.get(i).R, 1e-8));
}
}
}
use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkMultipleRuns.
@Test
void checkMultipleRuns() {
CameraPinholeBrown intrinsic = loadDistortion(true);
LensDistortionBrown lensDistorted = new LensDistortionBrown(intrinsic);
for (ImageType type : types) {
ImageBase image = renderImage(intrinsic, type);
FiducialDetector detector = createDetector(type);
detector.setLensDistortion(lensDistorted, image.width, image.height);
detect(detector, image);
assertTrue(detector.totalFound() >= 1);
Results results = extractResults(detector);
// run it again
detect(detector, image);
// see if it produced exactly the same results
assertEquals(results.id.length, detector.totalFound());
for (int i = 0; i < detector.totalFound(); i++) {
assertEquals(results.id[i], detector.getId(i));
Point2D_F64 centerPixel = new Point2D_F64();
detector.getCenter(i, centerPixel);
assertEquals(0.0, results.centerPixel.get(i).distance(centerPixel), 1e-8);
Se3_F64 pose = new Se3_F64();
detector.getFiducialToCamera(i, pose);
assertEquals(0, pose.getT().distance(results.pose.get(i).T), 1e-8);
assertTrue(MatrixFeatures_DDRM.isIdentical(pose.getR(), results.pose.get(i).R, 1e-8));
}
}
}
use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkHandleNewIntrinsic.
/**
* Tests several items:
*
* 1) Does it properly handle setIntrinsic() being called multiple times
* 2) Can it handle no distortion
*/
@Test
void checkHandleNewIntrinsic() {
for (ImageType type : types) {
// distorted camera model
CameraPinholeBrown instrinsic = loadDistortion(true);
LensDistortionBrown distortion = new LensDistortionBrown(instrinsic);
// render a distorted image
ImageBase image = renderImage(instrinsic, type);
// give it an undistored model
FiducialDetector detector = createDetector(type);
assertFalse(detector.is3D());
detector.setLensDistortion(new LensDistortionBrown(loadDistortion(false)), image.width, image.height);
assertTrue(detector.is3D());
detect(detector, image);
// it might not be able to detect the target
if (detector.totalFound() >= 1) {
checkBounds(detector);
}
// Give it the correct model and this time it should work
detector.setLensDistortion(distortion, image.width, image.height);
assertTrue(detector.is3D());
detect(detector, image);
checkBounds(detector);
assertTrue(detector.totalFound() >= 1);
// Now remove the distortion model
detector.setLensDistortion(null, image.width, image.height);
assertFalse(detector.is3D());
detect(detector, image);
if (detector.totalFound() >= 1) {
checkBounds(detector);
}
}
}
use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkStability.
/**
* See if the stability estimation is reasonable. First detect targets in the full sized image. Then shrink it
* by 15% and see if the instability increases. The instability should always increase for smaller objects with
* the same orientation since the geometry is worse.
*/
@Test
void checkStability() {
// has to be undistorted otherwise rescaling the image won't work
CameraPinholeBrown intrinsic = loadDistortion(false);
LensDistortionBrown lensDistorted = new LensDistortionBrown(intrinsic);
for (ImageType type : types) {
ImageBase image = renderImage(intrinsic, type);
FiducialDetector detector = createDetector(type);
detector.setLensDistortion(lensDistorted, image.width, image.height);
// ShowImages.showBlocking(image, "First Detect", 3_000);
detect(detector, image);
assertTrue(detector.totalFound() >= 1);
long[] foundIds = new long[detector.totalFound()];
double[] location = new double[detector.totalFound()];
double[] orientation = new double[detector.totalFound()];
FiducialStability results = new FiducialStability();
for (int i = 0; i < detector.totalFound(); i++) {
detector.computeStability(i, 0.2, results);
foundIds[i] = detector.getId(i);
location[i] = results.location;
orientation[i] = results.orientation;
}
// by shrinking the image a small pixel error should result
// in a larger pose error, hence more unstable
ImageBase shrunk = image.createSameShape();
new FDistort(image, shrunk).affine(stabilityShrink, 0, 0, stabilityShrink, image.width / 4, image.height / 4).apply();
// ShowImages.showBlocking(shrunk, "Shrunk", 2_000);
detect(detector, shrunk);
assertEquals(detector.totalFound(), foundIds.length);
for (int i = 0; i < detector.totalFound(); i++) {
detector.computeStability(i, 0.2, results);
long id = detector.getId(i);
boolean matched = false;
for (int j = 0; j < foundIds.length; j++) {
if (foundIds[j] == id) {
matched = true;
assertTrue(location[j] < results.location);
assertTrue(orientation[j] < results.orientation);
break;
}
}
assertTrue(matched);
}
}
}
Aggregations