Commit 25a9b0a2 authored by Andrey Kamaev's avatar Andrey Kamaev

Fix depth calculation for Scalar in core arithmetic

parent c0f2a8e0
...@@ -1216,15 +1216,16 @@ void cv::min(const Mat& src1, double src2, Mat& dst) ...@@ -1216,15 +1216,16 @@ void cv::min(const Mat& src1, double src2, Mat& dst)
namespace cv namespace cv
{ {
static int actualScalarDepth(const Mat& src) static int actualScalarDepth(const double* data, int len)
{ {
const double* data = (const double*)src.data; double minval = data[0];
double minval = MIN(data[0], data[1]); double maxval = data[0];
minval = MIN(minval, data[2]); for(int i = 1; i < len; ++i)
minval = MIN(minval, data[3]); {
double maxval = MAX(data[0], data[1]); minval = MIN(minval, data[i]);
maxval = MAX(maxval, data[2]); maxval = MAX(maxval, data[i]);
maxval = MAX(maxval, data[3]); }
int depth = CV_64F; int depth = CV_64F;
if(minval >= 0 && maxval <= UCHAR_MAX) if(minval >= 0 && maxval <= UCHAR_MAX)
depth = CV_8U; depth = CV_8U;
...@@ -1236,6 +1237,8 @@ static int actualScalarDepth(const Mat& src) ...@@ -1236,6 +1237,8 @@ static int actualScalarDepth(const Mat& src)
depth = CV_16S; depth = CV_16S;
else if(minval >= INT_MIN && maxval <= INT_MAX) else if(minval >= INT_MIN && maxval <= INT_MAX)
depth = CV_32S; depth = CV_32S;
else if(minval >= -FLT_MAX && maxval <= FLT_MAX)
depth = CV_32F;
return depth; return depth;
} }
...@@ -1275,7 +1278,7 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, ...@@ -1275,7 +1278,7 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
"nor 'array op scalar', nor 'scalar op array'" ); "nor 'array op scalar', nor 'scalar op array'" );
haveScalar = true; haveScalar = true;
CV_Assert(src2.type() == CV_64F && (src2.rows == 4 || src2.rows == 1)); CV_Assert(src2.type() == CV_64F && (src2.rows == 4 || src2.rows == 1));
depth2 = actualScalarDepth(src2); depth2 = MAX(src1.depth(), actualScalarDepth(src2.ptr<double>(), src1.channels()));
} }
int cn = src1.channels(), depth1 = src1.depth(), wtype; int cn = src1.channels(), depth1 = src1.depth(), wtype;
...@@ -1522,23 +1525,32 @@ void cv::subtract( InputArray src1, InputArray src2, OutputArray dst, ...@@ -1522,23 +1525,32 @@ void cv::subtract( InputArray src1, InputArray src2, OutputArray dst,
InputArray mask, int dtype ) InputArray mask, int dtype )
{ {
#ifdef HAVE_TEGRA_OPTIMIZATION #ifdef HAVE_TEGRA_OPTIMIZATION
if(mask.empty() && src1.depth() == CV_8U && src2.depth() == CV_8U && (dtype == CV_16S || (dtype == -1 && dst.fixedType() && dst.depth() == CV_16S))) if (mask.empty() && src1.depth() == CV_8U && src2.depth() == CV_8U)
{
Mat _dst = dst.getMat();
if(tegra::subtract_8u8u16s(src1.getMat(), src2.getMat(), _dst))
return;
}
if(mask.empty() && src1.depth() == CV_8U && src2.depth() == CV_8U && dst.depth() == CV_32F)
{
Mat _dst = dst.getMat();
if(tegra::subtract_8u8u32f(src1.getMat(), src2.getMat(), _dst))
return;
}
if(mask.empty() && src1.depth() == CV_8U && src2.depth() == CV_8U && dst.depth() == CV_8S)
{ {
Mat _dst = dst.getMat(); if (dtype == -1 && dst.fixedType())
if(tegra::subtract_8u8u8s(src1.getMat(), src2.getMat(), _dst)) dtype = dst.depth();
return;
if (!dst.fixedType() || dtype == dst.depth())
{
if (dtype == CV_16S)
{
Mat _dst = dst.getMat();
if(tegra::subtract_8u8u16s(src1.getMat(), src2.getMat(), _dst))
return;
}
else if (dtype == CV_32F)
{
Mat _dst = dst.getMat();
if(tegra::subtract_8u8u32f(src1.getMat(), src2.getMat(), _dst))
return;
}
else if (dtype == CV_8S)
{
Mat _dst = dst.getMat();
if(tegra::subtract_8u8u8s(src1.getMat(), src2.getMat(), _dst))
return;
}
}
} }
#endif #endif
arithm_op(src1, src2, dst, mask, dtype, subTab ); arithm_op(src1, src2, dst, mask, dtype, subTab );
......
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