use of boofcv.alg.geo.WorldToCameraToPixel in project BoofCV by lessthanoptimal.
the class TestSimulatePlanarWorld method checkOrientation.
private void checkOrientation(int expectedAA, int expectedAB, int expectedBB, int expectedBA, double rotZ) {
double markerZ = 2;
double markerWidth = 0.5;
CameraPinhole pinhole = new CameraPinhole(400, 400, 0, 300, 250, 600, 500);
GrayF32 marker = new GrayF32(40, 30);
GImageMiscOps.fill(marker, 255);
// fill the top left corner so that we can tell the orientation
GImageMiscOps.fillRectangle(marker, 100, 0, 0, 20, 15);
Se3_F64 markerToWorld = eulerXyz(0, 0, markerZ, 0, Math.PI, rotZ, null);
SimulatePlanarWorld alg = new SimulatePlanarWorld();
alg.setCamera(pinhole);
alg.addSurface(markerToWorld, markerWidth, marker);
alg.render();
GrayF32 image = alg.getOutput();
// ShowImages.showWindow(image,"Adsasd");
// try {
// Thread.sleep(10000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// figure out where the marker was rendered
Point2D_F64 p0 = new Point2D_F64();
Point2D_F64 p1 = new Point2D_F64();
double ratio = marker.height / (double) marker.width;
WorldToCameraToPixel w2p = new WorldToCameraToPixel();
w2p.configure(pinhole, markerToWorld);
assertTrue(w2p.transform(new Point3D_F64(-markerWidth / 2, -ratio * markerWidth / 2, 0), p0));
assertTrue(w2p.transform(new Point3D_F64(markerWidth / 2, ratio * markerWidth / 2, 0), p1));
int x0 = (int) Math.min(p0.x, p1.x);
int y0 = (int) Math.min(p0.y, p1.y);
int x1 = (int) Math.max(p0.x, p1.x);
int y1 = (int) Math.max(p0.y, p1.y);
int xm = (x0 + x1) / 2;
int ym = (y0 + y1) / 2;
double regionAA = image.get((x0 + xm) / 2, (y0 + ym) / 2);
double regionAB = image.get((x0 + xm) / 2, (ym + y1) / 2);
double regionBB = image.get((xm + x1) / 2, (ym + y1) / 2);
double regionBA = image.get((xm + x1) / 2, (y0 + ym) / 2);
assertEquals(expectedAA, regionAA, 5);
assertEquals(expectedAB, regionAB, 5);
assertEquals(expectedBB, regionBB, 5);
assertEquals(expectedBA, regionBA, 5);
}
use of boofcv.alg.geo.WorldToCameraToPixel in project BoofCV by lessthanoptimal.
the class TestQuadPoseEstimator method computeErrors.
@Test
void computeErrors() {
LensDistortionNarrowFOV distortion = createDistortion();
Se3_F64 fiducialToCamera = new Se3_F64();
fiducialToCamera.getT().setTo(0.2, -0.15, 2);
ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.05, 0.015, 0.001, fiducialToCamera.R);
QuadPoseEstimator alg = new QuadPoseEstimator(1e-8, 200);
alg.setLensDistoriton(distortion);
double r = 1.5;
alg.setFiducial(r, -r, r, r, -r, r, -r, -r);
WorldToCameraToPixel worldToPixel = PerspectiveOps.createWorldToPixel(distortion, fiducialToCamera);
for (int i = 0; i < 4; i++) {
Point3D_F64 X = alg.points.get(i).location;
alg.listObs.add(worldToPixel.transform(X));
}
// perfect
assertEquals(0, alg.computeErrors(fiducialToCamera), 1e-8);
// now with known errors
for (int i = 0; i < 4; i++) {
alg.listObs.get(i).x += 1.5;
assertEquals(1.5, alg.computeErrors(fiducialToCamera), 1e-8);
alg.listObs.get(i).x -= 1.5;
}
}
Aggregations