use of org.ddogleg.struct.FastArray in project BoofCV by lessthanoptimal.
the class TestAssociateNearestNeighbor_ST method various.
/**
* Several tests combined into one
*/
@Test
void various() {
Dummy<TupleDesc_F64> nn = new Dummy<>();
// src = assoc[i] where src is the index of the source feature and i is the index of the dst feature
nn.assoc = new int[] { 2, 0, 1, -1, 4, -1, -1, 2, 2, 1 };
AssociateNearestNeighbor_ST<TupleDesc_F64> alg = new AssociateNearestNeighbor_ST<>(nn, TupleDesc_F64.class);
FastArray<TupleDesc_F64> src = new FastArray<>(TupleDesc_F64.class);
FastArray<TupleDesc_F64> dst = new FastArray<>(TupleDesc_F64.class);
for (int i = 0; i < 5; i++) {
src.add(new TupleDesc_F64(10));
}
for (int i = 0; i < 10; i++) {
dst.add(new TupleDesc_F64(10));
}
alg.setSource(src);
alg.setDestination(dst);
alg.associate();
DogArray<AssociatedIndex> matches = alg.getMatches();
assertEquals(7, matches.size);
for (int i = 0, count = 0; i < nn.assoc.length; i++) {
if (nn.assoc[i] != -1) {
int source = nn.assoc[i];
assertEquals(source, matches.get(count).src);
assertEquals(i, matches.get(count).dst);
count++;
}
}
DogArray_I32 unassoc = alg.getUnassociatedSource();
assertEquals(1, unassoc.size);
assertEquals(3, unassoc.get(0));
unassoc = alg.getUnassociatedDestination();
assertEquals(3, unassoc.size);
assertEquals(3, unassoc.get(0));
assertEquals(5, unassoc.get(1));
assertEquals(6, unassoc.get(2));
}
use of org.ddogleg.struct.FastArray in project BoofCV by lessthanoptimal.
the class TestFeatureSelectUniformBest method checkAcknowledgePrior.
void checkAcknowledgePrior(boolean positive) {
int width = 30;
int height = 20;
// One detected feature in each cell
QueueCorner prior = new QueueCorner();
QueueCorner detected = new QueueCorner();
int cellSize = 10;
for (int y = 0; y < height; y += cellSize) {
for (int x = 0; x < width; x += cellSize) {
detected.grow().setTo(x + 2, y + 2);
}
}
// add two prior features to the top row
for (int x = 0; x < width; x += cellSize) {
prior.grow().setTo(x + 2, 2);
prior.grow().setTo(x + 2, 2);
}
var found = new FastArray<>(Point2D_I16.class);
FeatureSelectUniformBest<Point2D_I16> alg = createAlgorithm();
// make it easy to know the cell size
alg.configUniform = new HackedConfig(cellSize);
// Since there is a prior feature in every cell and 6 features were requested nothing should be returned
// since the prior features already constributed to the spread
alg.select(intensity, -1, -1, positive, prior, detected, 3, found);
assertEquals(3, found.size);
// the found features should all be in the bottom row since it gives preference to cells without priors
for (int x = 0, idx = 0; x < width; x += cellSize, idx++) {
assertEquals(x + 2, found.get(idx).x);
assertEquals(12, found.get(idx).y);
}
// We now request two and 6 of the detected features should be returned
alg.select(intensity, -1, -1, positive, prior, detected, 6, found);
assertEquals(6, found.size);
}
use of org.ddogleg.struct.FastArray in project BoofCV by lessthanoptimal.
the class TestFeatureSelectUniform method everyCellHasPrior.
/**
* Every cell has a prior in it. make sure it doesn't get messed up.
*/
@Test
void everyCellHasPrior() {
int width = 30;
int height = 20;
// One detected feature in each cell and two priors
QueueCorner prior = new QueueCorner();
QueueCorner detected = new QueueCorner();
int cellSize = 10;
for (int y = 0; y < height; y += cellSize) {
for (int x = 0; x < width; x += cellSize) {
detected.grow().setTo(x + 2, y + 2);
prior.grow().setTo(x + 2, y + 2);
prior.grow().setTo(x + 1, y + 1);
}
}
var found = new FastArray<>(Point2D_I16.class);
FeatureSelectUniform<Point2D_I16> alg = createAlgorithm();
// make it easy to know the cell size
alg.configUniform = new HackedConfig(cellSize);
// a bug earlier aborted because the total count didn't change when every cell had a prior in it
alg.select(width, height, prior, detected, 6, found);
assertEquals(6, found.size);
}
use of org.ddogleg.struct.FastArray in project BoofCV by lessthanoptimal.
the class TestProjectiveToMetricCameraDualQuadratic method averageCommonCameras.
/**
* Have some cameras be duplicated and others not. See if it averages correctly
*/
@Test
void averageCommonCameras() {
List<ElevateViewInfo> views = new ArrayList<>();
views.add(new ElevateViewInfo(300, 400, 1));
views.add(new ElevateViewInfo(300, 400, 0));
views.add(new ElevateViewInfo(300, 400, 0));
views.add(new ElevateViewInfo(300, 400, 2));
var solutions = new FastArray<>(Intrinsic.class);
for (int i = 0; i < 4; i++) {
Intrinsic cam = new Intrinsic();
cam.fx = 100 + i;
cam.fy = 200 + i;
cam.skew = 400 + i;
solutions.add(cam);
}
var selfcalib = new SelfCalibrationLinearDualQuadratic(1.0);
var alg = new ProjectiveToMetricCameraDualQuadratic(selfcalib);
// process
alg.averageCommonCameras(views, solutions, 3);
// check results
assertEquals(3, alg.cameraCounts.size);
assertEquals(3, alg.workCameras.size);
// see if it counted the cameras correctly
assertEquals(2, alg.cameraCounts.get(0));
assertEquals(1, alg.cameraCounts.get(1));
assertEquals(1, alg.cameraCounts.get(2));
// See if the values are as epected
CameraPinhole cam0 = alg.workCameras.get(0);
CameraPinhole cam1 = alg.workCameras.get(1);
CameraPinhole cam2 = alg.workCameras.get(2);
assertEquals(101.5, cam0.fx, UtilEjml.TEST_F64);
assertEquals(201.5, cam0.fy, UtilEjml.TEST_F64);
assertEquals(401.5, cam0.skew, UtilEjml.TEST_F64);
assertEquals(100, cam1.fx, UtilEjml.TEST_F64);
assertEquals(200, cam1.fy, UtilEjml.TEST_F64);
assertEquals(400, cam1.skew, UtilEjml.TEST_F64);
assertEquals(103, cam2.fx, UtilEjml.TEST_F64);
assertEquals(203, cam2.fy, UtilEjml.TEST_F64);
assertEquals(403, cam2.skew, UtilEjml.TEST_F64);
}
use of org.ddogleg.struct.FastArray in project BoofCV by lessthanoptimal.
the class SerializeFieldsYamlBase method deserializeFastAccess.
private void deserializeFastAccess(Object parent, Map<String, Object> state, String key, Field f) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
// See if the list is empty and there's nothing to do
List listOfStates = (List) state.get(key);
if (listOfStates.isEmpty())
return;
// See if we are dealing with a regular array or DogArray
if (FastArray.class.isAssignableFrom(f.get(parent).getClass())) {
FastArray<Object> plist = (FastArray<Object>) f.get(parent);
Class<?> itemType = plist.type;
boolean basic = itemType.isEnum() || itemType.isPrimitive() || itemType.getName().equals("java.lang.String");
// deserialize each element and add it to the list
plist.reset();
for (int i = 0; i < listOfStates.size(); i++) {
Object value = listOfStates.get(i);
if (basic) {
// since numeric values are stored as objects this should work too. Not tested.
if (itemType.isEnum())
plist.add(Enum.valueOf((Class) itemType, (String) value));
else
plist.add(value);
} else {
Object dst = itemType.getConstructor().newInstance();
deserialize(dst, (Map) value);
plist.add(dst);
}
}
} else {
DogArray<Object> plist = (DogArray<Object>) f.get(parent);
// predeclare all the required elements
plist.resetResize(listOfStates.size());
// deserialize each element and add it to the list
for (int i = 0; i < listOfStates.size(); i++) {
Object value = listOfStates.get(i);
Object dst = plist.get(i);
deserialize(dst, (Map) value);
}
}
}
Aggregations