Repository navigation
video: accept CV_Bool masks in findTransformECC (#25895) - #29681
Conversation
cv::Mat_<bool>::depth() returns CV_Bool in 5.0, where it returned CV_8U in 4.x. findTransformECC does not type check inputMask, it passes it straight to cv::threshold(), which has no CV_Bool branch, so a boolean mask fails with: thresh.cpp:1607: error: (-210:Unsupported format or combination of formats) in function 'cv::threshold' Widen a CV_Bool mask to CV_8U before the threshold call. The subsequent binarization then treats any non-zero entry as selected, matching the CV_8U mask semantics. CV_8U masks are unaffected, and inputMask is used nowhere else in the function. Added a regression test that aligns a checkerboard against a translated copy with a Mat_<bool> mask and with the equivalent CV_8UC1 mask, and requires the same warp matrix from both.
|
@asmorkalov Done in 953a178, thanks. Exactly as you described: the mask was widened to CV_8U, pushed through cv::threshold() with the same 0 and 1 values it already had, then converted to 0.0 and 1.0. CV_Bool now converts directly to CV_32F in one step, which is what your suggestion asked for. This is safe because conversion out of CV_Bool already normalises every non-zero entry to exactly 1 (DEF_CVTBOOL2_FUNC in modules/core/src/convert.simd.hpp emits I also dropped the now-stale comment above the test, since it described the widening step that no longer exists. Rebuilt and reran opencv_test_video: 115 of 116 pass, including Video_ECC_BoolMask and all 8 existing ECC accuracy fixtures that exercise the CV_8U path. The single failure is vittrack.accuracy_vittrack, which needs a dnn ONNX model that this build does not include, and it is unrelated to this change. Negative test reconfirmed, the bool test throws |
Address review feedback: the previous patch widened the bool mask to CV_8U, ran cv::threshold() over values that were already 0 and 1, then converted the result to float. Conversion out of CV_Bool already maps every non-zero entry to exactly 1, so a single convertTo() to CV_32F produces the same matrix in one pass instead of three. The CV_8U path is unchanged.
7f37131 to
953a178
Compare
Problem
cv::Mat_<bool>::depth()returnsCV_Boolin 5.0, where it returnedCV_8Uin 4.x.findTransformECCWithMaskdoes not type checkinputMaskat all. It passes it straight tocv::threshold()atecc.cpp:483, andcv::threshold()dispatches only onCV_8U,CV_16S,CV_16U,CV_32FandCV_64F, erroring otherwise. So a boolean mask fails with an error pointing at imgproc rather than at the mask:Fix
Widen a
CV_Boolmask toCV_8Ubefore thethresholdcall. The existingTHRESH_BINARYstep then treats any non-zero entry as selected, which matches theCV_8Umask semantics.inputMaskis used nowhere else in the function (only atecc.cpp:476for theempty()check and at:483), so this is the single point that needed handling.CV_8Umasks take an unchanged path.Note that
cv::computeECCalready accepts a boolean mask, because it only forwards the mask tocountNonZero,meanStdDevandsubtract, which all handleCV_Bool. This change makesfindTransformECCconsistent with it.Test
Video_ECC_BoolMask.matches_uchar_maskbuilds a blurred checkerboard, warps it by a known translation, then runsfindTransformECCwithMOTION_TRANSLATIONusing aMat_<bool>mask and the equivalentCV_8UC1mask, and requires the same warp matrix from both.Verified locally on 5.x: the test fails without the change (with the error above) and passes with it. The full
*ECC*set, 15 tests, passes withOPENCV_TEST_DATA_PATHset. No test data needed for the new test itself, it is synthetic.Part of #25895, and follows the same approach as #29580, #29597 and #29622.
Pull Request Readiness Checklist
Patch to opencv_extra has the same branch name.