Commit 76c97145 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #5883 from alalek:fix_5876

parents 512e73db 17e4d33b
...@@ -5352,22 +5352,21 @@ void cv::normalize( InputArray _src, InputOutputArray _dst, double a, double b, ...@@ -5352,22 +5352,21 @@ void cv::normalize( InputArray _src, InputOutputArray _dst, double a, double b,
else else
CV_Error( CV_StsBadArg, "Unknown/unsupported norm type" ); CV_Error( CV_StsBadArg, "Unknown/unsupported norm type" );
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); int type = _src.type(), depth = CV_MAT_DEPTH(type);
if( rtype < 0 ) if( rtype < 0 )
rtype = _dst.fixedType() ? _dst.depth() : depth; rtype = _dst.fixedType() ? _dst.depth() : depth;
_dst.createSameSize(_src, CV_MAKETYPE(rtype, cn));
CV_OCL_RUN(_dst.isUMat(), CV_OCL_RUN(_dst.isUMat(),
ocl_normalize(_src, _dst, _mask, rtype, scale, shift)) ocl_normalize(_src, _dst, _mask, rtype, scale, shift))
Mat src = _src.getMat(), dst = _dst.getMat(); Mat src = _src.getMat();
if( _mask.empty() ) if( _mask.empty() )
src.convertTo( dst, rtype, scale, shift ); src.convertTo( _dst, rtype, scale, shift );
else else
{ {
Mat temp; Mat temp;
src.convertTo( temp, rtype, scale, shift ); src.convertTo( temp, rtype, scale, shift );
temp.copyTo( dst, _mask ); temp.copyTo( _dst, _mask );
} }
} }
......
...@@ -1885,6 +1885,22 @@ OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceMin, Combine(testing::Values(std::make ...@@ -1885,6 +1885,22 @@ OCL_INSTANTIATE_TEST_CASE_P(Arithm, ReduceMin, Combine(testing::Values(std::make
OCL_ALL_CHANNELS, testing::Values(0, 1), Bool())); OCL_ALL_CHANNELS, testing::Values(0, 1), Bool()));
// T-API BUG (haveOpenCL() is false): modules/core/src/matrix.cpp:212: error: (-215) u->refcount == 0 in function deallocate
OCL_TEST(Normalize, DISABLED_regression_5876_inplace_change_type)
{
double initial_values[] = {1, 2, 5, 4, 3};
float result_values[] = {0, 0.25, 1, 0.75, 0.5};
Mat m(Size(5, 1), CV_64FC1, initial_values);
Mat result(Size(5, 1), CV_32FC1, result_values);
UMat um; m.copyTo(um);
UMat uresult; result.copyTo(uresult);
OCL_ON(normalize(um, um, 1, 0, NORM_MINMAX, CV_32F));
EXPECT_EQ(0, cvtest::norm(um, uresult, NORM_INF));
}
} } // namespace cvtest::ocl } } // namespace cvtest::ocl
#endif // HAVE_OPENCL #endif // HAVE_OPENCL
...@@ -1833,3 +1833,14 @@ TEST(MinMaxLoc, Mat_IntMax_Without_Mask) ...@@ -1833,3 +1833,14 @@ TEST(MinMaxLoc, Mat_IntMax_Without_Mask)
ASSERT_EQ(Point(0, 0), minLoc); ASSERT_EQ(Point(0, 0), minLoc);
ASSERT_EQ(Point(0, 0), maxLoc); ASSERT_EQ(Point(0, 0), maxLoc);
} }
TEST(Normalize, regression_5876_inplace_change_type)
{
double initial_values[] = {1, 2, 5, 4, 3};
float result_values[] = {0, 0.25, 1, 0.75, 0.5};
Mat m(Size(5, 1), CV_64FC1, initial_values);
Mat result(Size(5, 1), CV_32FC1, result_values);
normalize(m, m, 1, 0, NORM_MINMAX, CV_32F);
EXPECT_EQ(0, cvtest::norm(m, result, NORM_INF));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment