Numerical setImage / operator() tests for each feature evaluator#25
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The existing feature tests verified construction,
initand featurecounts, but never evaluated a feature on a real image. This MR adds
8 numerical tests that drive the full pipeline of every concrete
evaluator (
CvHaarEvaluator,CvLBPEvaluator,CvHOGEvaluator):The tests use synthetic images (constant patches and step edges) and
assert closed-form invariants that hold regardless of which feature
index corresponds to which geometric layout, so they remain meaningful
without hard-coding implementation-specific feature ordering.
Library line coverage rises from 42.4% → 44.4%, driven primarily by
HOGfeatures.cppgoing from 28% → 77% (the entire integralhistogram + feature evaluation path was previously untested).
Changes
traincascade/test/test_features.cpp8 new test cases appended, all following the existing Arrange / Act /
Assert pattern with comments per step:
normfactor = 0→operator()short-circuits to0.0ffor every featuresetImage)cval→ all 8>= cvalcomparisons true → result0xFF = 255<255, two-sample isolation by index> 0.001fguard →0.0ffor every variablenumFeatures × N_BINS × N_CELLSvars, vertical edge produces ≥1 nonzeroInner loops use a fail-fast accumulator into a single
CHECKso thedoctest assertion counter stays sane (291 total, not 170k+).
Why these invariants?
Each evaluator has a property that holds for any uniform input:
On a constant patch the variance is zero, the implementation
short-circuits, and every feature returns exactly 0. Any non-zero
output on a textured image therefore proves
setImageactuallypopulated the integral image and
operator()is using it.Equal sums make every comparison
true, producing the maximum bitpattern
0xFF. A non-0xFFoutput on a textured image proves thepipeline is working end-to-end.
bin is zero and the implementation's
res > 0.001fguard returns0.0feverywhere. A non-zero output on an edge image provesintegralHistogram, normalization andFeature::calcare wired up.Using closed-form invariants instead of golden values keeps the tests
robust against benign reordering of generated features.
Test results
Coverage impact (
traincascade/lib/)Per-file gains:
HOGfeatures.cppHOGfeatures.h(inlineoperator()/Feature::calc)haarfeatures.cpplbpfeatures.h(inlineFeature::calc)The HOG jump is the key win: previously no test ever called
CvHOGEvaluator::setImage, so the entireintegralHistogram,gradient-bin accumulation and normalization paths were dark. They are
now covered on both the zero-gradient short-circuit path and the normal
evaluation path.
Risks / Notes
cv::Matimages — no filesystem I/O, no testfixtures.
Checklist
ctest --output-on-failure)