Search in sources :

Example 1 with Se2_F32

use of georegression.struct.se.Se2_F32 in project BoofCV by lessthanoptimal.

the class TestImageMotionPointTrackerKey method process.

/**
 * Give it a very simple example and see if it computes the correct motion and has the expected behavior
 * when processing an image
 */
@Test
public void process() {
    // what the initial transform should be
    Se2_F32 computed = new Se2_F32(4, 5, 6);
    Se2_F32 model = new Se2_F32();
    DummyTracker tracker = new DummyTracker();
    DummyModelMatcher<Se2_F32> matcher = new DummyModelMatcher<>(computed, 5);
    GrayU8 input = new GrayU8(20, 30);
    ImageMotionPointTrackerKey<GrayU8, Se2_F32> alg = new ImageMotionPointTrackerKey<>(tracker, matcher, null, model, 1000);
    // the first time it processes an image it should always return false since no motion can be estimated
    assertFalse(alg.process(input));
    assertFalse(alg.isKeyFrame());
    assertEquals(0, tracker.numSpawn);
    // make the current frame into the keyframe
    // request that the current frame is a keyframe
    alg.changeKeyFrame();
    assertEquals(0, tracker.numDropAll);
    assertEquals(1, tracker.numSpawn);
    assertTrue(alg.isKeyFrame());
    // now it should compute some motion
    assertTrue(alg.process(input));
    assertFalse(alg.isKeyFrame());
    // no new tracks should have been spawned
    assertEquals(1, tracker.numSpawn);
    // test the newly computed results
    assertEquals(computed.getX(), alg.getKeyToCurr().getX(), 1e-8);
    assertEquals(computed.getX(), alg.getWorldToCurr().getX(), 1e-8);
    // see if reset does its job
    assertEquals(0, tracker.numDropAll);
    alg.reset();
    assertEquals(1, tracker.numDropAll);
    assertEquals(0, alg.getTotalFramesProcessed());
    assertEquals(0, alg.getKeyToCurr().getX(), 1e-8);
    assertEquals(0, alg.getWorldToCurr().getX(), 1e-8);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) Se2_F32(georegression.struct.se.Se2_F32) Test(org.junit.Test)

Example 2 with Se2_F32

use of georegression.struct.se.Se2_F32 in project BoofCV by lessthanoptimal.

the class TestImageMotionPointTrackerKey method testPrune.

/**
 * See if tracks are pruned after not being in inlier set for X time
 */
@Test
public void testPrune() {
    Se2_F32 computed = new Se2_F32(4, 5, 6);
    Se2_F32 model = new Se2_F32();
    DummyTracker tracker = new DummyTracker();
    DummyModelMatcher<Se2_F32> matcher = new DummyModelMatcher<>(computed, 5);
    GrayU8 input = new GrayU8(20, 30);
    ImageMotionPointTrackerKey<GrayU8, Se2_F32> alg = new ImageMotionPointTrackerKey<>(tracker, matcher, null, model, 5);
    // create tracks such that only some of them will be dropped
    alg.totalFramesProcessed = 9;
    for (int i = 0; i < 10; i++) {
        PointTrack t = new PointTrack();
        AssociatedPairTrack a = new AssociatedPairTrack();
        a.lastUsed = i;
        t.cookie = a;
        tracker.list.add(t);
    }
    // update
    alg.process(input);
    // check to see how many were dropped
    assertEquals(6, tracker.numDropped);
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack) GrayU8(boofcv.struct.image.GrayU8) Se2_F32(georegression.struct.se.Se2_F32) Test(org.junit.Test)

Example 3 with Se2_F32

use of georegression.struct.se.Se2_F32 in project BoofCV by lessthanoptimal.

the class TestImageMotionPointTrackerKey method changeKeyFrame.

/**
 * Test the keyframe based on the definition of the keyframe
 */
@Test
public void changeKeyFrame() {
    Se2_F32 computed = new Se2_F32(4, 5, 6);
    Se2_F32 model = new Se2_F32();
    DummyTracker tracker = new DummyTracker();
    DummyModelMatcher<Se2_F32> matcher = new DummyModelMatcher<>(computed, 5);
    GrayU8 input = new GrayU8(20, 30);
    ImageMotionPointTrackerKey<GrayU8, Se2_F32> alg = new ImageMotionPointTrackerKey<>(tracker, matcher, null, model, 100);
    // process twice to change the transforms
    alg.process(input);
    alg.changeKeyFrame();
    alg.process(input);
    // sanity check
    Se2_F32 worldToKey = alg.getWorldToKey();
    assertEquals(0, worldToKey.getX(), 1e-8);
    assertEquals(1, tracker.numSpawn);
    // invoke the function being tested
    alg.changeKeyFrame();
    // the keyframe should be changed and new tracks spawned
    assertEquals(2, tracker.numSpawn);
    // worldToKey should now be equal to worldToCurr
    worldToKey = alg.getWorldToKey();
    assertEquals(computed.getX(), worldToKey.getX(), 1e-8);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) Se2_F32(georegression.struct.se.Se2_F32) Test(org.junit.Test)

Example 4 with Se2_F32

use of georegression.struct.se.Se2_F32 in project BoofCV by lessthanoptimal.

the class DistortSupport method transformRotate.

/**
 * Creates a {@link boofcv.alg.distort.PixelTransformAffine_F32} from the dst image into the src image.
 *
 * @param x0 Center of rotation in input image coordinates.
 * @param y0 Center of rotation in input image coordinates.
 * @param x1 Center of rotation in output image coordinates.
 * @param y1 Center of rotation in output image coordinates.
 * @param angle Angle of rotation.
 */
public static PixelTransformAffine_F32 transformRotate(float x0, float y0, float x1, float y1, float angle) {
    // make the coordinate system's origin the image center
    Se2_F32 imageToCenter = new Se2_F32(-x0, -y0, 0);
    Se2_F32 rotate = new Se2_F32(0, 0, angle);
    Se2_F32 centerToImage = new Se2_F32(x1, y1, 0);
    InvertibleTransformSequence sequence = new InvertibleTransformSequence();
    sequence.addTransform(true, imageToCenter);
    sequence.addTransform(true, rotate);
    sequence.addTransform(true, centerToImage);
    Se2_F32 total = new Se2_F32();
    sequence.computeTransform(total);
    Se2_F32 inv = total.invert(null);
    Affine2D_F32 affine = ConvertTransform_F32.convert(inv, (Affine2D_F32) null);
    PixelTransformAffine_F32 distort = new PixelTransformAffine_F32();
    distort.set(affine);
    return distort;
}
Also used : InvertibleTransformSequence(georegression.transform.InvertibleTransformSequence) Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Se2_F32(georegression.struct.se.Se2_F32)

Aggregations

Se2_F32 (georegression.struct.se.Se2_F32)4 GrayU8 (boofcv.struct.image.GrayU8)3 Test (org.junit.Test)3 PointTrack (boofcv.abst.feature.tracker.PointTrack)1 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)1 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)1 InvertibleTransformSequence (georegression.transform.InvertibleTransformSequence)1