Search in sources :

Example 6 with ImageBorder1D_F32

use of boofcv.core.image.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.

the class TestKltTracker method compare_computeGandE_border_toInsideImage.

@Test
public void compare_computeGandE_border_toInsideImage() {
    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(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);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ImageBorder1D_F32(boofcv.core.image.border.ImageBorder1D_F32) BorderIndex1D_Extend(boofcv.core.image.border.BorderIndex1D_Extend) Test(org.junit.Test)

Example 7 with ImageBorder1D_F32

use of boofcv.core.image.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.

the class TestKltTracker method testTracking_border1.

/**
 * Create a description of a feature next to the border then place the feature just outside of the image
 * and see if it can track to its original position.
 */
@Test
public void testTracking_border1() {
    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);
    // lower right border, but fully inside the image
    feature.setPosition(imageWidth - 4, imageHeight - 4);
    tracker.setDescription(feature);
    // put it partially outside the image
    feature.setPosition(imageWidth - 2, imageHeight - 1);
    // see if it got sucked back
    assertTrue(tracker.track(feature) == KltTrackFault.SUCCESS);
    assertEquals(imageWidth - 4, feature.x, 0.01);
    assertEquals(imageHeight - 4, feature.y, 0.01);
    // same thing but with the top left image
    feature.setPosition(3, 3);
    tracker.setDescription(feature);
    // put it partially outside the image
    feature.setPosition(1, 2);
    // see if it got sucked back
    assertTrue(tracker.track(feature) == KltTrackFault.SUCCESS);
    assertEquals(3, feature.x, 0.01);
    assertEquals(3, feature.y, 0.01);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ImageBorder1D_F32(boofcv.core.image.border.ImageBorder1D_F32) BorderIndex1D_Extend(boofcv.core.image.border.BorderIndex1D_Extend) Test(org.junit.Test)

Example 8 with ImageBorder1D_F32

use of boofcv.core.image.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, cornerX, cornerY, 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.class));
    }
}
Also used : ImageBorder1D_F32(boofcv.core.image.border.ImageBorder1D_F32) BorderIndex1D_Extend(boofcv.core.image.border.BorderIndex1D_Extend)

Example 9 with ImageBorder1D_F32

use of boofcv.core.image.border.ImageBorder1D_F32 in project BoofCV by lessthanoptimal.

the class StandardGradientChecks method testSecondDerivative.

/**
 * The XY and YX second derivatives should be indential
 */
private void testSecondDerivative(Method m1, Method m2) {
    Class[] params = m1.getParameterTypes();
    ImageGray input = GeneralizedImageOps.createSingleBand(params[0], width, height);
    ImageGray derivX = GeneralizedImageOps.createSingleBand(params[1], width, height);
    ImageGray derivY = GeneralizedImageOps.createSingleBand(params[2], width, height);
    ImageGray derivXX = GeneralizedImageOps.createSingleBand(params[1], width, height);
    ImageGray derivYY = GeneralizedImageOps.createSingleBand(params[2], width, height);
    ImageGray derivXY = GeneralizedImageOps.createSingleBand(params[1], width, height);
    ImageGray derivYX = GeneralizedImageOps.createSingleBand(params[1], width, height);
    GImageMiscOps.fillUniform(input, rand, 0, 40);
    Object border;
    if (params[3] == ImageBorder_F32.class) {
        border = new ImageBorder1D_F32(BorderIndex1D_Wrap.class);
    } else {
        border = new ImageBorder1D_S32(BorderIndex1D_Wrap.class);
    }
    try {
        m1.invoke(null, input, derivX, derivY, border);
        m2.invoke(null, derivX, derivXX, derivXY, border);
        m2.invoke(null, derivY, derivYX, derivYY, border);
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
    // BoofTesting.printDiff(derivXY,derivYX);
    BoofTesting.assertEquals(derivXY, derivYX, 1e-3f);
}
Also used : BorderIndex1D_Wrap(boofcv.core.image.border.BorderIndex1D_Wrap) ImageBorder1D_F32(boofcv.core.image.border.ImageBorder1D_F32) ImageGray(boofcv.struct.image.ImageGray) ImageBorder1D_S32(boofcv.core.image.border.ImageBorder1D_S32) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ImageBorder1D_F32 (boofcv.core.image.border.ImageBorder1D_F32)9 BorderIndex1D_Extend (boofcv.core.image.border.BorderIndex1D_Extend)8 Test (org.junit.Test)7 GrayF32 (boofcv.struct.image.GrayF32)5 BorderIndex1D_Wrap (boofcv.core.image.border.BorderIndex1D_Wrap)1 ImageBorder1D_S32 (boofcv.core.image.border.ImageBorder1D_S32)1 Kernel1D_F32 (boofcv.struct.convolve.Kernel1D_F32)1 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)1 ImageGray (boofcv.struct.image.ImageGray)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1