use of boofcv.struct.sfm.ScaleTranslate2D in project BoofCV by lessthanoptimal.
the class TldAdjustRegion method process.
/**
* Adjusts target rectangle using track information
*
* @param pairs List of feature location in previous and current frame.
* @param targetRectangle (Input) current location of rectangle. (output) adjusted location
* @return true if successful
*/
public boolean process(FastQueue<AssociatedPair> pairs, Rectangle2D_F64 targetRectangle) {
// estimate how the rectangle has changed and update it
if (!estimateMotion.process(pairs.toList()))
return false;
ScaleTranslate2D motion = estimateMotion.getModelParameters();
adjustRectangle(targetRectangle, motion);
if (targetRectangle.p0.x < 0 || targetRectangle.p0.y < 0)
return false;
if (targetRectangle.p1.x >= imageWidth || targetRectangle.p1.y >= imageHeight)
return false;
return true;
}
use of boofcv.struct.sfm.ScaleTranslate2D in project BoofCV by lessthanoptimal.
the class TestTldAdjustRegion method process.
@Test
public void process() {
ScaleTranslate2D motion = new ScaleTranslate2D(1.5, 2, 3);
FastQueue<AssociatedPair> pairs = new FastQueue<>(AssociatedPair.class, true);
for (int i = 0; i < 200; i++) {
AssociatedPair p = pairs.grow();
p.p1.x = rand.nextGaussian() * 2;
p.p1.y = rand.nextGaussian() * 2;
p.p2.x = p.p1.x * motion.scale + motion.transX;
p.p2.y = p.p1.y * motion.scale + motion.transY;
}
Rectangle2D_F64 rect = new Rectangle2D_F64(10, 20, 30, 40);
TldAdjustRegion alg = new TldAdjustRegion(30);
alg.init(300, 400);
assertTrue(alg.process(pairs, rect));
assertEquals(17, rect.p0.x, 1e-8);
assertEquals(33, rect.p0.y, 1e-8);
assertEquals(47, rect.p1.x, 1e-8);
assertEquals(63, rect.p1.y, 1e-8);
}
use of boofcv.struct.sfm.ScaleTranslate2D in project BoofCV by lessthanoptimal.
the class TestDistanceScaleTranslate2DSq method multiple.
@Test
public void multiple() {
ScaleTranslate2D model = new ScaleTranslate2D(1.5, -2, 3);
AssociatedPair a = apply(-5, 4, model);
a.p2.x += 3.5;
AssociatedPair b = apply(2.15, 2, model);
List<AssociatedPair> obs = new ArrayList<>();
obs.add(a);
obs.add(b);
DistanceScaleTranslate2DSq alg = new DistanceScaleTranslate2DSq();
alg.setModel(model);
double[] found = new double[2];
alg.computeDistance(obs, found);
assertEquals(3.5 * 3.5, found[0], 1e-8);
assertEquals(0, found[1], 1e-8);
}
use of boofcv.struct.sfm.ScaleTranslate2D in project BoofCV by lessthanoptimal.
the class TestGenerateScaleTranslate2D method pathological_noscale.
/**
* Both points are at 0,0. Scale can't be resolved
*/
@Test
public void pathological_noscale() {
ScaleTranslate2D model = new ScaleTranslate2D(1.5, -2, 3);
AssociatedPair a = TestDistanceScaleTranslate2DSq.apply(0, 0, model);
AssociatedPair b = TestDistanceScaleTranslate2DSq.apply(0, 0, model);
List<AssociatedPair> obs = new ArrayList<>();
obs.add(a);
obs.add(b);
ScaleTranslate2D found = new ScaleTranslate2D();
GenerateScaleTranslate2D alg = new GenerateScaleTranslate2D();
assertFalse(alg.generate(obs, found));
}
use of boofcv.struct.sfm.ScaleTranslate2D in project BoofCV by lessthanoptimal.
the class TestGenerateScaleTranslate2D method perfect.
@Test
public void perfect() {
ScaleTranslate2D model = new ScaleTranslate2D(1.5, -2, 3);
AssociatedPair a = TestDistanceScaleTranslate2DSq.apply(-5, 4, model);
AssociatedPair b = TestDistanceScaleTranslate2DSq.apply(2, 3, model);
List<AssociatedPair> obs = new ArrayList<>();
obs.add(a);
obs.add(b);
ScaleTranslate2D found = new ScaleTranslate2D();
GenerateScaleTranslate2D alg = new GenerateScaleTranslate2D();
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);
}
Aggregations