mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Merge pull request #11706 from take1014:setTo_Nan_10507
* setTo_#10507 * setTo_Nan_10507 * setTo: update check / test for NaNs
This commit is contained in:
parent
ff3d4d8b7f
commit
4fe648b15c
@ -463,9 +463,14 @@ static bool ipp_Mat_setTo_Mat(Mat &dst, Mat &_val, Mat &mask)
|
||||
return false;
|
||||
|
||||
if (dst.depth() == CV_32F)
|
||||
{
|
||||
for (int i = 0; i < (int)(_val.total()); i++)
|
||||
if (_val.at<double>(i) < iwTypeGetMin(ipp32f) || _val.at<double>(i) > iwTypeGetMax(ipp32f))
|
||||
{
|
||||
float v = (float)(_val.at<double>(i)); // cast to float
|
||||
if (cvIsNaN(v) || cvIsInf(v)) // accept finite numbers only
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(dst.dims <= 2)
|
||||
{
|
||||
|
@ -1612,6 +1612,32 @@ TEST(Mat, regression_7873_mat_vector_initialize)
|
||||
ASSERT_EQ(2, sub_mat.size[2]);
|
||||
}
|
||||
|
||||
TEST(Mat, regression_10507_mat_setTo)
|
||||
{
|
||||
Size sz(6, 4);
|
||||
Mat test_mask(sz, CV_8UC1, cv::Scalar::all(255));
|
||||
test_mask.at<uchar>(1,0) = 0;
|
||||
test_mask.at<uchar>(0,1) = 0;
|
||||
for (int cn = 1; cn <= 4; cn++)
|
||||
{
|
||||
cv::Mat A(sz, CV_MAKE_TYPE(CV_32F, cn), cv::Scalar::all(5));
|
||||
A.setTo(cv::Scalar::all(std::numeric_limits<float>::quiet_NaN()), test_mask);
|
||||
int nans = 0;
|
||||
for (int y = 0; y < A.rows; y++)
|
||||
{
|
||||
for (int x = 0; x < A.cols; x++)
|
||||
{
|
||||
for (int c = 0; c < cn; c++)
|
||||
{
|
||||
float v = A.ptr<float>(y, x)[c];
|
||||
nans += (v == v) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(nans, cn * (sz.area() - 2)) << "A=" << A << std::endl << "mask=" << test_mask << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CV_CXX_STD_ARRAY
|
||||
TEST(Core_Mat_array, outputArray_create_getMat)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user