use of boofcv.core.image.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
public void testSubImages() {
ImageMiscOps.fillUniform(image, rand, 0, 100);
GradientSobel.process(image, derivX, derivY, new ImageBorder1D_F32(BorderIndex1D_Extend.class));
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);
assertTrue(faultA == faultB);
if (x == 4)
System.out.println();
if (faultA == KltTrackFault.SUCCESS) {
assertTrue(x + " " + y, featureA.x == featureB.x);
assertTrue(x + " " + y, featureA.y == featureB.y);
}
}
}
}
use of boofcv.core.image.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
public void testTracking_border2() {
ImageMiscOps.fillUniform(image, rand, 0, 100);
GradientSobel.process(image, derivX, derivY, new ImageBorder1D_F32(BorderIndex1D_Extend.class));
KltTracker<GrayF32, GrayF32> tracker = createDefaultTracker();
tracker.setImage(image, derivX, derivY);
KltFeature feature = new KltFeature(3);
// just outside the image
feature.setPosition(imageWidth - 3 - 1 + 2, imageHeight - 3 - 1 + 1);
tracker.setDescription(feature);
// now fuly inside the image
feature.setPosition(imageWidth - 3 - 1, imageHeight - 3 - 1);
// see if it got sucked back
assertTrue(tracker.track(feature) == KltTrackFault.SUCCESS);
assertEquals(imageWidth - 3 - 1 + 2, feature.x, 0.01);
assertEquals(imageHeight - 3 - 1 + 1, feature.y, 0.01);
// same thing but with the top left image
feature.setPosition(2, 1);
tracker.setDescription(feature);
// put it fully inside the image
feature.setPosition(3, 3);
// see if it got sucked back
assertTrue(tracker.track(feature) == KltTrackFault.SUCCESS);
assertEquals(2, feature.x, 0.01);
assertEquals(1, feature.y, 0.01);
}
use of boofcv.core.image.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.
the class TestKltTracker method setDescription_compare.
/**
* Compares the border algorithm to the inner algorithm
*/
@Test
public void setDescription_compare() {
ImageMiscOps.fillUniform(image, rand, 0, 100);
GradientSobel.process(image, derivX, derivY, new ImageBorder1D_F32(BorderIndex1D_Extend.class));
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);
tracker.internalSetDescriptionBorder(featureB);
for (int i = 0; i < featureA.desc.data.length; i++) {
assertTrue(featureA.desc.data[i] == featureB.desc.data[i]);
assertTrue(featureA.derivX.data[i] == featureB.derivX.data[i]);
assertTrue(featureA.derivY.data[i] == featureB.derivY.data[i]);
}
}
use of boofcv.core.image.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.
the class TestFactoryConvolve method convolve2D_F32.
@Test
public void convolve2D_F32() {
Kernel2D_F32 kernel = FactoryKernel.random2D_F32(kernelWidth, radius, 1, 6, rand);
ConvolveInterface<GrayF32, GrayF32> conv;
GrayF32 input = new GrayF32(width, height);
GrayF32 found = new GrayF32(width, height);
GrayF32 expected = new GrayF32(width, height);
ImageMiscOps.fillUniform(input, rand, 0, 5);
// CHECK NO BORDER
conv = FactoryConvolve.convolve(kernel, GrayF32.class, GrayF32.class, BorderType.SKIP);
conv.process(input, found);
ConvolveImageNoBorder.convolve(kernel, input, expected);
BoofTesting.assertEquals(expected, found, 1e-4f);
// CHECK EXTENDED
conv = FactoryConvolve.convolve(kernel, GrayF32.class, GrayF32.class, BorderType.EXTENDED);
conv.process(input, found);
ConvolveImage.convolve(kernel, input, expected, new ImageBorder1D_F32(BorderIndex1D_Extend.class));
BoofTesting.assertEquals(expected, found, 1e-4f);
// CHECK NORMALIZED
conv = FactoryConvolve.convolve(kernel, GrayF32.class, GrayF32.class, BorderType.NORMALIZED);
conv.process(input, found);
ConvolveImageNormalized.convolve(kernel, input, expected);
BoofTesting.assertEquals(expected, found, 1e-4f);
}
use of boofcv.core.image.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.
the class TestFactoryConvolve method convolve1D_F32.
@Test
public void convolve1D_F32() {
Kernel1D_F32 kernel = FactoryKernel.random1D_F32(kernelWidth, radius, 1, 6, rand);
ConvolveInterface<GrayF32, GrayF32> conv;
GrayF32 input = new GrayF32(width, height);
GrayF32 found = new GrayF32(width, height);
GrayF32 expected = new GrayF32(width, height);
ImageMiscOps.fillUniform(input, rand, 0, 5);
// CHECK NO BORDER
conv = FactoryConvolve.convolve(kernel, input.imageType, found.imageType, BorderType.SKIP, true);
conv.process(input, found);
ConvolveImageNoBorder.horizontal(kernel, input, expected);
BoofTesting.assertEquals(expected, found, 1e-4f);
// CHECK EXTENDED
conv = FactoryConvolve.convolve(kernel, input.imageType, found.imageType, BorderType.EXTENDED, true);
conv.process(input, found);
ConvolveImage.horizontal(kernel, input, expected, new ImageBorder1D_F32(BorderIndex1D_Extend.class));
BoofTesting.assertEquals(expected, found, 1e-4f);
// CHECK NORMALIZED
conv = FactoryConvolve.convolve(kernel, input.imageType, found.imageType, BorderType.NORMALIZED, true);
conv.process(input, found);
ConvolveImageNormalized.horizontal(kernel, input, expected);
BoofTesting.assertEquals(expected, found, 1e-4f);
}
Aggregations