use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestSceneMergingOperations method findViewCounts.
@Test
void findViewCounts() {
var list = new DogArray<>(SceneCommonCounts::new, SceneCommonCounts::reset);
// First two calls should add elements. The third all look up the first one again
SceneCommonCounts found1 = SceneMergingOperations.findViewCounts(list, 5);
SceneCommonCounts found2 = SceneMergingOperations.findViewCounts(list, 6);
SceneCommonCounts found3 = SceneMergingOperations.findViewCounts(list, 5);
assertEquals(2, list.size);
assertSame(found1, found3);
assertEquals(5, found1.sceneIndex);
assertEquals(6, found2.sceneIndex);
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class CommonEpipolarScore3DChecks method createAssociations.
private List<AssociatedPair> createAssociations(boolean oneCamera, int N, @Nullable PlaneNormal3D_F64 plane, Se3_F64 view0_to_view1) {
List<Point3D_F64> feats3D;
if (plane != null) {
feats3D = UtilPoint3D_F64.random(plane, 0.5, N, rand);
} else {
feats3D = UtilPoint3D_F64.random(new Point3D_F64(0, 0, 1), -0.5, 0.5, N, rand);
}
var associated = new DogArray<>(AssociatedPair::new);
// If generated from one camera use the first camera for both views
CameraPinholeBrown intrinsic2 = oneCamera ? intrinsic1 : this.intrinsic2;
double sigma = 0.5;
for (int i = 0; i < feats3D.size(); i++) {
Point3D_F64 X = feats3D.get(i).copy();
AssociatedPair a = associated.grow();
if (X.z <= 0)
throw new RuntimeException("Point is behind camera! Pick a better scenario");
PerspectiveOps.renderPixel(intrinsic1, X, a.p1);
SePointOps_F64.transform(view0_to_view1, X, X);
if (X.z <= 0)
throw new RuntimeException("Point is behind camera! Pick a better scenario");
PerspectiveOps.renderPixel(intrinsic2, X, a.p2);
// add a little bit of noise so that it isn't perfect
a.p1.x += rand.nextGaussian() * sigma;
a.p1.y += rand.nextGaussian() * sigma;
a.p2.x += rand.nextGaussian() * sigma;
a.p2.y += rand.nextGaussian() * sigma;
}
return associated.toList();
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestEstimateViewUtils method configureSbaStructure.
/**
* Very simple test that just makes sure three views/cameras have been set as constant initially
*/
@Test
void configureSbaStructure() {
DogArray<AssociatedTriple> inliers = new DogArray<>(AssociatedTriple::new);
inliers.resize(95);
var alg = new EstimateViewUtils();
// configure internal data structures so that it won't blow up
alg.camera1 = new BundlePinholeSimplified();
alg.camera2 = new BundlePinholeSimplified();
alg.camera3 = new BundlePinholeSimplified();
alg.normalize1.setK(100, 100, 0, 100, 100).setDistortion(0.1, 0.1);
alg.normalize2.setK(100, 100, 0, 100, 100).setDistortion(0.1, 0.1);
alg.normalize3.setK(100, 100, 0, 100, 100).setDistortion(0.1, 0.1);
alg.usedThreeViewInliers.resize(40);
alg.configureSbaStructure(inliers.toList());
// Check the results to make sure stuff is marked as known
for (int i = 0; i < 3; i++) {
assertTrue(alg.metricSba.structure.cameras.get(i).known);
assertTrue(alg.metricSba.structure.motions.get(i).known);
}
assertEquals(40, alg.metricSba.structure.points.size);
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class SceneMergingOperations method computeSceneTransform.
/**
* Computes the transform between the two views in different scenes. This is done by computing the depth
* for all common image features. The depth is used to estimate the scale difference between the scenes.
* After that finding the SE3 transform is trivial.
*/
public boolean computeSceneTransform(LookUpSimilarImages dbSimilar, SceneWorkingGraph src, SceneWorkingGraph dst, SceneWorkingGraph.View selectedSrc, SceneWorkingGraph.View selectedDst, ScaleSe3_F64 src_to_dst) {
// Sanity check
BoofMiscOps.checkSame(selectedSrc.pview, selectedDst.pview);
if (verbose != null)
printInlierViews(selectedSrc, selectedDst);
// Get the set feature indexes for the selected view that were inliers in each scene
SceneWorkingGraph.InlierInfo inliersSrc = Objects.requireNonNull(selectedSrc.getBestInliers());
SceneWorkingGraph.InlierInfo inliersDst = Objects.requireNonNull(selectedDst.getBestInliers());
DogArray_I32 zeroSrcIdx = inliersSrc.observations.get(0);
DogArray_I32 zeroDstIdx = inliersDst.observations.get(0);
// Number of feature observations in this view
int numObservations = selectedSrc.pview.totalObservations;
// Find features in the target view that are common between the two scenes inlier feature sets
int numCommon = findCommonInliers(zeroSrcIdx, zeroDstIdx, numObservations, zeroFeatureToCommonIndex);
if (numCommon == 0)
return false;
// Load observation of common features in view[0]
SceneWorkingGraph.Camera cameraSrc = src.getViewCamera(selectedSrc);
loadViewZeroCommonObservations(dbSimilar, cameraSrc.prior, numCommon, selectedSrc.pview.id);
List<DogArray<Point2D_F64>> listViewPixelsSrc = getCommonFeaturePixelsViews(dbSimilar, src, inliersSrc);
List<DogArray<Point2D_F64>> listViewPixelsDst = getCommonFeaturePixelsViews(dbSimilar, dst, inliersDst);
// Load the extrinsics and convert the intrinsics into a usable format
loadExtrinsicsIntrinsics(src, inliersSrc, listWorldToViewSrc, listIntrinsicsSrc);
loadExtrinsicsIntrinsics(dst, inliersDst, listWorldToViewDst, listIntrinsicsDst);
if (verbose != null)
verbose.println("commonInliers.size=" + numCommon + " src.size=" + zeroSrcIdx.size + " dst.size=" + zeroDstIdx.size);
// Pass in everything to the scale resolving algorithm
resolveScale.initialize(zeroViewPixels.size);
resolveScale.setScene1((viewIdx, featureIdx, pixel) -> {
if (viewIdx == 0)
pixel.setTo(zeroViewPixels.get(featureIdx));
else
pixel.setTo(listViewPixelsSrc.get(viewIdx - 1).get(featureIdx));
}, listWorldToViewSrc, (List) listIntrinsicsSrc.toList());
resolveScale.setScene2((viewIdx, featureIdx, pixel) -> {
if (viewIdx == 0)
pixel.setTo(zeroViewPixels.get(featureIdx));
else
pixel.setTo(listViewPixelsDst.get(viewIdx - 1).get(featureIdx));
}, listWorldToViewDst, (List) listIntrinsicsDst.toList());
return resolveScale.process(src_to_dst);
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestSimilarImagesTrackThenMatch method simpleLoop.
/**
* Faking the inputs, see if it can attack all frames to the first frame when tracking fails
*/
@Test
void simpleLoop() {
int numViews = 6;
var alg = new SimilarImagesTrackThenMatch<>(new DummyDetector(), new AssociateDescriptionHashSets<>(FactoryAssociation.greedy(null, new ScoreAssociateEuclideanSq.F32())), new DummyRecognizerLoop(numViews), () -> new PackedTupleArray_F32(1));
// Remove any restriction on how many frames need to have past
alg.minimumRecognizeDistance = 0;
alg.initialize(10, 20);
// A dummy image
GrayU8 image = new GrayU8(10, 20);
// Create a set of tracks
int numTracks = 20;
DogArray<PointTrack> tracks = new DogArray<>(PointTrack::new);
for (int i = 0; i < numTracks; i++) {
PointTrack t = tracks.grow();
t.pixel.setTo(i, 21 * (i + 1));
t.featureId = i;
}
// the frame-to-frame tracker will fail but the recognizer will match everything to frame 0
for (int frameID = 0; frameID < numViews; frameID++) {
alg.processFrame(image, tracks.toList(), frameID);
for (int i = 0; i < tracks.size; i++) {
PointTrack t = tracks.get(i);
t.pixel.setTo((frameID + 1) * numTracks, 21 * (i + 1));
// this will prevent the tracker from matching frames
t.featureId = i + (frameID + 1) * numTracks;
}
}
// Has to be called after frame to frame tracking
alg.finishedTracking();
// Storage for association results
DogArray<AssociatedIndex> pairs = new DogArray<>(AssociatedIndex::new);
List<String> listImages = alg.getImageIDs();
List<String> listSimilar = new ArrayList<>();
// everything should be matched to the first frame
alg.findSimilar(listImages.get(0), null, listSimilar);
assertEquals(numViews - 1, listSimilar.size());
for (String similarID : listSimilar) {
assertTrue(alg.lookupAssociated(similarID, pairs));
assertEquals(numTracks, pairs.size);
}
// Other frames shouldn't be matched with each other
for (int frameIdx = 1; frameIdx < 6; frameIdx++) {
alg.findSimilar(listImages.get(frameIdx), null, listSimilar);
assertEquals(1, listSimilar.size());
}
}
Aggregations