use of boofcv.alg.structure.PairwiseImageGraph in project BoofCV by lessthanoptimal.
the class TestMultiViewIO method save_load_PairwiseImageGraph.
@Test
void save_load_PairwiseImageGraph() {
for (int trial = 0; trial < 20; trial++) {
PairwiseImageGraph expected = createPairwise();
var output = new ByteArrayOutputStream();
MultiViewIO.save(expected, new OutputStreamWriter(output, UTF_8));
var input = new ByteArrayInputStream(output.toByteArray());
PairwiseImageGraph found = MultiViewIO.load(new InputStreamReader(input, UTF_8), (PairwiseImageGraph) null);
checkIdentical(expected, found);
}
}
use of boofcv.alg.structure.PairwiseImageGraph in project BoofCV by lessthanoptimal.
the class ViewPairwiseImageGraphApp method openFile.
@Override
public void openFile(File file, boolean addToRecent) {
// Save the path just in case it wants to reload it later
inputFilePath = systemToUnix(file.getPath());
// update recent items menu
if (addToRecent) {
String path = inputFilePath;
BoofSwingUtil.invokeNowOrLater(() -> {
BoofSwingUtil.addToRecentFiles(ViewPairwiseImageGraphApp.this, selectRecentFileName(BoofMiscOps.asList(file)), BoofMiscOps.asList(path));
updateRecentItems();
});
}
stopAllInputProcessing();
threadPool.execute(() -> {
setMenuBarEnabled(false);
Objects.requireNonNull(inputFilePath);
System.out.println("Loading pairwise graph at: " + inputFilePath);
graph = MultiViewIO.load(inputFilePath, (PairwiseImageGraph) null);
db = MultiViewIO.loadSimilarImages(new File(new File(inputFilePath).getParentFile(), "similar.yaml").getPath());
smartFindImagePath();
SwingUtilities.invokeLater(() -> {
loadPairwiseIntoGui();
setMenuBarEnabled(true);
});
});
}
use of boofcv.alg.structure.PairwiseImageGraph 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)));
}
use of boofcv.alg.structure.PairwiseImageGraph in project BoofCV by lessthanoptimal.
the class TestEstimateViewKnownCalibration method simpleKnownScenario.
/**
* Generate a known scene and pass in everything but the location of the 3rd view. Make sure
* it's able to estimate it. A couple of outliers will be added and checked to make sure they are removed.
*/
@Test
void simpleKnownScenario() {
var db = new MockLookupSimilarImagesRealistic().pathLine(5, 0.3, 1.5, 2);
PairwiseImageGraph pairwise = db.createPairwise();
SceneWorkingGraph scene = db.createWorkingGraph(pairwise);
var pairwiseUtils = new PairwiseGraphUtils();
pairwiseUtils.dbSimilar = db;
pairwiseUtils.dbCams = db.createLookUpCams();
// Specify the 3-views it should use. viewC = target that's estimated
pairwiseUtils.seed = pairwise.nodes.get(1);
pairwiseUtils.viewB = pairwise.nodes.get(2);
pairwiseUtils.viewC = pairwise.nodes.get(3);
// Use truth for the priors
pairwiseUtils.priorCamA.setTo(db.intrinsic);
pairwiseUtils.priorCamB.setTo(db.intrinsic);
pairwiseUtils.priorCamC.setTo(db.intrinsic);
// Specifies the observations for the 3-views
SceneWorkingGraph.View wviewA = scene.listViews.get(1);
db.addInlierInfo(pairwise, wviewA, 2, 3);
// Create the triplet of pixel observations using the "inlier" set created above
SceneWorkingGraph.InlierInfo info = Objects.requireNonNull(wviewA.getBestInliers());
int numInliers = info.getInlierCount();
pairwiseUtils.inlierIdx.resize(numInliers, (idx) -> idx);
assertTrue(numInliers > 20);
for (int i = 0; i < numInliers; i++) {
int obs1 = info.observations.get(0).get(i);
int obs2 = info.observations.get(1).get(i);
int obs3 = info.observations.get(2).get(i);
AssociatedTriple a = new AssociatedTriple();
a.p1.setTo(db.views.get(1).observations.get(obs1).pixel);
a.p2.setTo(db.views.get(2).observations.get(obs2).pixel);
a.p3.setTo(db.views.get(3).observations.get(obs3).pixel);
pairwiseUtils.inliersThreeView.add(a);
}
// Pixels must be centered at (0,0)
for (int i = 0; i < numInliers; i++) {
AssociatedTriple a = pairwiseUtils.inliersThreeView.get(i);
a.p1.x -= db.intrinsic.cx;
a.p1.y -= db.intrinsic.cy;
a.p2.x -= db.intrinsic.cx;
a.p2.y -= db.intrinsic.cy;
a.p3.x -= db.intrinsic.cx;
a.p3.y -= db.intrinsic.cy;
}
var alg = new EstimateViewKnownCalibration();
// alg.setVerbose(System.out, BoofMiscOps.hashSet(BoofVerbose.RECURSIVE));
var solution = new MetricExpandByOneView.Solution();
assertTrue(alg.process(pairwiseUtils, scene, solution));
// See if the transforms are the same
Se3_F64 expected = scene.listViews.get(3).world_to_view;
assertEquals(0.0, expected.T.distance(solution.world_to_target.T), 1e-2);
// NOTE: The tolerance does seem a bit high for noise free observations. Could there be numeric issues?
}
Aggregations