Skip to content

Commit

Permalink
[keyframe] Do not fail before the end of the feed when frames are mis…
Browse files Browse the repository at this point in the history
…sing

When a frame was missing in a VideoFeed, the behaviour used to be to skip
it and try to read the next one. If the next one was missing as well, the
whole process would stop and fail, with the assumption that the feed was
corrupted.

Instead of that, we now keep on skipping the frame and attempting to read
the next one until a valid frame is found or there is no frame left to
read. Dummy scores are still pushed for every frame that is missing.
  • Loading branch information
cbentejac committed Aug 18, 2023
1 parent b51a519 commit 5f6289d
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/aliceVision/keyframe/KeyframeSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,21 @@ bool KeyframeSelector::computeScores(const std::size_t rescaledWidthSharpness, c
// Read image for sharpness and rescale it if requested
currentMatSharpness = readImage(feed, rescaledWidthSharpness);
} catch (const std::invalid_argument& ex) {
// currentFrame + 1 = currently evaluated frame with indexing starting at 1, for display reasons
// currentFrame + 2 = next frame to evaluate with indexing starting at 1, for display reasons
ALICEVISION_LOG_WARNING("Invalid or missing frame " << currentFrame + 1
<< ", attempting to read frame " << currentFrame + 2 << ".");
bool success = feed.goToFrame(++currentFrame);
if (success) {
// Will throw an exception if next frame is also invalid
currentMatSharpness = readImage(feed, rescaledWidthSharpness);
// If no exception has been thrown, push dummy scores for the frame that was skipped
bool success = false;
while (!success && currentFrame < nbFrames) {
// currentFrame + 1 = currently evaluated frame with indexing starting at 1, for display reasons
// currentFrame + 2 = next frame to evaluate with indexing starting at 1, for display reasons
ALICEVISION_LOG_WARNING("Invalid or missing frame " << currentFrame + 1
<< ", attempting to read frame " << currentFrame + 2 << ".");
success = feed.goToFrame(++currentFrame);
if (success) {
// Will throw an exception if next frame is also invalid
currentMatSharpness = readImage(feed, rescaledWidthSharpness);
}
// Push dummy scores for the frame that was skipped
_sharpnessScores.push_back(-1.f);
_flowScores.push_back(-1.f);
} else
ALICEVISION_THROW_ERROR("Could not go to frame " << currentFrame + 1
<< " either. The feed might be corrupted.");
}
}
}

Expand Down

0 comments on commit 5f6289d

Please sign in to comment.