1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

imgproc: accept CV_Bool masks in distanceTransform

cv::Mat_<bool>::depth() returns CV_Bool in 5.0 where it returned CV_8U in
4.x, so distanceTransform started rejecting boolean masks. CV_Bool is a
1-byte type whose values are only zero-tested here, so accept it wherever
a CV_8UC1 mask was previously accepted, matching the 4.x behaviour and the
4->5 migration guide.

Relaxes the type checks on all four reachable paths: the public wrapper,
distanceTransform_L1_8U, trueDistTrans (DIST_MASK_PRECISE) and
distanceATS_L1_8u (CV_8U output).

Closes #29596
This commit is contained in:
Trishanth Mellimi
2026-07-24 23:48:00 +05:30
parent 864f9594ad
commit b41cda2b93
2 changed files with 53 additions and 4 deletions
+8 -4
View File
@@ -830,7 +830,7 @@ trueDistTrans( const Mat& src, Mat& dst )
CV_Assert( src.size() == dst.size() );
CV_Assert( src.type() == CV_8UC1 && dst.type() == CV_32FC1 );
CV_Assert( (src.type() == CV_8UC1 || src.type() == CV_BoolC1) && dst.type() == CV_32FC1 );
int i, m = src.rows, n = src.cols;
cv::AutoBuffer<uchar> _buf(std::max(m*2*sizeof(int) + (m*3+1)*sizeof(int), n*2*sizeof(float)));
@@ -886,7 +886,7 @@ distanceATS_L1_8u( const Mat& src, Mat& dst )
int srcstep = (int)src.step;
int dststep = (int)dst.step;
CV_Assert( src.type() == CV_8UC1 && dst.type() == CV_8UC1 );
CV_Assert( (src.type() == CV_8UC1 || src.type() == CV_BoolC1) && dst.type() == CV_8UC1 );
CV_Assert( src.size() == dst.size() );
////////////////////// forward scan ////////////////////////
@@ -957,7 +957,9 @@ static void distanceTransform_L1_8U(InputArray _src, OutputArray _dst)
Mat src = _src.getMat();
CV_Assert( src.type() == CV_8UC1);
// CV_Bool is a 1-byte mask type (added in 5.0) and is only ever zero-tested
// here, so accept it wherever a CV_8UC1 mask was accepted. See #29596.
CV_Assert( src.type() == CV_8UC1 || src.type() == CV_BoolC1);
_dst.create( src.size(), CV_8UC1);
Mat dst = _dst.getMat();
@@ -978,7 +980,9 @@ void cv::distanceTransform( InputArray _src, OutputArray _dst, OutputArray _labe
Mat src = _src.getMat(), labels;
bool need_labels = _labels.needed();
CV_Assert( src.type() == CV_8UC1);
// CV_Bool is a 1-byte mask type (added in 5.0) and is only ever zero-tested
// here, so accept it wherever a CV_8UC1 mask was accepted. See #29596.
CV_Assert( src.type() == CV_8UC1 || src.type() == CV_BoolC1);
_dst.create( src.size(), CV_32F);
Mat dst = _dst.getMat();