use of boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BFrame in project BoofCV by lessthanoptimal.
the class MaxGeoKeyFrameManager method keepCurrentFrame.
/**
* Perform different checks that attempt to see if too much has changed. If too much has changed then the
* current keyframe should be kept so that new features can be spawned and starvation avoided.
*
* @return true if it should keep the current frame
*/
protected boolean keepCurrentFrame(VisOdomBundleAdjustment<?> sba) {
BFrame current = sba.frames.getTail();
CameraInfo camera = cameras.get(current.camera.index);
// Compute fraction of the image covered by tracks
coverage.reset(camera.maxFeaturesPerFrame, camera.imageWidth, camera.imageHeight);
for (int i = 0; i < activeTracks.size; i++) {
Point2D_F64 p = activeTracks.get(i).pixel;
coverage.markPixel((int) p.x, (int) p.y);
}
coverage.process();
return coverage.getFraction() < minimumCoverage;
}
use of boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BFrame in project BoofCV by lessthanoptimal.
the class MaxGeoKeyFrameManager method selectOldToDiscard.
/**
* Selects an older frame to discard. If a frame has zero features in common with the current frame it
* will be selected. After that it scores frames based on how many features it has in common with the other
* frames, excluding the current frame.
*
* @param totalDiscard How many need to be discarded
*/
protected void selectOldToDiscard(VisOdomBundleAdjustment<?> sba, int totalDiscard) {
if (totalDiscard <= 0 || sba.frames.size < 2)
return;
frameToIndex.clear();
for (int i = 0; i < sba.frames.size; i++) {
frameToIndex.put(sba.frames.get(i).id, i);
}
// Create a histogram showing how observations connect the frames
final int N = sba.frames.size;
histogram.reshape(N, N);
histogram.zero();
// Skip the last row since it's not needed
for (int frameIdxA = 0; frameIdxA < N - 1; frameIdxA++) {
BFrame frame = sba.frames.get(frameIdxA);
for (int trackIdx = 0; trackIdx < frame.tracks.size; trackIdx++) {
BTrack track = frame.tracks.get(trackIdx);
for (int obsIdx = 0; obsIdx < track.observations.size; obsIdx++) {
BObservation o = track.observations.get(obsIdx);
int frameIdxB = frameToIndex.get(o.frame.id);
if (frameIdxA == frameIdxB)
continue;
histogram.increment(frameIdxA, frameIdxB);
}
}
}
if (verbose != null)
histogram.print("%4d");
// See which keyframe the current frame has the best connection with
// Most of the time it will be the previous frame, but if that was experienced a lot of motion blur it might
// not be...
int bestFrame = histogram.maximumRowIdx(N - 1);
if (verbose != null)
verbose.println("Frame with best connection to current " + bestFrame);
// mark it so that it's skipped
histogram.set(bestFrame, bestFrame, Integer.MAX_VALUE);
for (int i = 0; i < totalDiscard; i++) {
// Select the frame with the worst connection to the bestFrame. The reason the bestFrame is used and not
// the current frame is that the current frame could be blurred too and might get discarded
int lowestCount = Integer.MAX_VALUE;
int worstIdx = -1;
// N-1 to avoid the current frame
for (int frameIdx = 0; frameIdx < N - 1; frameIdx++) {
int connection = histogram.get(frameIdx, bestFrame);
if (connection == Integer.MAX_VALUE)
continue;
// influence over the current frame's state and have no direct influence over bestFrame's state
if (connection == 0) {
if (verbose != null)
verbose.println("No connection index " + frameIdx);
lowestCount = 0;
worstIdx = frameIdx;
break;
}
if (connection < lowestCount) {
lowestCount = connection;
worstIdx = frameIdx;
}
}
if (verbose != null)
verbose.println("Worst index " + worstIdx + " count " + lowestCount);
discardKeyIndices.add(worstIdx);
// Mark the worst keyframe so it won't be selected again
histogram.set(worstIdx, bestFrame, Integer.MAX_VALUE);
}
}
Aggregations