use of boofcv.alg.structure.SceneWorkingGraph in project BoofCV by lessthanoptimal.
the class TestExpandByOneView method createListOfValid.
@Test
void createListOfValid() {
var working = new SceneWorkingGraph();
var graph = new PairwiseImageGraph();
SceneWorkingGraph.Camera camera = working.addCamera(2);
View seed = graph.createNode("A");
for (int i = 0; i < 10; i++) {
View viewI = graph.createNode("" + i);
Motion mA = graph.connect(seed, viewI);
// is3D and being known are at different frequencies and will only intersect twice
mA.is3D = i % 2 == 0;
if (i % 3 == 0)
working.addView(viewI, camera);
}
var alg = new ChildProjectiveExpandByOneView();
alg.workGraph = working;
List<Motion> valid = new ArrayList<>();
alg.createListOfValid(seed, valid);
assertEquals(2, valid.size());
}
use of boofcv.alg.structure.SceneWorkingGraph in project BoofCV by lessthanoptimal.
the class TestMultiViewIO method checkIdentical.
private void checkIdentical(SceneWorkingGraph a, SceneWorkingGraph b) {
assertEquals(a.listCameras.size(), b.listCameras.size());
assertEquals(a.listViews.size(), b.listViews.size());
assertEquals(a.views.size(), b.views.size());
for (int cameraIdx = 0; cameraIdx < a.listCameras.size(); cameraIdx++) {
SceneWorkingGraph.Camera ca = a.listCameras.get(cameraIdx);
SceneWorkingGraph.Camera cb = b.listCameras.get(cameraIdx);
assertEquals(ca.indexDB, cb.indexDB);
assertEquals(ca.localIndex, cb.localIndex);
assertEquals(ca.prior.fx, cb.prior.fx);
assertEquals(ca.intrinsic.f, cb.intrinsic.f);
}
for (int viewIdx = 0; viewIdx < a.listViews.size(); viewIdx++) {
SceneWorkingGraph.View va = a.listViews.get(viewIdx);
SceneWorkingGraph.View vb = b.listViews.get(viewIdx);
assertSame(va, a.views.get(va.pview.id));
assertSame(vb, b.views.get(vb.pview.id));
assertEquals(0.0, va.world_to_view.T.distance(vb.world_to_view.T), UtilEjml.EPS);
assertTrue(MatrixFeatures_DDRM.isEquals(va.world_to_view.R, vb.world_to_view.R, UtilEjml.EPS));
assertEquals(va.inliers.size, vb.inliers.size);
for (int inlierInfo = 0; inlierInfo < va.inliers.size; inlierInfo++) {
SceneWorkingGraph.InlierInfo infoa = va.inliers.get(inlierInfo);
SceneWorkingGraph.InlierInfo infob = vb.inliers.get(inlierInfo);
assertEquals(infoa.observations.size, infob.observations.size);
final int numViews = infoa.views.size;
for (int i = 0; i < numViews; i++) {
assertEquals(infoa.views.get(i).id, infob.views.get(i).id);
DogArray_I32 oa = infoa.observations.get(i);
DogArray_I32 ob = infob.observations.get(i);
assertEquals(oa.size, ob.size);
oa.forIdx((idx, v) -> assertEquals(v, ob.get(idx)));
}
}
}
}
use of boofcv.alg.structure.SceneWorkingGraph in project BoofCV by lessthanoptimal.
the class TestMultiViewIO method save_load_SceneWorkingGraph.
@Test
void save_load_SceneWorkingGraph() {
for (int trial = 0; trial < 20; trial++) {
PairwiseImageGraph pairwise = createPairwise();
SceneWorkingGraph expected = createWorkingGraph(pairwise);
var output = new ByteArrayOutputStream();
MultiViewIO.save(expected, new OutputStreamWriter(output, UTF_8));
var input = new ByteArrayInputStream(output.toByteArray());
SceneWorkingGraph found = MultiViewIO.load(new InputStreamReader(input, UTF_8), pairwise, null);
checkIdentical(expected, found);
}
}
use of boofcv.alg.structure.SceneWorkingGraph in project BoofCV by lessthanoptimal.
the class TestMultiViewIO method createWorkingGraph.
private SceneWorkingGraph createWorkingGraph(PairwiseImageGraph pairwise) {
var ret = new SceneWorkingGraph();
// Add a camera for each view
for (int cameraIdx = 0; cameraIdx < pairwise.nodes.size; cameraIdx++) {
SceneWorkingGraph.Camera c = ret.addCamera(cameraIdx);
c.intrinsic.f = rand.nextDouble();
c.intrinsic.k1 = rand.nextDouble();
c.intrinsic.k2 = rand.nextDouble();
c.prior.fx = rand.nextDouble();
}
pairwise.nodes.forIdx((i, v) -> ret.addView(v, ret.listCameras.get(i)));
var candidates = DogArray_I32.range(0, pairwise.nodes.size);
ret.listViews.forEach(v -> {
SpecialEuclideanOps_F64.eulerXyz(rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), v.world_to_view);
RandomMatrices_DDRM.fillUniform(v.projective, rand);
PrimitiveArrays.shuffle(candidates.data, 0, candidates.size, rand);
v.inliers.resetResize(2);
for (int infoIdx = 0; infoIdx < v.inliers.size; infoIdx++) {
SceneWorkingGraph.InlierInfo inlier = v.inliers.get(infoIdx);
int numViews = rand.nextInt(Math.min(5, candidates.size));
int numObs = rand.nextInt(20) + 1;
inlier.views.resize(numViews);
inlier.observations.resize(numViews);
for (int i = 0; i < numViews; i++) {
inlier.views.set(i, pairwise.nodes.get(candidates.get(i)));
DogArray_I32 obs = inlier.observations.get(i);
obs.resize(numObs);
for (int j = 0; j < numObs; j++) {
obs.data[j] = rand.nextInt();
}
}
}
});
return ret;
}
use of boofcv.alg.structure.SceneWorkingGraph in project BoofCV by lessthanoptimal.
the class TestExpandByOneView method selectTwoConnections.
/**
* Creates a more complex scenario and sees if it selects the correct two views
*/
@Test
void selectTwoConnections() {
var working = new SceneWorkingGraph();
var graph = new PairwiseImageGraph();
SceneWorkingGraph.Camera camera = working.addCamera(2);
View seed = graph.createNode("A");
for (int i = 0; i < 6; i++) {
View viewI = graph.createNode("" + i);
// make sure src/dst is handled correctly
Motion mA = i % 2 == 0 ? graph.connect(seed, viewI) : graph.connect(viewI, seed);
// All have the same score so that the connections between the other two is what decides the winner
mA.score3D = 2.0;
mA.is3D = true;
working.addView(viewI, camera);
}
View viewB = seed.connection(1);
View viewC = seed.connection(2);
View viewD = seed.connection(3);
Motion connBC = graph.connect(viewB, viewC);
Motion connBD = graph.connect(viewD, viewB);
connBD.is3D = connBC.is3D = true;
connBC.score3D = 1.2;
// this is the more desirable connection
connBD.score3D = 1.3;
var alg = new ChildProjectiveExpandByOneView();
alg.workGraph = working;
var found = new ArrayList<Motion>();
assertTrue(alg.selectTwoConnections(seed, found));
assertTrue(found.contains(seed.connections.get(1)));
assertTrue(found.contains(seed.connections.get(3)));
}
Aggregations