Merge pull request #30249 from tandede/fix/checkrange-float16

Fix checkRange for new 5.x data types  🤖🤖🤖
This commit is contained in:
Zhewen Tan
2026-10-16 19:06:36 +08:00
committed by GitHub
parent 5e581286e4
commit 37040df206
2 changed files with 131 additions and 2 deletions

View File

@@ -1168,6 +1168,30 @@ check_range_function check_range_functions[] =
&checkIntegerRange<CV_32S>
};
template<typename T>
static void checkTypedRange(Mat& src, Point& badPt, double minVal, double maxVal)
{
int loc = 0;
int cn = src.channels();
Size size = getContinuousSize2D(src, cn);
const T* isrc = src.ptr<T>();
size_t step = src.step / sizeof(isrc[0]);
for( ; badPt.x < 0 && size.height--; loc += size.width, isrc += step )
{
for( int i = 0; i < size.width; i++ )
{
double val = (double)isrc[i];
if( !(val >= minVal && val < maxVal) )
{
int pixelId = (loc + i) / cn;
badPt = Point(pixelId % src.cols, pixelId / src.cols);
break;
}
}
}
}
bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double maxVal)
{
CV_INSTRUMENT_REGION();
@@ -1208,7 +1232,15 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma
int cn = src.channels();
Size size = getContinuousSize2D(src, cn);
if( depth == CV_32F )
if( depth == CV_16F )
{
checkTypedRange<hfloat>(src, badPt, minVal, maxVal);
}
else if( depth == CV_16BF )
{
checkTypedRange<bfloat>(src, badPt, minVal, maxVal);
}
else if( depth == CV_32F )
{
Cv32suf a, b;
int ia, ib;
@@ -1237,7 +1269,7 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma
}
}
}
else
else if( depth == CV_64F )
{
Cv64suf a, b;
int64 ia, ib;
@@ -1266,6 +1298,26 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma
}
}
}
else if( depth == CV_Bool )
{
checkTypedRange<uchar>(src, badPt, minVal, maxVal);
}
else if( depth == CV_32U )
{
checkTypedRange<uint32_t>(src, badPt, minVal, maxVal);
}
else if( depth == CV_64U )
{
checkTypedRange<uint64_t>(src, badPt, minVal, maxVal);
}
else if( depth == CV_64S )
{
checkTypedRange<int64_t>(src, badPt, minVal, maxVal);
}
else
{
CV_Error(Error::StsUnsupportedFormat, "Unsupported matrix depth in checkRange");
}
}
if( badPt.x >= 0 )