use of boofcv.struct.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.
the class TestKltTracker method testTracking_border2.
/**
* Place a feature on the border then put it inside the image. See if it moves towards the border
*/
@Test
void testTracking_border2() {
ImageMiscOps.fillUniform(image, rand, 1, 100);
GradientSobel.process(image, derivX, derivY, new ImageBorder1D_F32(BorderIndex1D_Extend::new));
KltTracker<GrayF32, GrayF32> tracker = createDefaultTracker();
tracker.setImage(image, derivX, derivY);
int r = 3;
KltFeature feature = new KltFeature(r);
// just outside the image
feature.setPosition(imageWidth - r - 1 + 1, imageHeight - r - 1 + 1);
tracker.setDescription(feature);
// now fully inside the image
feature.setPosition(imageWidth - r - 1, imageHeight - r - 1);
// see if it got sucked back
assertSame(KltTrackFault.SUCCESS, tracker.track(feature));
assertEquals(imageWidth - r - 1 + 1, feature.x, 0.01);
assertEquals(imageHeight - r - 1 + 1, feature.y, 0.01);
// same thing but with the top left image
feature.setPosition(r - 1, 1);
tracker.setDescription(feature);
// put it fully inside the image
feature.setPosition(r, r);
// see if it got sucked back
assertSame(KltTrackFault.SUCCESS, tracker.track(feature));
assertEquals(r - 1, feature.x, 0.01);
assertEquals(1, feature.y, 0.01);
}
use of boofcv.struct.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.
the class TestKltTracker method testSubImages.
/**
* Process the same features in two different sets of image. only difference is that one is a sub image
* results should be identical
*/
@Test
void testSubImages() {
ImageMiscOps.fillUniform(image, rand, 0, 100);
GradientSobel.process(image, derivX, derivY, new ImageBorder1D_F32(BorderIndex1D_Extend::new));
KltTracker<GrayF32, GrayF32> trackerA = createDefaultTracker();
trackerA.setImage(image, derivX, derivY);
KltTracker<GrayF32, GrayF32> trackerB = createDefaultTracker();
GrayF32 image = BoofTesting.createSubImageOf(this.image);
GrayF32 derivX = BoofTesting.createSubImageOf(this.derivX);
GrayF32 derivY = BoofTesting.createSubImageOf(this.derivY);
trackerB.setImage(image, derivX, derivY);
for (int y = 0; y < imageHeight; y += 4) {
for (int x = 0; x < imageWidth; x += 4) {
KltFeature featureA = new KltFeature(3);
KltFeature featureB = new KltFeature(3);
featureA.setPosition(x, y);
featureB.setPosition(x, y);
trackerA.setDescription(featureA);
trackerB.setDescription(featureB);
float dx = rand.nextFloat() * 2 - 1;
float dy = rand.nextFloat() * 2 - 1;
featureA.setPosition(x + dx, y + dy);
featureB.setPosition(x + dx, y + dy);
KltTrackFault faultA = trackerA.track(featureA);
KltTrackFault faultB = trackerB.track(featureB);
assertSame(faultA, faultB);
if (faultA == KltTrackFault.SUCCESS) {
assertEquals(featureB.x, featureA.x);
assertEquals(featureB.y, featureA.y);
}
}
}
}
use of boofcv.struct.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.
the class TestKltTracker method setDescription_compare.
/**
* Compares the border algorithm to the inner algorithm
*/
@Test
void setDescription_compare() {
ImageMiscOps.fillUniform(image, rand, 0, 100);
GradientSobel.process(image, derivX, derivY, new ImageBorder1D_F32(BorderIndex1D_Extend::new));
KltTracker<GrayF32, GrayF32> tracker = createDefaultTracker();
tracker.setImage(image, derivX, derivY);
KltFeature featureA = new KltFeature(3);
KltFeature featureB = new KltFeature(3);
featureA.setPosition(20.6f, 25.1f);
featureB.setPosition(20.6f, 25.1f);
tracker.setAllowedBounds(featureA);
tracker.internalSetDescription(featureA, derivX, derivY);
tracker.internalSetDescriptionBorder(featureB, derivX, derivY);
for (int i = 0; i < featureA.desc.data.length; i++) {
assertEquals(featureB.desc.data[i], featureA.desc.data[i]);
assertEquals(featureB.derivX.data[i], featureA.derivX.data[i]);
assertEquals(featureB.derivY.data[i], featureA.derivY.data[i]);
}
}
use of boofcv.struct.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.
the class TestPyramidKltTracker method setTargetLocation.
private void setTargetLocation(int x, int y) {
ImageMiscOps.fillUniform(image, rand, 0, 1);
ImageMiscOps.fillRectangle(image, 100, x, y, 20, 20);
pyramid.process(image);
for (int i = 0; i < pyramid.getNumLayers(); i++) {
GradientSobel.process(pyramid.getLayer(i), derivX[i], derivY[i], new ImageBorder1D_F32(BorderIndex1D_Extend::new));
}
}
use of boofcv.struct.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.
the class TestKltTracker method compare_computeGandE_border_toInsideImage.
@Test
void compare_computeGandE_border_toInsideImage() {
ImageMiscOps.fillUniform(image, rand, 0, 100);
GradientSobel.process(image, derivX, derivY, new ImageBorder1D_F32(BorderIndex1D_Extend::new));
KltTracker<GrayF32, GrayF32> tracker = createDefaultTracker();
tracker.setImage(image, derivX, derivY);
KltFeature feature = new KltFeature(2);
feature.setPosition(20, 22);
tracker.setDescription(feature);
tracker.currDesc.reshape(5, 5);
// need to compute E from a shifted location or else it will be zero
tracker.computeE(feature, 21, 23);
float expectedGxx = feature.Gxx;
float expectedGxy = feature.Gxy;
float expectedGyy = feature.Gyy;
float expectedEx = tracker.Ex;
float expectedEy = tracker.Ey;
assertTrue(0 != expectedGxx);
assertTrue(0 != expectedEy);
assertEquals(25, tracker.computeGandE_border(feature, 20, 22));
assertEquals(expectedGxx, tracker.Gxx, 1e-8);
assertEquals(expectedGxy, tracker.Gxy, 1e-8);
assertEquals(expectedGyy, tracker.Gyy, 1e-8);
assertEquals(25, tracker.computeGandE_border(feature, 21, 23));
assertEquals(expectedEx, tracker.Ex, 1e-8);
assertEquals(expectedEy, tracker.Ey, 1e-8);
}
Aggregations