Search in sources :

Example 76 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.

the class RectifyFundamental method process.

/**
 * Compute rectification transforms for the stereo pair given a fundamental matrix and its observations.
 *
 * @param F Fundamental matrix
 * @param observations Observations used to compute F
 * @param width Width of first image.
 * @param height Height of first image.
 */
public void process(DMatrixRMaj F, List<AssociatedPair> observations, int width, int height) {
    int centerX = width / 2;
    int centerY = height / 2;
    MultiViewOps.extractEpipoles(F, epipole1, epipole2);
    checkEpipoleInside(width, height);
    // compute the transform H which will send epipole2 to infinity
    SimpleMatrix R = rotateEpipole(epipole2, centerX, centerY);
    SimpleMatrix T = translateToOrigin(centerX, centerY);
    SimpleMatrix G = computeG(epipole2, centerX, centerY);
    SimpleMatrix H = G.mult(R).mult(T);
    // Find the two matching transforms
    SimpleMatrix Hzero = computeHZero(F, epipole2, H);
    SimpleMatrix Ha = computeAffineH(observations, H.getDDRM(), Hzero.getDDRM());
    rect1.setTo(Ha.mult(Hzero).getDDRM());
    rect2.setTo(H.getDDRM());
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 77 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.

the class ImplRectifyImageOps_F64 method adjustUncalibrated.

/**
 * Internal function which applies the rectification adjustment to an uncalibrated stereo pair
 */
private static void adjustUncalibrated(DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, RectangleLength2D_F64 bound, double scale) {
    // translation
    double deltaX = -bound.x0 * scale;
    double deltaY = -bound.y0 * scale;
    // adjustment matrix
    SimpleMatrix A = new SimpleMatrix(3, 3, true, new double[] { scale, 0, deltaX, 0, scale, deltaY, 0, 0, 1 });
    SimpleMatrix rL = SimpleMatrix.wrap(rectifyLeft);
    SimpleMatrix rR = SimpleMatrix.wrap(rectifyRight);
    rectifyLeft.setTo(A.mult(rL).getDDRM());
    rectifyRight.setTo(A.mult(rR).getDDRM());
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 78 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.

the class RectifyFundamental method rotateEpipole.

/**
 * Apply a rotation such that the epipole is equal to [f,0,1]
 */
static SimpleMatrix rotateEpipole(Point3D_F64 epipole, int x0, int y0) {
    // compute rotation which will set
    // x * sin(theta) + y * cos(theta) = 0
    double x = epipole.x / epipole.z - x0;
    double y = epipole.y / epipole.z - y0;
    double theta = Math.atan2(-y, x);
    double c = Math.cos(theta);
    double s = Math.sin(theta);
    SimpleMatrix R = new SimpleMatrix(3, 3);
    R.setRow(0, 0, c, -s);
    R.setRow(1, 0, s, c);
    R.set(2, 2, 1);
    return R;
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 79 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.

the class RectifyFundamental method computeHZero.

/**
 * H0 = H*M
 * P=[M|m] from canonical camera
 */
private SimpleMatrix computeHZero(DMatrixRMaj F, Point3D_F64 e2, SimpleMatrix H) {
    Vector3D_F64 v = new Vector3D_F64(.1, 0.5, .2);
    // need to make sure M is not singular for this technique to work
    SimpleMatrix P = SimpleMatrix.wrap(MultiViewOps.fundamentalToProjective(F, e2, v, 1));
    SimpleMatrix M = P.extractMatrix(0, 3, 0, 3);
    return H.mult(M);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Vector3D_F64(georegression.struct.point.Vector3D_F64)

Example 80 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.

the class TestPerspectiveOps method createCameraMatrix.

@Test
void createCameraMatrix() {
    SimpleMatrix R = SimpleMatrix.random_DDRM(3, 3, -1, 1, rand);
    Vector3D_F64 T = new Vector3D_F64(2, 3, -4);
    SimpleMatrix K = SimpleMatrix.wrap(RandomMatrices_DDRM.triangularUpper(3, 0, -1, 1, rand));
    SimpleMatrix T_ = new SimpleMatrix(3, 1, true, new double[] { T.x, T.y, T.z });
    // test calibrated camera
    DMatrixRMaj found = PerspectiveOps.createCameraMatrix(R.getDDRM(), T, null, null);
    for (int i = 0; i < 3; i++) {
        assertEquals(found.get(i, 3), T_.get(i), 1e-8);
        for (int j = 0; j < 3; j++) {
            assertEquals(found.get(i, j), R.get(i, j), 1e-8);
        }
    }
    // test uncalibrated camera
    found = PerspectiveOps.createCameraMatrix(R.getDDRM(), T, K.getDDRM(), null);
    SimpleMatrix expectedR = K.mult(R);
    SimpleMatrix expectedT = K.mult(T_);
    for (int i = 0; i < 3; i++) {
        assertEquals(found.get(i, 3), expectedT.get(i), 1e-8);
        for (int j = 0; j < 3; j++) {
            assertEquals(found.get(i, j), expectedR.get(i, j), 1e-8);
        }
    }
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) DMatrixRMaj(org.ejml.data.DMatrixRMaj) georegression.struct.point(georegression.struct.point) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleMatrix (org.ejml.simple.SimpleMatrix)156 Test (org.junit.Test)30 Layer (org.gitia.froog.layer.Layer)14 Test (org.junit.jupiter.api.Test)13 Map (java.util.Map)12 ArrayList (java.util.ArrayList)11 TransferFunction (org.gitia.froog.transferfunction.TransferFunction)10 Tree (edu.stanford.nlp.trees.Tree)9 TwoDimensionalMap (edu.stanford.nlp.util.TwoDimensionalMap)9 List (java.util.List)8 LexicalizedParser (edu.stanford.nlp.parser.lexparser.LexicalizedParser)7 Pair (edu.stanford.nlp.util.Pair)6 EmbeddingExtractor (edu.stanford.nlp.coref.neural.EmbeddingExtractor)5 Embedding (edu.stanford.nlp.neural.Embedding)5 DeepTree (edu.stanford.nlp.trees.DeepTree)5 CoreLabel (edu.stanford.nlp.ling.CoreLabel)4 SimpleTensor (edu.stanford.nlp.neural.SimpleTensor)4 DVModel (edu.stanford.nlp.parser.dvparser.DVModel)4 Logsig (org.gitia.froog.transferfunction.Logsig)4 Ignore (org.junit.Ignore)4