Search in sources :

Example 21 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TestTldFernClassifier method learnFernNoise.

@Test
public void learnFernNoise() {
    TldFernClassifier<GrayU8> alg = createAlg();
    alg.setImage(input);
    alg.learnFernNoise(true, new ImageRectangle(10, 12, 30, 45));
    for (int i = 0; i < alg.managers.length; i++) {
        int found = countNum(true, alg.managers[i]);
        assertEquals(1 + numLearnRandom, found);
        assertEquals(0, countNum(false, alg.managers[i]));
    }
    assertTrue(alg.getMaxP() > 0);
    assertTrue(alg.getMaxN() == 0);
    alg.learnFernNoise(false, new ImageRectangle(10, 12, 30, 45));
    for (int i = 0; i < alg.managers.length; i++) {
        assertEquals(1 + numLearnRandom, countNum(true, alg.managers[i]));
        assertEquals(1 + numLearnRandom, countNum(false, alg.managers[i]));
    }
    assertTrue(alg.getMaxP() > 0);
    assertTrue(alg.getMaxN() > 0);
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 22 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TestTldFernClassifier method learnFern.

@Test
public void learnFern() {
    TldFernClassifier<GrayU8> alg = createAlg();
    alg.setImage(input);
    alg.learnFern(true, new ImageRectangle(10, 12, 30, 45));
    for (int i = 0; i < alg.managers.length; i++) {
        assertEquals(1, countNum(true, alg.managers[i]));
        assertEquals(0, countNum(false, alg.managers[i]));
    }
    assertTrue(alg.getMaxP() > 0);
    assertTrue(alg.getMaxN() == 0);
    alg.learnFern(false, new ImageRectangle(10, 12, 30, 45));
    for (int i = 0; i < alg.managers.length; i++) {
        assertEquals(1, countNum(true, alg.managers[i]));
        assertEquals(1, countNum(false, alg.managers[i]));
    }
    assertTrue(alg.getMaxP() > 0);
    assertTrue(alg.getMaxN() > 0);
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 23 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TestTldFernClassifier method computeFernValueRand.

@Test
public void computeFernValueRand() {
    TldFernDescription fern = new TldFernDescription(rand, 10);
    ImageRectangle r = new ImageRectangle(2, 20, 12, 28);
    float cx = r.x0 + r.getWidth() / 2.0f;
    float cy = r.x0 + r.getHeight() / 2.0f;
    float w = r.getWidth();
    float h = r.getHeight();
    boolean[] expected = new boolean[10];
    for (int i = 0; i < 10; i++) {
        Point2D_F32 a = fern.pairs[i].a;
        Point2D_F32 b = fern.pairs[i].b;
        float valA = interpolate.get(cx + a.x * w, cy + a.y * h);
        float valB = interpolate.get(cx + b.x * w, cy + b.y * h);
        expected[9 - i] = valA < valB;
    }
    TldFernClassifier<GrayU8> alg = createAlg();
    alg.setImage(input);
    int found = alg.computeFernValueRand(cx, cy, w, h, fern);
    int numDiff = 0;
    for (int i = 0; i < 10; i++) {
        if (expected[i] != (((found >> i) & 0x0001) == 1)) {
            numDiff++;
        }
    }
    assertTrue(numDiff != 0);
    assertTrue(numDiff < 10);
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle) Point2D_F32(georegression.struct.point.Point2D_F32) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 24 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TestTldTemplateMatching method reset.

@Test
public void reset() {
    TldTemplateMatching alg = new TldTemplateMatching(interpolate);
    alg.setImage(input);
    alg.addDescriptor(true, new ImageRectangle(10, 12, 45, 22));
    alg.addDescriptor(false, new ImageRectangle(23, 12, 55, 22));
    assertEquals(1, alg.getTemplatePositive().size());
    assertEquals(1, alg.getTemplateNegative().size());
    alg.reset();
    assertEquals(0, alg.getTemplatePositive().size());
    assertEquals(0, alg.getTemplateNegative().size());
    assertEquals(2, alg.unused.size());
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle) Test(org.junit.Test)

Example 25 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TestTldTemplateMatching method computeConfidence.

@Test
public void computeConfidence() {
    TldTemplateMatching alg = new TldTemplateMatching(interpolate);
    alg.setImage(input);
    alg.addDescriptor(true, new ImageRectangle(2, 3, 17, 18));
    alg.addDescriptor(false, new ImageRectangle(20, 32, 40, 60));
    assertEquals(1, alg.computeConfidence(new ImageRectangle(2, 3, 17, 18)), 1e-8);
    assertEquals(0, alg.computeConfidence(new ImageRectangle(20, 32, 40, 60)), 1e-8);
    double found = alg.computeConfidence(new ImageRectangle(14, 30, 20, 50));
    assertTrue(found >= 0 && found <= 1);
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle) Test(org.junit.Test)

Aggregations

ImageRectangle (boofcv.struct.ImageRectangle)43 Test (org.junit.Test)15 GrayU8 (boofcv.struct.image.GrayU8)10 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)3 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)3 GImageGray (boofcv.core.image.GImageGray)3 ImageGray (boofcv.struct.image.ImageGray)3 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2 GrayS32 (boofcv.struct.image.GrayS32)2 Point2D_F32 (georegression.struct.point.Point2D_F32)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Point2D_I32 (georegression.struct.point.Point2D_I32)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)1 FastQueue (org.ddogleg.struct.FastQueue)1 GrowQueue_F64 (org.ddogleg.struct.GrowQueue_F64)1