use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class TestProjectiveReconstructionByFactorization method perfect_input_badDepths.
/**
* All data is perfect, but 1 is used for the depth estimate
*/
@Test
void perfect_input_badDepths() {
int numViews = 8;
int numFeatures = 10;
simulate(numViews, numFeatures, false);
ProjectiveStructureByFactorization alg = new ProjectiveStructureByFactorization();
alg.initialize(features3D.size(), projections.size());
// depth isn't known so just set it to 1. it could easily converge to a poor local optimal
alg.setAllDepths(1);
for (int viewIdx = 0; viewIdx < projections.size(); viewIdx++) {
alg.setPixels(viewIdx, observations.get(viewIdx));
}
assertTrue(alg.process());
DMatrixRMaj P = new DMatrixRMaj(3, 4);
Point4D_F64 X = new Point4D_F64();
int total = 0;
for (int viewIdx = 0; viewIdx < numViews; viewIdx++) {
alg.getCameraMatrix(viewIdx, P);
for (int featureIdx = 0; featureIdx < numFeatures; featureIdx++) {
alg.getFeature3D(featureIdx, X);
Point2D_F64 expected = observations.get(viewIdx).get(featureIdx);
Point3D_F64 xh = PerspectiveOps.renderPixel(P, X, (Point3D_F64) null);
Point2D_F64 found = new Point2D_F64(xh.x / xh.z, xh.y / xh.z);
// System.out.println(expected+" "+found);
if (expected.distance(found) <= 2)
total++;
}
}
// see if a large number of solutions are within 2 pixels
assertTrue(total >= 0.95 * numViews * numFeatures);
}
use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class TestProjectiveStructureFromHomographies method constructLinearSystem.
/**
* Tests linear system by seeing if zero is returned when truth is passed in. Input camera matrix is
* K*[R,T] to make the match much easier.
*/
@Test
void constructLinearSystem() {
int numViews = 4;
int numFeatures = 7;
simulate(numViews, numFeatures, true);
ProjectiveStructureFromHomographies alg = new ProjectiveStructureFromHomographies();
List<DMatrixRMaj> homographies = new ArrayList<>();
for (int i = 0; i < projections.size(); i++) {
DMatrixRMaj R = new DMatrixRMaj(3, 3);
CommonOps_DDRM.extract(projections.get(i), 0, 0, R);
homographies.add(R);
}
List<List<PointIndex2D_F64>> observations = convertToPointIndex();
alg.computeConstants(homographies, observations, numFeatures);
alg.constructLinearSystem(homographies, observations);
DMatrixRMaj X = new DMatrixRMaj(alg.numUnknown, 1);
for (int i = 0; i < features3D.size(); i++) {
int row = i * 3;
X.data[row] = features3D.get(i).x;
X.data[row + 1] = features3D.get(i).y;
X.data[row + 2] = features3D.get(i).z;
}
for (int i = 0; i < homographies.size(); i++) {
// homography is from view 0 to view i
DMatrixRMaj P = projections.get(i);
int row = features3D.size() * 3 + i * 3;
X.data[row] = P.get(0, 3);
X.data[row + 1] = P.get(1, 3);
X.data[row + 2] = P.get(2, 3);
}
DMatrixRMaj B = new DMatrixRMaj(alg.numEquations, 1);
CommonOps_DDRM.mult(alg.A, X, B);
assertEquals(0, NormOps_DDRM.normF(B), UtilEjml.TEST_F64);
}
use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class TestProjectiveStructureFromHomographies method perfect_input.
/**
* Given perfect input see if it can create camera matrices which will return the original observations
*/
@Test
void perfect_input() {
int numViews = 8;
int numFeatures = 20;
simulate(numViews, numFeatures, true);
ProjectiveStructureFromHomographies alg = new ProjectiveStructureFromHomographies();
assertTrue(alg.proccess(computeHomographies(), convertToPointIndex(), numFeatures));
DMatrixRMaj P = new DMatrixRMaj(3, 4);
Point3D_F64 X = new Point3D_F64();
for (int viewIdx = 0; viewIdx < numViews; viewIdx++) {
alg.getCameraMatrix(viewIdx, P);
for (int featureIdx = 0; featureIdx < numFeatures; featureIdx++) {
alg.getFeature3D(featureIdx, X);
Point2D_F64 expected = observations.get(viewIdx).get(featureIdx);
Point2D_F64 x = PerspectiveOps.renderPixel(P, X, (Point2D_F64) null);
assertTrue(expected.distance(x) < UtilEjml.TEST_F64_SQ);
}
}
}
use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class TestRefineTwoViewPinholeRotation method evaluateImperfect.
private void evaluateImperfect(CameraPinhole intrinsic1, CameraPinhole intrinsic2, List<AssociatedPair> pairs) {
var alg = new RefineTwoViewPinholeRotation();
// Apply some constraints. Yes this test isn't exhaustive at all.
alg.assumeUnityAspect = true;
alg.zeroSkew = true;
alg.assumeSameIntrinsics = false;
alg.knownFocalLength = false;
// Focal length and rotation are going to be way off as a test
CameraPinhole found1 = new CameraPinhole(200, 200, 0.0, 530, 530, 1000, 1000);
CameraPinhole found2 = new CameraPinhole(1000, 1000, 0.0, 430, 430, 800, 800);
DMatrixRMaj R = CommonOps_DDRM.identity(3);
alg.converge.maxIterations = 40;
// alg.setVerbose(System.out, null);
assertTrue(alg.refine(pairs, R, found1, found2));
// Should be significantly better
assertTrue(alg.errorAfter * 1e5 <= alg.errorBefore);
// Check constraints
assertEquals(found1.fx, found1.fy);
assertEquals(found2.fx, found2.fy);
assertEquals(0.0, found1.skew);
assertEquals(0.0, found2.skew);
// Based on manual inspection there seems to be redundancy in these equations some place that I've
// not yet dug out. The error is zero but K1 and K2 are significantly different. R is "close"
// very crude test for focal length
assertEquals(intrinsic1.fx, found1.fx, 150);
assertEquals(intrinsic2.fx, found2.fy, 150);
// Compute the number of radians different the two rotations are
DMatrixRMaj diffR = CommonOps_DDRM.multTransA(view1_to_view2.R, R, null);
double angle = ConvertRotation3D_F64.matrixToRodrigues(diffR, null).theta;
assertEquals(0.0, angle, 0.05);
}
use of org.ejml.data.DMatrixRMaj in project BoofCV by lessthanoptimal.
the class TestRefineTwoViewPinholeRotation method perfectInput.
/**
* Give it perfect input and see if it screws things up
*/
@Test
void perfectInput() {
CameraPinhole intrinsic1 = new CameraPinhole(400, 410, 0.1, 500, 550, 1000, 1000);
CameraPinhole intrinsic2 = new CameraPinhole(600, 550, 0.02, 400, 440, 800, 800);
List<AssociatedPair> pairs = renderPairs(intrinsic1, intrinsic2, 50, 0.0);
var alg = new RefineTwoViewPinholeRotation();
// turn off all assumptions
alg.assumeUnityAspect = false;
alg.zeroSkew = false;
alg.assumeSameIntrinsics = false;
CameraPinhole found1 = new CameraPinhole(intrinsic1);
CameraPinhole found2 = new CameraPinhole(intrinsic2);
DMatrixRMaj R = view1_to_view2.R.copy();
assertTrue(alg.refine(pairs, R, found1, found2));
// Score shouldn't get worse, but since the input is perfect it might not get better
assertTrue(alg.errorAfter <= alg.errorBefore);
// should be very very similar
assertTrue(found1.isEquals(intrinsic1, 1e-6));
assertTrue(found2.isEquals(intrinsic2, 1e-6));
assertTrue(MatrixFeatures_DDRM.isIdentical(view1_to_view2.R, R, 1e-6));
}
Aggregations