Search in sources :

Example 1 with ScaleTranslateRotate2D

use of boofcv.struct.sfm.ScaleTranslateRotate2D in project BoofCV by lessthanoptimal.

the class SparseFlowObjectTracker method update.

/**
 * Given the input image compute the new location of the target region and store the results in output.
 *
 * @param input next image in the sequence.
 * @param output Storage for the output.
 * @return true if tracking is successful
 */
public boolean update(Image input, RectangleRotate_F64 output) {
    if (trackLost)
        return false;
    trackFeatures(input, region);
    // See if there are enough points remaining.  use of config.numberOfSamples is some what arbitrary
    if (pairs.size() < config.numberOfSamples) {
        System.out.println("Lack of sample pairs");
        trackLost = true;
        return false;
    }
    // find the motion using tracked features
    if (!estimateMotion.process(pairs.toList())) {
        System.out.println("estimate motion failed");
        trackLost = true;
        return false;
    }
    if (estimateMotion.getFitQuality() > config.robustMaxError) {
        System.out.println("exceeded Max estimation error");
        trackLost = true;
        return false;
    }
    // update the target's location using the found motion
    ScaleTranslateRotate2D model = estimateMotion.getModelParameters();
    region.width *= model.scale;
    region.height *= model.scale;
    double c = Math.cos(model.theta);
    double s = Math.sin(model.theta);
    double x = region.cx;
    double y = region.cy;
    region.cx = (x * c - y * s) * model.scale + model.transX;
    region.cy = (x * s + y * c) * model.scale + model.transY;
    region.theta += model.theta;
    output.set(region);
    // make the current image into the previous image
    swapImages();
    return true;
}
Also used : GenerateScaleTranslateRotate2D(boofcv.alg.sfm.robust.GenerateScaleTranslateRotate2D) ScaleTranslateRotate2D(boofcv.struct.sfm.ScaleTranslateRotate2D) ModelManagerScaleTranslateRotate2D(boofcv.alg.sfm.robust.ModelManagerScaleTranslateRotate2D)

Example 2 with ScaleTranslateRotate2D

use of boofcv.struct.sfm.ScaleTranslateRotate2D in project BoofCV by lessthanoptimal.

the class TestDistanceScaleTranslateRotate2DSq method noisy.

@Test
public void noisy() {
    ScaleTranslateRotate2D model = new ScaleTranslateRotate2D(0.2, 1.5, -2, 3);
    AssociatedPair a = apply(-5, 4, model);
    a.p2.x += 3.5;
    DistanceScaleTranslateRotate2DSq alg = new DistanceScaleTranslateRotate2DSq();
    alg.setModel(model);
    assertEquals(3.5 * 3.5, alg.computeDistance(a), 1e-8);
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) ScaleTranslateRotate2D(boofcv.struct.sfm.ScaleTranslateRotate2D) Test(org.junit.Test)

Example 3 with ScaleTranslateRotate2D

use of boofcv.struct.sfm.ScaleTranslateRotate2D in project BoofCV by lessthanoptimal.

the class TestGenerateScaleTranslateRotate2D method perfect.

@Test
public void perfect() {
    for (int i = 0; i < 100; i++) {
        double theta = rand.nextDouble() * Math.PI * 2 - Math.PI;
        double scale = rand.nextDouble() * 5 + 0.1;
        ScaleTranslateRotate2D model = new ScaleTranslateRotate2D(theta, scale, -2, 3);
        AssociatedPair a = TestDistanceScaleTranslateRotate2DSq.apply(-5, 4, model);
        AssociatedPair b = TestDistanceScaleTranslateRotate2DSq.apply(2, 3, model);
        AssociatedPair c = TestDistanceScaleTranslateRotate2DSq.apply(-3, 2, model);
        List<AssociatedPair> obs = new ArrayList<>();
        obs.add(a);
        obs.add(b);
        obs.add(c);
        ScaleTranslateRotate2D found = new ScaleTranslateRotate2D();
        GenerateScaleTranslateRotate2D alg = new GenerateScaleTranslateRotate2D();
        assertTrue(alg.generate(obs, found));
        assertEquals(model.transX, found.transX, 1e-8);
        assertEquals(model.transY, found.transY, 1e-8);
        assertEquals(model.scale, found.scale, 1e-8);
        assertEquals(model.theta, found.theta, 1e-8);
    }
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) ScaleTranslateRotate2D(boofcv.struct.sfm.ScaleTranslateRotate2D) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with ScaleTranslateRotate2D

use of boofcv.struct.sfm.ScaleTranslateRotate2D in project BoofCV by lessthanoptimal.

the class TestModelManagerScaleTranslateRotate2D method copyModel.

@Test
public void copyModel() {
    ModelManagerScaleTranslateRotate2D alg = new ModelManagerScaleTranslateRotate2D();
    ScaleTranslateRotate2D model = new ScaleTranslateRotate2D(1, 2, 3, 4);
    ScaleTranslateRotate2D found = new ScaleTranslateRotate2D();
    alg.copyModel(model, found);
    assertEquals(model.theta, found.theta, 1e-8);
    assertEquals(model.scale, found.scale, 1e-8);
    assertEquals(model.transX, found.transX, 1e-8);
    assertEquals(model.transY, found.transY, 1e-8);
}
Also used : ScaleTranslateRotate2D(boofcv.struct.sfm.ScaleTranslateRotate2D) Test(org.junit.Test)

Example 5 with ScaleTranslateRotate2D

use of boofcv.struct.sfm.ScaleTranslateRotate2D in project BoofCV by lessthanoptimal.

the class TestDistanceScaleTranslateRotate2DSq method perfect.

@Test
public void perfect() {
    ScaleTranslateRotate2D model = new ScaleTranslateRotate2D(0.2, 1.5, -2, 3);
    AssociatedPair a = apply(-5, 4, model);
    DistanceScaleTranslateRotate2DSq alg = new DistanceScaleTranslateRotate2DSq();
    alg.setModel(model);
    assertEquals(0, alg.computeDistance(a), 1e-8);
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) ScaleTranslateRotate2D(boofcv.struct.sfm.ScaleTranslateRotate2D) Test(org.junit.Test)

Aggregations

ScaleTranslateRotate2D (boofcv.struct.sfm.ScaleTranslateRotate2D)6 Test (org.junit.Test)5 AssociatedPair (boofcv.struct.geo.AssociatedPair)4 ArrayList (java.util.ArrayList)2 GenerateScaleTranslateRotate2D (boofcv.alg.sfm.robust.GenerateScaleTranslateRotate2D)1 ModelManagerScaleTranslateRotate2D (boofcv.alg.sfm.robust.ModelManagerScaleTranslateRotate2D)1