use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TextureGrayTrackerObjectRectangleTests method convexFill.
public static void convexFill(Polygon2D_I32 poly, GrayU8 image, double value) {
int minX = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
for (int i = 0; i < poly.size(); i++) {
Point2D_I32 p = poly.vertexes.data[i];
if (p.y < minY) {
minY = p.y;
} else if (p.y > maxY) {
maxY = p.y;
}
if (p.x < minX) {
minX = p.x;
} else if (p.x > maxX) {
maxX = p.x;
}
}
ImageRectangle bounds = new ImageRectangle(minX, minY, maxX, maxY);
BoofMiscOps.boundRectangleInside(image, bounds);
Point2D_F64 p = new Point2D_F64();
Polygon2D_F64 poly64 = new Polygon2D_F64(4);
for (int i = 0; i < 4; i++) poly64.vertexes.data[i].set(poly.vertexes.data[i].x, poly.vertexes.data[i].y);
for (int y = bounds.y0; y < bounds.y1; y++) {
p.y = y;
for (int x = bounds.x0; x < bounds.x1; x++) {
p.x = x;
if (Intersection2D_F64.containConvex(poly64, p)) {
GeneralizedImageOps.set(image, x, y, value);
}
}
}
}
use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TestTldDetection method selectBestRegionsFern_smaller.
/**
* See if the case where there are fewer than the maximum number of regions is handled correctly
*/
@Test
public void selectBestRegionsFern_smaller() {
TldDetection<GrayU8> alg = new TldDetection<>();
alg.config = new TldParameters();
alg.config.maximumCascadeConsider = 20;
// all 10 should be accepted
for (int i = 0; i < 10; i++) {
alg.fernInfo.grow();
alg.fernInfo.get(i).r = new ImageRectangle(i, i, i, i);
alg.fernInfo.get(i).sumP = 20;
alg.fernInfo.get(i).sumN = 6;
}
alg.selectBestRegionsFern(200, 200);
assertEquals(10, alg.fernRegions.size());
}
use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TestTldDetection method computeTemplateConfidence.
@Test
public void computeTemplateConfidence() {
TldDetection<GrayU8> alg = new TldDetection<>();
alg.config = new TldParameters();
alg.config.confidenceThresholdUpper = 0.6;
alg.template = new HelperTemplate();
for (int i = 0; i < 4; i++) {
alg.fernRegions.add(new ImageRectangle(i, i, i, i));
}
alg.computeTemplateConfidence();
assertEquals(3, alg.candidateDetections.size());
for (int i = 0; i < 3; i++) {
TldRegion r = alg.candidateDetections.get(i);
assertEquals(0, r.connections);
assertTrue(r.confidence > 0.6);
assertTrue(r.rect.x0 != 0);
}
}
use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TestTldDetection method selectBestRegionsFern_larger.
/**
* See if the case where there are more than the maximum number of regions is handled correctly
*/
@Test
public void selectBestRegionsFern_larger() {
TldDetection<GrayU8> alg = new TldDetection<>();
alg.config = new TldParameters();
alg.config.maximumCascadeConsider = 20;
// all 10 should be accepted
for (int i = 0; i < 30; i++) {
alg.fernInfo.grow();
alg.fernInfo.get(i).r = new ImageRectangle(i, i, i, i);
alg.fernInfo.get(i).sumP = 50 - i;
alg.fernInfo.get(i).sumN = 6;
}
alg.selectBestRegionsFern(200, 200);
assertEquals(20, alg.fernRegions.size());
// should contain all the best ones
for (int i = 0; i < 20; i++) {
assertTrue(alg.fernRegions.contains(alg.fernInfo.get(i).r));
}
}
use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TestTldFernClassifier method computeFernValue.
@Test
public void computeFernValue() {
TldFernDescription fern = new TldFernDescription(rand, 10);
ImageRectangle r = new ImageRectangle(2, 20, 12, 28);
float cx = r.x0 + (r.getWidth() - 1) / 2.0f;
float cy = r.x0 + (r.getHeight() - 1) / 2.0f;
float w = r.getWidth() - 1;
float h = r.getHeight() - 1;
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.computeFernValue(cx, cy, r.getWidth(), r.getHeight(), fern);
for (int i = 0; i < 10; i++) {
assertTrue(expected[i] == (((found >> i) & 0x0001) == 1));
}
}
Aggregations