use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class PruneStructureFromSceneMetric method pruneViews.
/**
* Removes views with less than or equal to 'count' features visible. Observations of features
* in removed views are also removed. Views which are parents (after children than can be removed have been
* removed) will remain since they are needed for the correct transform.
*
* @param count Prune if less than or equal to this many features
* @return true if the graph has been modified
*/
public boolean pruneViews(int count) {
DogArray_I32 removeIdx = new DogArray_I32();
Set<SceneStructureMetric.View> parents = new HashSet<>();
// chain of views needs to be removed they will be removed
for (int viewId = structure.views.size - 1; viewId >= 0; viewId--) {
SceneObservations.View oview = observations.views.data[viewId];
SceneStructureMetric.View sview = structure.views.data[viewId];
// See if has enough observations to not prune or is a parent and can't be pruned
if (oview.size() > count || parents.contains(sview)) {
// mark it's parent as a parent
if (sview.parent != null)
parents.add(sview.parent);
continue;
}
removeIdx.add(viewId);
// Go through list of points and remove this view from them
for (int pointIdx = 0; pointIdx < oview.point.size; pointIdx++) {
int pointId = oview.getPointId(pointIdx);
int viewIdx = structure.points.data[pointId].views.indexOf(viewId);
if (viewIdx < 0)
throw new RuntimeException("Bug in structure. view has point but point doesn't have view");
structure.points.data[pointId].views.remove(viewIdx);
}
}
if (removeIdx.isEmpty())
return false;
// Remove the views
structure.views.remove(removeIdx.data, 0, removeIdx.size, null);
observations.views.remove(removeIdx.data, 0, removeIdx.size, null);
return true;
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class PruneStructureFromSceneProjective method prunePoints.
/**
* Prunes Points/features with less than 'count' observations. Observations of the points are also removed.
*
* Call {@link #pruneViews(int)} to ensure that all views have points in view
*
* @param count Minimum number of observations
*/
public boolean prunePoints(int count) {
// create a lookup table from old to new point indexes
int[] oldToNew = new int[structure.points.size];
// list of remaining points
DogArray_I32 removeIdx = new DogArray_I32();
// List<SceneStructureProjective.Point> remainingP = new ArrayList<>();
for (int pointIdx = 0; pointIdx < structure.points.size; pointIdx++) {
SceneStructureCommon.Point sp = structure.points.data[pointIdx];
if (sp.views.size < count) {
removeIdx.add(pointIdx);
// remove observations of this point from each view
for (int i = 0; i < sp.views.size; i++) {
int viewIdx = sp.views.data[i];
SceneObservations.View ov = observations.views.get(viewIdx);
int localIdx = ov.point.indexOf(pointIdx);
if (localIdx == -1)
throw new RuntimeException("Point not in view's observation!?");
ov.remove(localIdx);
}
} else {
oldToNew[pointIdx] = pointIdx - removeIdx.size();
}
}
// if all of them are still remaining nothing changed
if (removeIdx.size == 0)
return false;
// update point references
for (int viewIdx = 0; viewIdx < structure.views.size; viewIdx++) {
SceneObservations.View so = observations.views.get(viewIdx);
for (int i = 0; i < so.point.size; i++) {
so.point.data[i] = oldToNew[so.point.data[i]];
}
}
// Remove the pruned points
structure.removePoints(removeIdx);
return true;
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestSceneStructureCommon method removePoints.
@Test
void removePoints() {
MockSceneStructureCommon structure = new MockSceneStructureCommon(false);
structure.homogenous = false;
structure.pointSize = 3;
List<Point> original = new ArrayList<>();
for (int i = 0; i < 20; i++) {
original.add(structure.points.grow());
}
DogArray_I32 which = new DogArray_I32();
which.add(2);
which.add(5);
structure.removePoints(which);
assertEquals(18, structure.points.size);
assertSame(original.get(0), structure.points.data[0]);
assertSame(original.get(3), structure.points.data[2]);
assertSame(original.get(4), structure.points.data[3]);
assertSame(original.get(7), structure.points.data[5]);
assertSame(original.get(19), structure.points.data[17]);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class CommonGenerateMetricCameraTripleChecks method checkScene.
private void checkScene() {
ModelGeneratorViews<MetricCameraTriple, AssociatedTriple, ElevateViewInfo> alg = createGenerator();
assertEquals(3, alg.getNumberOfViews());
for (int i = 0; i < 3; i++) {
alg.setView(i, new ElevateViewInfo(800, 600, i));
}
assertTrue(alg.getMinimumPoints() > 0);
var found = new MetricCameraTriple();
List<AssociatedTriple> selected = new ArrayList<>();
DogArray_I32 indexes = DogArray_I32.range(0, numFeatures);
int countSuccess = 0;
for (int trial = 0; trial < totalTrials; trial++) {
// Randomly select different points each trial
PrimitiveArrays.shuffle(indexes.data, 0, numFeatures, rand);
selected.clear();
for (int i = 0; i < alg.getMinimumPoints() + extraObservations; i++) {
selected.add(observations3.get(indexes.get(i)));
}
// Compute the model
if (!alg.generate(selected, found)) {
continue;
}
countSuccess++;
// System.out.println("Trial = "+trial);
// Check results
checkEquals(cameraA, found.view1);
checkEquals(cameraB, found.view2);
checkEquals(cameraC, found.view3);
BoofTesting.assertEqualsToScaleS(truthView_1_to_i(1), found.view_1_to_2, 1e-2, 1e-3);
BoofTesting.assertEqualsToScaleS(truthView_1_to_i(2), found.view_1_to_3, 1e-2, 1e-3);
}
// System.out.println("Passed "+countSuccess+" / "+totalTrials);
assertTrue(minimumFractionSuccess * totalTrials <= countSuccess, "Failed " + (totalTrials - countSuccess) + " min " + (minimumFractionSuccess * totalTrials - countSuccess));
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestPointCloudUtils_F64 method prune_color.
@Test
void prune_color() {
List<Point3D_F64> list = new ArrayList<>();
DogArray_I32 rgb = new DogArray_I32();
for (int i = 0; i < 100; i++) {
list.add(new Point3D_F64(i * 0.1, 0, 0));
rgb.add(i);
}
PointCloudUtils_F64.prune(list, rgb, 3, 0.31);
assertEquals(100, list.size());
assertEquals(100, rgb.size());
// end points should be pruned
PointCloudUtils_F64.prune(list, rgb, 3, 0.28);
assertEquals(98, list.size());
assertEquals(98, rgb.size());
assertEquals(1, rgb.get(0));
assertEquals(97, rgb.get(96));
}
Aggregations