use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class TestTrifocalAlgebraicPoint7 method checkInducedErrors.
/**
* Computes the error using induced homographies.
*/
public void checkInducedErrors(TrifocalTensor tensor, List<AssociatedTriple> observations, double tol) {
for (AssociatedTriple o : observations) {
// homogeneous vector for observations in views 2 and 3
Vector3D_F64 obs2 = new Vector3D_F64(o.p2.x, o.p2.y, 1);
Vector3D_F64 obs3 = new Vector3D_F64(o.p3.x, o.p3.y, 1);
// compute lines which pass through the observations
Vector3D_F64 axisY = new Vector3D_F64(0, 1, 0);
Vector3D_F64 line2 = new Vector3D_F64();
Vector3D_F64 line3 = new Vector3D_F64();
GeometryMath_F64.cross(obs2, axisY, line2);
GeometryMath_F64.cross(obs3, axisY, line3);
// compute induced homographies
DMatrixRMaj H12 = MultiViewOps.inducedHomography12(tensor, line3, null);
DMatrixRMaj H13 = MultiViewOps.inducedHomography13(tensor, line2, null);
Point2D_F64 induced2 = new Point2D_F64();
Point2D_F64 induced3 = new Point2D_F64();
GeometryMath_F64.mult(H12, o.p1, induced2);
GeometryMath_F64.mult(H13, o.p1, induced3);
assertEquals(0, induced2.distance(o.p2), tol);
assertEquals(0, induced3.distance(o.p3), tol);
}
}
use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class TestTrifocalLinearPoint7 method fullTest.
@Test
public void fullTest() {
TrifocalLinearPoint7 alg = new TrifocalLinearPoint7();
assertTrue(alg.process(observations, found));
// validate the solution by using a constraint
for (AssociatedTriple a : observations) {
DMatrixRMaj A = MultiViewOps.constraint(found, a.p1, a.p2, a.p3, null);
assertEquals(0, NormOps_DDRM.normF(A), 1e-7);
}
}
use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class TestBaseDetectFiducialSquare method render.
/**
* Draws a distorted pattern onto the output
*/
public static void render(GrayU8 pattern, Quadrilateral_F64 where, GrayU8 output) {
int w = pattern.width;
int h = pattern.height;
ArrayList<AssociatedPair> associatedPairs = new ArrayList<>();
associatedPairs.add(new AssociatedPair(where.a, new Point2D_F64(0, 0)));
associatedPairs.add(new AssociatedPair(where.b, new Point2D_F64(w, 0)));
associatedPairs.add(new AssociatedPair(where.c, new Point2D_F64(w, h)));
associatedPairs.add(new AssociatedPair(where.d, new Point2D_F64(0, h)));
Estimate1ofEpipolar computeHomography = FactoryMultiView.computeHomographyDLT(true);
DMatrixRMaj H = new DMatrixRMaj(3, 3);
computeHomography.process(associatedPairs, H);
// Create the transform for distorting the image
FMatrixRMaj H32 = new FMatrixRMaj(3, 3);
ConvertMatrixData.convert(H, H32);
PointTransformHomography_F32 homography = new PointTransformHomography_F32(H32);
PixelTransform2_F32 pixelTransform = new PointToPixelTransform_F32(homography);
// Apply distortion and show the results
DistortImageOps.distortSingle(pattern, output, pixelTransform, InterpolationType.BILINEAR, BorderType.SKIP);
// ShowImages.showWindow(output, "Rendered");
// try {Thread.sleep(10000);} catch (InterruptedException e) {}
}
use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class ImplPerspectiveOps_F64 method calibrationMatrix.
public static DMatrixRMaj calibrationMatrix(CameraPinhole param, DMatrixRMaj K) {
if (K == null) {
K = new DMatrixRMaj(3, 3);
}
CommonOps_DDRM.fill(K, 0);
K.data[0] = (double) param.fx;
K.data[1] = (double) param.skew;
K.data[2] = (double) param.cx;
K.data[4] = (double) param.fy;
K.data[5] = (double) param.cy;
K.data[8] = 1;
return K;
}
use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class PnPLepetitEPnP method selectWorldControlPoints.
/**
* Selects control points along the data's axis and the data's centroid. If the data is determined
* to be planar then only 3 control points are selected.
*
* The data's axis is determined by computing the covariance matrix then performing SVD. The axis
* is contained along the
*/
public void selectWorldControlPoints(List<Point3D_F64> worldPts, FastQueue<Point3D_F64> controlWorldPts) {
UtilPoint3D_F64.mean(worldPts, meanWorldPts);
// covariance matrix elements, summed up here for speed
double c11 = 0, c12 = 0, c13 = 0, c22 = 0, c23 = 0, c33 = 0;
final int N = worldPts.size();
for (int i = 0; i < N; i++) {
Point3D_F64 p = worldPts.get(i);
double dx = p.x - meanWorldPts.x;
double dy = p.y - meanWorldPts.y;
double dz = p.z - meanWorldPts.z;
c11 += dx * dx;
c12 += dx * dy;
c13 += dx * dz;
c22 += dy * dy;
c23 += dy * dz;
c33 += dz * dz;
}
c11 /= N;
c12 /= N;
c13 /= N;
c22 /= N;
c23 /= N;
c33 /= N;
DMatrixRMaj covar = new DMatrixRMaj(3, 3, true, c11, c12, c13, c12, c22, c23, c13, c23, c33);
// find the data's orientation and check to see if it is planar
svd.decompose(covar);
double[] singularValues = svd.getSingularValues();
DMatrixRMaj V = svd.getV(null, false);
SingularOps_DDRM.descendingOrder(null, false, singularValues, 3, V, false);
// planar check
if (singularValues[0] < singularValues[2] * 1e13) {
numControl = 4;
} else {
numControl = 3;
}
// put control points along the data's major axises
controlWorldPts.reset();
for (int i = 0; i < numControl - 1; i++) {
double m = Math.sqrt(singularValues[1]) * magicNumber;
double vx = V.unsafe_get(0, i) * m;
double vy = V.unsafe_get(1, i) * m;
double vz = V.unsafe_get(2, i) * m;
controlWorldPts.grow().set(meanWorldPts.x + vx, meanWorldPts.y + vy, meanWorldPts.z + vz);
}
// set a control point to be the centroid
controlWorldPts.grow().set(meanWorldPts.x, meanWorldPts.y, meanWorldPts.z);
}
Aggregations