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;
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations