Add round-trip serialization tests for *Params types#24
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 cascade trainer persists every stage's configuration to
params.xmlvia
cv::FileStorage, then reads it back when resuming training oremitting the final cascade. This MR locks down that contract with a new
test file that round-trips each
*Paramstype through an in-memoryFileStorageand verifies the result matches the source — plus a focusedset of negative cases for the documented validation paths.
Library line coverage rises from 41.1% → 42.4%, with notable gains
in
features.cpp(85% → 96%),haarfeatures.cpp(67% → 73%) andboost.cpp(63% → 70%). No production code changes.Changes
traincascade/test/test_serialization.cpp(new)19 doctest test cases, all strictly following the Arrange / Act /
Assert pattern with comments per step. Two small helpers wrap each
instance under a named section since the
write/readmethods emitchildren directly without their own enclosing node:
Both use
FileStorage::MEMORY— no temp files, no I/O.CvCascadeParamswidth; unknown feature type stringCvFeatureParamsCvHaarFeatureParamsBASIC/CORE/ALLround-trips; unknown mode; missing modeCvLBPFeatureParamsCvCascadeBoostParamsGENTLE/DISCRETE/REAL+LOGITround-trips; out-of-rangeminHitRatethrows; unknown boost type throwsCMakeLists.txt
test/test_serialization.cppto thetest_traincascadetarget.Library bug surfaced (not fixed in this MR)
CvCascadeBoostParams::CvCascadeBoostParams(int _boostType, ...)writesboost_type = cv::ml::Boost::GENTLEafter delegating to the baseconstructor, so the
_boostTypeargument is effectively ignored. TheDISCRETEandREAL/LOGITround-trip tests work around this bysetting
boost_typedirectly after construction; the workaround isdocumented in test comments. Recommended follow-up: drop the override or
honor the argument.
Test results
Coverage impact (lib)
Per-file gains:
The new tests fully exercise
CvFeatureParams::read/write(includingthe empty-node guard), all three
CvHaarFeatureParamsmodes plus theirtwo failure branches, and both
CV_Errorpaths insideCvCascadeBoostParams::read(unknown boost type and out-of-rangevalues).
Risks / Notes
FileStorage— no filesystem state, no testfixtures to clean up.
unaffected.
boost_typeissue notedabove is documented in test comments and tracked separately.
Checklist
ctest --output-on-failure)