Add integration tests for CvCascadeClassifier::train#23
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
Extend the test suite with end-to-end integration tests that exercise the
real cascade training pipeline (
CvCascadeClassifier::train) against thesample resources bundled in
traincascade/res/. These complement theexisting unit tests by covering the wiring between
CvCascadeImageReader,the feature evaluators and the boosted-tree trainer through one full stage.
Coverage of the
traincascade/lib/library jumped from 9.6% to41.1% of lines (and 76.0% of functions) thanks to these tests.
Changes
traincascade/test/test_integration.cpp(new)Five integration tests, all strictly following the Arrange / Act / Assert
pattern with explicit comments per step:
cascade.xmlfeatureType=LBP,boostType=GENTLEcascade.xmlfeatureType=HAAR,mode=BASICbaseFormatSave=trueproduces a non-empty cascade.vecfile →trainreturnsfalsetrainthrowsparams.xmlcannot be openedHelpers introduced:
makeUniqueOutputDir(tag)— per-test isolation under/tmp/traincascade_it/<timestamp>_<random>_<tag>/.stageResources(workDir)— copiesbarcode.vec, synthesizes a256×128 deterministic-texture negative image, and writes a
bg.txtwith an absolute path so the negative reader resolves regardless of
the current working directory.
traincascade/CMakeLists.txttest/test_integration.cppto thetest_traincascadetarget.TRAINCASCADE_RES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/res"so tests areCWD-independent.
Why a synthetic negative image?
The bundled
res/bg.pngis 32×32, butbarcode.vechard-codes a 75×32detection window. The negative reader cannot slide a 75×32 window over a
32×32 source; the resulting
cv::Matviolates_step >= minstepandtraining aborts. The tests therefore generate a 256×128 grayscale image
in-memory (deterministic pattern, no extra resource file) and reference it
from a freshly-generated
bg.txt.Test results
CI parity verified locally on Linux (g++ 13.3 + clang 18). The runtime is
within an acceptable budget for the existing GitHub Actions Test step on
ubuntu,macosandwindowsworkflows.Coverage impact
Modules now ≥ 85% line coverage:
o_cvboostparams.cpp,o_cvdtreeparams.cpp,o_cvstatmodel.cpp,o_utils.cpp,o_cvboost.cpp,lbpfeatures.cpp,imagestorage.cpp,features.cpp.Risks / Notes
behind in the repo. Cleanup is intentionally not done so failing
runs leave artifacts available for inspection.
maxWeakCount=10,maxDepth=1configuration to keep CI runtime under ~20s.
CORE/ALLmodes remain uncovered — flagged asa follow-up.
Checklist
ctest --output-on-failure)