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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations