use of boofcv.struct.image.ImageType in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkImageLocation.
@Test
public void checkImageLocation() {
for (ImageType type : types) {
ImageBase image = loadImage(type);
FiducialDetector detector = createDetector(type);
// It's not specified if the center should be undistorted or distorted. Just make it easier by
// using undistorted
LensDistortionNarrowFOV distortion = loadDistortion(false);
detector.setLensDistortion(distortion, image.width, image.height);
detector.detect(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(distortion, fidToCam);
worldToPixel.transform(new Point3D_F64(0, 0, 0), rendered);
// see if the reprojected is near the pixel location
assertTrue(rendered.distance(found) <= pixelAndProjectedTol);
}
}
}
use of boofcv.struct.image.ImageType in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkMultipleRuns.
@Test
public void checkMultipleRuns() {
for (ImageType type : types) {
ImageBase image = loadImage(type);
FiducialDetector detector = createDetector(type);
detector.setLensDistortion(loadDistortion(true), image.width, image.height);
detector.detect(image);
assertTrue(detector.totalFound() >= 1);
Results results = extractResults(detector);
// run it again
detector.detect(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));
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.image.ImageType 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
public void checkStability() {
for (ImageType type : types) {
ImageBase image = loadImage(type);
FiducialDetector detector = createDetector(type);
detector.setLensDistortion(loadDistortion(true), image.width, image.height);
detector.detect(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;
}
ImageBase shrunk = image.createSameShape();
new FDistort(image, shrunk).affine(0.8, 0, 0, 0.8, 0, 0).apply();
detector.detect(shrunk);
assertTrue(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);
}
}
}
use of boofcv.struct.image.ImageType 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
public void checkHandleNewIntrinsic() {
for (ImageType type : types) {
ImageBase image = loadImage(type);
FiducialDetector detector = createDetector(type);
detector.setLensDistortion(loadDistortion(true), image.width, image.height);
detector.detect(image);
assertTrue(detector.totalFound() >= 1);
checkBounds(detector);
Results results = extractResults(detector);
// run it again with a changed intrinsic that's incorrect
detector.setLensDistortion(loadDistortion(false), image.width, image.height);
detector.detect(image);
checkBounds(detector);
// results should have changed
if (results.id.length == detector.totalFound()) {
assertEquals(results.id.length, detector.totalFound());
for (int i = 0; i < detector.totalFound(); i++) {
assertEquals(results.id[i], detector.getId(i));
Se3_F64 pose = new Se3_F64();
Point2D_F64 pixel = new Point2D_F64();
detector.getFiducialToCamera(i, pose);
detector.getCenter(i, pixel);
assertTrue(pose.getT().distance(results.pose.get(i).T) > 1e-4);
assertFalse(MatrixFeatures_DDRM.isIdentical(pose.getR(), results.pose.get(i).R, 1e-4));
// pixel location is based on the observed location, thus changing the intrinsics should not
// affect it
assertTrue(results.pixel.get(i).distance(pixel) <= 2.0);
}
} else {
// clearly changed
}
// then reproduce original
detector.setLensDistortion(loadDistortion(true), image.width, image.height);
detector.detect(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));
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.image.ImageType in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkSubImage.
@Test
public void checkSubImage() {
for (ImageType type : types) {
ImageBase image = loadImage(type);
FiducialDetector detector = createDetector(type);
detector.setLensDistortion(loadDistortion(true), image.width, image.height);
detector.detect(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
detector.detect(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));
}
}
}
Aggregations