use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestBinaryEllipseDetectorPixel method undistortContour_WithDistortion.
/**
* Undistort the image when distortion model is provided
*/
@Test
void undistortContour_WithDistortion() {
List<Point2D_I32> input = new ArrayList<>();
DogArray<Point2D_F64> output = new DogArray<>(Point2D_F64::new);
for (int i = 0; i < 10; i++) {
input.add(new Point2D_I32(i, i));
}
BinaryEllipseDetectorPixel alg = new BinaryEllipseDetectorPixel();
alg.setLensDistortion(new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 10.0f, 0)));
alg.undistortContour(input, output);
assertEquals(input.size(), output.size);
for (int i = 0; i < input.size(); i++) {
Point2D_I32 p = input.get(i);
assertEquals(p.x + 10, output.get(i).x, 1e-8);
assertEquals(p.y, output.get(i).y, 1e-8);
}
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class GenericFhEdgeWeightsChecks method basicTest.
@Test
void basicTest() {
T input = imageType.createImage(10, 12);
GImageMiscOps.fillUniform(input, rand, 0, 200);
FhEdgeWeights<T> alg = createAlg();
DogArray<Edge> edges = new DogArray<>(Edge::new);
alg.process(input, edges);
int[] hist = new int[input.width * input.height];
// see if the edges computed the expected weight
for (int i = 0; i < edges.size(); i++) {
Edge e = edges.get(i);
int indexA = e.indexA;
int indexB = e.indexB;
hist[indexA]++;
hist[indexB]++;
float expected = weight(input, indexA, indexB);
assertEquals(expected, e.weight(), 1e-4f);
}
// make sure each pixel was inspected
if (rule == ConnectRule.FOUR) {
for (int y = 0; y < input.height; y++) {
for (int x = 0; x < input.width; x++) {
if (x >= 1 && x < input.width - 1 && y >= 1 && y < input.height - 1)
assertEquals(hist[input.getIndex(x, y)], 4);
else if (x == 0 && y == 0)
assertEquals(hist[input.getIndex(x, y)], 2);
else if (x == input.width - 1 && y == 0)
assertEquals(hist[input.getIndex(x, y)], 2);
else if (x == input.width - 1 && y == input.height - 1)
assertEquals(hist[input.getIndex(x, y)], 2);
else if (x == 0 && y == input.height - 1)
assertEquals(hist[input.getIndex(x, y)], 2);
else {
assertEquals(hist[input.getIndex(x, y)], 3);
}
}
}
} else if (rule == ConnectRule.EIGHT) {
for (int y = 0; y < input.height; y++) {
for (int x = 0; x < input.width; x++) {
if (x >= 1 && x < input.width - 1 && y >= 1 && y < input.height - 1)
assertEquals(hist[input.getIndex(x, y)], 8);
else if (x == 0 && y == 0)
assertEquals(hist[input.getIndex(x, y)], 3);
else if (x == input.width - 1 && y == 0)
assertEquals(hist[input.getIndex(x, y)], 3);
else if (x == input.width - 1 && y == input.height - 1)
assertEquals(hist[input.getIndex(x, y)], 3);
else if (x == 0 && y == input.height - 1)
assertEquals(hist[input.getIndex(x, y)], 3);
else {
assertEquals(hist[input.getIndex(x, y)], 5);
}
}
}
} else {
throw new RuntimeException("Unknown rule");
}
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestMergeRegionMeanShift method basicAll.
@Test
void basicAll() {
MergeRegionMeanShift alg = new MergeRegionMeanShift(1, 1);
GrayS32 pixelToRegion = new GrayS32(4, 4);
pixelToRegion.data = new int[] { 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 1, 1, 0, 0, 3, 1 };
DogArray_I32 regionMemberCount = new DogArray_I32();
regionMemberCount.data = new int[] { 1, 2, 3, 4 };
regionMemberCount.size = 4;
DogArray<float[]> regionColor = createList(5, 1, 6, 4);
DogArray<Point2D_I32> modeLocation = new DogArray<>(Point2D_I32::new);
modeLocation.grow().setTo(0, 0);
modeLocation.grow().setTo(3, 3);
modeLocation.grow().setTo(0, 1);
modeLocation.grow().setTo(2, 3);
alg.process(pixelToRegion, regionMemberCount, regionColor, modeLocation);
GrayS32 expectedP2R = new GrayS32(4, 4);
expectedP2R.data = new int[] { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1 };
int[] expectedCount = new int[] { 4, 2, 4 };
for (int i = 0; i < expectedP2R.data.length; i++) assertEquals(expectedP2R.data[i], pixelToRegion.data[i]);
for (int i = 0; i < expectedCount.length; i++) assertEquals(expectedCount[i], regionMemberCount.data[i]);
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class PointCloudUtils_F64 method prune.
/**
* Prunes points from the point cloud if they have very few neighbors
*
* @param cloud Point cloud
* @param minNeighbors Minimum number of neighbors for it to not be pruned
* @param radius search distance for neighbors
*/
public static void prune(List<Point3D_F64> cloud, int minNeighbors, double radius) {
if (minNeighbors < 0)
throw new IllegalArgumentException("minNeighbors must be >= 0");
NearestNeighbor<Point3D_F64> nn = FactoryNearestNeighbor.kdtree(new KdTreePoint3D_F64());
NearestNeighbor.Search<Point3D_F64> search = nn.createSearch();
nn.setPoints(cloud, false);
DogArray<NnData<Point3D_F64>> results = new DogArray<>(NnData::new);
// It will always find itself
minNeighbors += 1;
// distance is Euclidean squared
radius *= radius;
for (int i = cloud.size() - 1; i >= 0; i--) {
search.findNearest(cloud.get(i), radius, minNeighbors, results);
if (results.size < minNeighbors) {
cloud.remove(i);
}
}
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class PointCloudUtils_F64 method filter.
/**
* Creates a new list of points while filtering out points
*/
public static DogArray<Point3dRgbI_F64> filter(AccessPointIndex<Point3D_F64> accessPoint, AccessColorIndex accessColor, int size, BoofLambdas.FilterInt filter, @Nullable DogArray<Point3dRgbI_F64> output) {
if (output == null)
output = new DogArray<>(Point3dRgbI_F64::new);
output.reset();
// Guess how much memory is needed
output.reserve(size / 5);
Point3dRgbI_F64 p = output.grow();
for (int pointIdx = 0; pointIdx < size; pointIdx++) {
if (!filter.keep(pointIdx))
continue;
accessPoint.getPoint(pointIdx, p);
p.rgb = accessColor.getRGB(pointIdx);
p = output.grow();
}
output.removeTail();
return output;
}
Aggregations