Commit f0049fa2 authored by Andrey Pavlenko's avatar Andrey Pavlenko Committed by OpenCV Buildbot

Merge pull request #1937 from ilya-lavrenov:tapi_integral

parents b16f0a25 3eaa8f14
...@@ -129,6 +129,8 @@ public: ...@@ -129,6 +129,8 @@ public:
virtual bool isContinuous(int i=-1) const; virtual bool isContinuous(int i=-1) const;
virtual bool empty() const; virtual bool empty() const;
virtual void copyTo(const _OutputArray& arr) const; virtual void copyTo(const _OutputArray& arr) const;
virtual size_t offset(int i=-1) const;
virtual size_t step(int i=-1) const;
bool isMat() const; bool isMat() const;
bool isUMat() const; bool isUMat() const;
bool isMatVectot() const; bool isMatVectot() const;
......
...@@ -1792,6 +1792,85 @@ bool _InputArray::isContinuous(int i) const ...@@ -1792,6 +1792,85 @@ bool _InputArray::isContinuous(int i) const
return false; return false;
} }
size_t _InputArray::offset(int i) const
{
int k = kind();
if( k == MAT )
{
CV_Assert( i < 0 );
const Mat * const m = ((const Mat*)obj);
return (size_t)(m->data - m->datastart);
}
if( k == UMAT )
{
CV_Assert( i < 0 );
return ((const UMat*)obj)->offset;
}
if( k == EXPR || k == MATX || k == STD_VECTOR || k == NONE || k == STD_VECTOR_VECTOR)
return 0;
if( k == STD_VECTOR_MAT )
{
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
if( i < 0 )
return 1;
CV_Assert( i < (int)vv.size() );
return (size_t)(vv[i].data - vv[i].datastart);
}
if( k == GPU_MAT )
{
CV_Assert( i < 0 );
const cuda::GpuMat * const m = ((const cuda::GpuMat*)obj);
return (size_t)(m->data - m->datastart);
}
CV_Error(Error::StsNotImplemented, "");
return 0;
}
size_t _InputArray::step(int i) const
{
int k = kind();
if( k == MAT )
{
CV_Assert( i < 0 );
return ((const Mat*)obj)->step;
}
if( k == UMAT )
{
CV_Assert( i < 0 );
return ((const UMat*)obj)->step;
}
if( k == EXPR || k == MATX || k == STD_VECTOR || k == NONE || k == STD_VECTOR_VECTOR)
return 0;
if( k == STD_VECTOR_MAT )
{
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
if( i < 0 )
return 1;
CV_Assert( i < (int)vv.size() );
return vv[i].step;
}
if( k == GPU_MAT )
{
CV_Assert( i < 0 );
return ((const cuda::GpuMat*)obj)->step;
}
CV_Error(Error::StsNotImplemented, "");
return 0;
}
void _InputArray::copyTo(const _OutputArray& arr) const void _InputArray::copyTo(const _OutputArray& arr) const
{ {
int k = kind(); int k = kind();
......
...@@ -596,15 +596,15 @@ Calculates the integral of an image. ...@@ -596,15 +596,15 @@ Calculates the integral of an image.
.. ocv:function:: void integral( InputArray src, OutputArray sum, int sdepth=-1 ) .. ocv:function:: void integral( InputArray src, OutputArray sum, int sdepth=-1 )
.. ocv:function:: void integral( InputArray src, OutputArray sum, OutputArray sqsum, int sdepth=-1 ) .. ocv:function:: void integral( InputArray src, OutputArray sum, OutputArray sqsum, int sdepth=-1, int sqdepth=-1 )
.. ocv:function:: void integral( InputArray src, OutputArray sum, OutputArray sqsum, OutputArray tilted, int sdepth=-1 ) .. ocv:function:: void integral( InputArray src, OutputArray sum, OutputArray sqsum, OutputArray tilted, int sdepth=-1, int sqdepth=-1 )
.. ocv:pyfunction:: cv2.integral(src[, sum[, sdepth]]) -> sum .. ocv:pyfunction:: cv2.integral(src[, sum[, sdepth]]) -> sum
.. ocv:pyfunction:: cv2.integral2(src[, sum[, sqsum[, sdepth]]]) -> sum, sqsum .. ocv:pyfunction:: cv2.integral2(src[, sum[, sqsum[, sdepth[, sqdepth]]]]) -> sum, sqsum
.. ocv:pyfunction:: cv2.integral3(src[, sum[, sqsum[, tilted[, sdepth]]]]) -> sum, sqsum, tilted .. ocv:pyfunction:: cv2.integral3(src[, sum[, sqsum[, tilted[, sdepth[, sqdepth]]]]]) -> sum, sqsum, tilted
.. ocv:cfunction:: void cvIntegral( const CvArr* image, CvArr* sum, CvArr* sqsum=NULL, CvArr* tilted_sum=NULL ) .. ocv:cfunction:: void cvIntegral( const CvArr* image, CvArr* sum, CvArr* sqsum=NULL, CvArr* tilted_sum=NULL )
...@@ -618,6 +618,8 @@ Calculates the integral of an image. ...@@ -618,6 +618,8 @@ Calculates the integral of an image.
:param sdepth: desired depth of the integral and the tilted integral images, ``CV_32S``, ``CV_32F``, or ``CV_64F``. :param sdepth: desired depth of the integral and the tilted integral images, ``CV_32S``, ``CV_32F``, or ``CV_64F``.
:param sqdepth: desired depth of the integral image of squared pixel values, ``CV_32F`` or ``CV_64F``.
The functions calculate one or more integral images for the source image as follows: The functions calculate one or more integral images for the source image as follows:
.. math:: .. math::
......
...@@ -1241,12 +1241,12 @@ CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 ); ...@@ -1241,12 +1241,12 @@ CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 );
//! computes the integral image and integral for the squared image //! computes the integral image and integral for the squared image
CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum, CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum,
OutputArray sqsum, int sdepth = -1 ); OutputArray sqsum, int sdepth = -1, int sqdepth = -1 );
//! computes the integral image, integral for the squared image and the tilted integral image //! computes the integral image, integral for the squared image and the tilted integral image
CV_EXPORTS_AS(integral3) void integral( InputArray src, OutputArray sum, CV_EXPORTS_AS(integral3) void integral( InputArray src, OutputArray sum,
OutputArray sqsum, OutputArray tilted, OutputArray sqsum, OutputArray tilted,
int sdepth = -1 ); int sdepth = -1, int sqdepth = -1 );
//! adds image to the accumulator (dst += src). Unlike cv::add, dst and src can have different types. //! adds image to the accumulator (dst += src). Unlike cv::add, dst and src can have different types.
CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst, CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -271,15 +271,50 @@ OCL_TEST_P(CornerHarris, DISABLED_Mat) ...@@ -271,15 +271,50 @@ OCL_TEST_P(CornerHarris, DISABLED_Mat)
struct Integral : struct Integral :
public ImgprocTestBase public ImgprocTestBase
{ {
int sdepth; int sdepth, sqdepth;
TEST_DECLARE_OUTPUT_PARAMETER(dst2)
virtual void SetUp() virtual void SetUp()
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
blockSize = GET_PARAM(1); sdepth = GET_PARAM(1);
sdepth = GET_PARAM(2); sqdepth = GET_PARAM(2);
useRoi = GET_PARAM(3); useRoi = GET_PARAM(3);
} }
virtual void random_roi()
{
ASSERT_EQ(CV_MAT_CN(type), 1);
Size roiSize = randomSize(1, MAX_VALUE), isize = Size(roiSize.width + 1, roiSize.height + 1);
Border srcBorder = randomBorder(0, useRoi ? 2 : 0);
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
Border dstBorder = randomBorder(0, useRoi ? 2 : 0);
randomSubMat(dst, dst_roi, isize, dstBorder, sdepth, 5, 16);
Border dst2Border = randomBorder(0, useRoi ? 2 : 0);
randomSubMat(dst2, dst2_roi, isize, dst2Border, sqdepth, 5, 16);
UMAT_UPLOAD_INPUT_PARAMETER(src)
UMAT_UPLOAD_OUTPUT_PARAMETER(dst)
UMAT_UPLOAD_OUTPUT_PARAMETER(dst2)
}
void Near2(double threshold = 0.0, bool relative = false)
{
if (relative)
{
EXPECT_MAT_NEAR_RELATIVE(dst2, udst2, threshold);
EXPECT_MAT_NEAR_RELATIVE(dst2_roi, udst2_roi, threshold);
}
else
{
EXPECT_MAT_NEAR(dst2, udst2, threshold);
EXPECT_MAT_NEAR(dst2_roi, udst2_roi, threshold);
}
}
}; };
OCL_TEST_P(Integral, Mat1) OCL_TEST_P(Integral, Mat1)
...@@ -297,19 +332,15 @@ OCL_TEST_P(Integral, Mat1) ...@@ -297,19 +332,15 @@ OCL_TEST_P(Integral, Mat1)
OCL_TEST_P(Integral, Mat2) OCL_TEST_P(Integral, Mat2)
{ {
Mat dst1;
UMat udst1;
for (int j = 0; j < test_loop_times; j++) for (int j = 0; j < test_loop_times; j++)
{ {
random_roi(); random_roi();
OCL_OFF(cv::integral(src_roi, dst_roi, dst1, sdepth)); OCL_OFF(cv::integral(src_roi, dst_roi, dst2_roi, sdepth, sqdepth));
OCL_ON(cv::integral(usrc_roi, udst_roi, udst1, sdepth)); OCL_ON(cv::integral(usrc_roi, udst_roi, udst2_roi, sdepth, sqdepth));
Near(); Near();
if (cv::ocl::Device::getDefault().doubleFPConfig() > 0) sqdepth == CV_32F ? Near2(1e-6, true) : Near2();
EXPECT_MAT_NEAR(dst1, udst1, 0.);
} }
} }
...@@ -412,19 +443,21 @@ OCL_INSTANTIATE_TEST_CASE_P(Imgproc, EqualizeHist, Combine( ...@@ -412,19 +443,21 @@ OCL_INSTANTIATE_TEST_CASE_P(Imgproc, EqualizeHist, Combine(
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerMinEigenVal, Combine( OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerMinEigenVal, Combine(
Values((MatType)CV_8UC1, (MatType)CV_32FC1), Values((MatType)CV_8UC1, (MatType)CV_32FC1),
Values(3, 5), Values(3, 5),
Values((int)BORDER_CONSTANT, (int)BORDER_REPLICATE, (int)BORDER_REFLECT, (int)BORDER_REFLECT101), Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT101),
Bool())); Bool()));
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerHarris, Combine( OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerHarris, Combine(
Values((MatType)CV_8UC1, CV_32FC1), Values((MatType)CV_8UC1, CV_32FC1),
Values(3, 5), Values(3, 5),
Values( (int)BORDER_CONSTANT, (int)BORDER_REPLICATE, (int)BORDER_REFLECT, (int)BORDER_REFLECT_101), Values( (BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),
Bool())); Bool()));
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Integral, Combine( OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Integral, Combine(
Values((MatType)CV_8UC1), // TODO does not work with CV_32F, CV_64F Values((MatType)CV_8UC1), // TODO does not work with CV_32F, CV_64F
Values(0), // not used Values(CV_32SC1, CV_32FC1), // desired sdepth
Values((MatType)CV_32SC1, (MatType)CV_32FC1), Values(CV_32FC1, CV_64FC1), // desired sqdepth
Bool())); Bool()));
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine( OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine(
......
...@@ -1225,7 +1225,7 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -1225,7 +1225,7 @@ public class ImgprocTest extends OpenCVTestCase {
expSqsum.put(2, 0, 0, 18, 36, 54); expSqsum.put(2, 0, 0, 18, 36, 54);
expSqsum.put(3, 0, 0, 27, 54, 81); expSqsum.put(3, 0, 0, 27, 54, 81);
Imgproc.integral2(src, sum, sqsum, CvType.CV_64F); Imgproc.integral2(src, sum, sqsum, CvType.CV_64F, CvType.CV_64F);
assertMatEqual(expSum, sum, EPS); assertMatEqual(expSum, sum, EPS);
assertMatEqual(expSqsum, sqsum, EPS); assertMatEqual(expSqsum, sqsum, EPS);
...@@ -1274,7 +1274,7 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -1274,7 +1274,7 @@ public class ImgprocTest extends OpenCVTestCase {
expTilted.put(0, 0, 0, 0); expTilted.put(0, 0, 0, 0);
expTilted.put(1, 0, 0, 1); expTilted.put(1, 0, 0, 1);
Imgproc.integral3(src, sum, sqsum, tilted, CvType.CV_64F); Imgproc.integral3(src, sum, sqsum, tilted, CvType.CV_64F, CvType.CV_64F);
assertMatEqual(expSum, sum, EPS); assertMatEqual(expSum, sum, EPS);
assertMatEqual(expSqsum, sqsum, EPS); assertMatEqual(expSqsum, sqsum, EPS);
......
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