use of boofcv.alg.similar.ConfigSimilarImagesTrackThenMatch in project BoofCV by lessthanoptimal.
the class ExampleMultiViewSparseReconstruction method similarImagesFromSequence.
/**
* For a pairwise graph to be constructed, image feature relationships between frames are needed. For a video
* sequence, KLT is an easy and fast way to do this. However, KLT will not "close the loop", and it will
* not realize you're back at the initial location. Typically this results in a noticeable miss alignment.
*/
private void similarImagesFromSequence() {
System.out.println("----------------------------------------------------------------------------");
System.out.println("### Creating Similar Images from an ordered set of images");
// Configure the KLT tracker
ConfigPointTracker configTracker = FactorySceneRecognition.createDefaultTrackerConfig();
PointTracker<GrayU8> tracker = FactoryPointTracker.tracker(configTracker, GrayU8.class, null);
var activeTracks = new ArrayList<PointTrack>();
var config = new ConfigSimilarImagesTrackThenMatch();
final var dbSimilar = FactorySceneReconstruction.createTrackThenMatch(config, ImageType.SB_U8);
dbSimilar.setVerbose(System.out, BoofMiscOps.hashSet(BoofVerbose.RECURSIVE));
// Track features across the entire sequence and save the results
BoofMiscOps.profile(() -> {
boolean first = true;
for (int frameId = 0; frameId < imageFiles.size(); frameId++) {
String filePath = imageFiles.get(frameId);
GrayU8 frame = UtilImageIO.loadImage(filePath, GrayU8.class);
Objects.requireNonNull(frame, "Failed to load image");
if (first) {
first = false;
dbSimilar.initialize(frame.width, frame.height);
dbCams.addCameraCanonical(frame.width, frame.height, 60.0);
}
tracker.process(frame);
int activeCount = tracker.getTotalActive();
int droppedCount = tracker.getDroppedTracks(null).size();
tracker.spawnTracks();
tracker.getActiveTracks(activeTracks);
dbSimilar.processFrame(frame, activeTracks, tracker.getFrameID());
String id = frameId + "";
System.out.println("frame id = " + id + " active=" + activeCount + " dropped=" + droppedCount);
// Everything maps to the same camera
dbCams.addView(id, 0);
}
dbSimilar.finishedTracking();
}, "Finding Similar");
this.dbSimilar = dbSimilar;
}
Aggregations