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

Merge pull request #1710 from melody-rain:2.4_moments_ocl

parents ef9f6905 3dbcd054
...@@ -1520,7 +1520,12 @@ namespace cv ...@@ -1520,7 +1520,12 @@ namespace cv
float pos, oclMat &newFrame, oclMat &buf); float pos, oclMat &newFrame, oclMat &buf);
//! computes moments of the rasterized shape or a vector of points //! computes moments of the rasterized shape or a vector of points
CV_EXPORTS Moments ocl_moments(InputArray _array, bool binaryImage); //! _array should be a vector a points standing for the contour
CV_EXPORTS Moments ocl_moments(InputArray contour);
//! src should be a general image uploaded to the GPU.
//! the supported oclMat type are CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1 and CV_64FC1
//! to use type of CV_64FC1, the GPU should support CV_64FC1
CV_EXPORTS Moments ocl_moments(oclMat& src, bool binary);
class CV_EXPORTS StereoBM_OCL class CV_EXPORTS StereoBM_OCL
{ {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
// //
// * Redistribution's in binary form must reproduce the above copyright notice, // * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation // this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. // and/or other Materials provided with the distribution.
// //
// * The name of the copyright holders may not be used to endorse or promote products // * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission. // derived from this software without specific prior written permission.
...@@ -49,41 +49,42 @@ ...@@ -49,41 +49,42 @@
using namespace perf; using namespace perf;
using std::tr1::tuple; using std::tr1::tuple;
using std::tr1::get; using std::tr1::get;
using namespace cv;
using namespace cv::ocl;
using namespace cvtest;
using namespace testing;
using namespace std;
///////////// Moments ////////////////////////
typedef Size_MatType MomentsFixture; ///////////// Moments ////////////////////////
//*! performance of image
typedef tuple<Size, MatType, bool> MomentsParamType;
typedef TestBaseWithParam<MomentsParamType> MomentsFixture;
PERF_TEST_P(MomentsFixture, DISABLED_Moments, PERF_TEST_P(MomentsFixture, Moments,
::testing::Combine(OCL_TYPICAL_MAT_SIZES, ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
OCL_PERF_ENUM(CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1))) // TODO does not work properly (see below) OCL_PERF_ENUM(CV_8UC1, CV_16SC1, CV_16UC1, CV_32FC1), ::testing::Values(false, true)))
{ {
const Size_MatType_t params = GetParam(); const MomentsParamType params = GetParam();
const Size srcSize = get<0>(params); const Size srcSize = get<0>(params);
const int type = get<1>(params); const int type = get<1>(params);
const bool binaryImage = get<2>(params);
Mat src(srcSize, type), dst(7, 1, CV_64F); Mat src(srcSize, type), dst(7, 1, CV_64F);
const bool binaryImage = false; randu(src, 0, 255);
cv::Moments mom;
declare.in(src, WARMUP_RNG).out(dst);
oclMat src_d(src);
cv::Moments mom;
if (RUN_OCL_IMPL) if (RUN_OCL_IMPL)
{ {
ocl::oclMat oclSrc(src); OCL_TEST_CYCLE() mom = cv::ocl::ocl_moments(src_d, binaryImage);
OCL_TEST_CYCLE() mom = cv::ocl::ocl_moments(oclSrc, binaryImage); // TODO Use oclSrc
cv::HuMoments(mom, dst);
SANITY_CHECK(dst);
} }
else if (RUN_PLAIN_IMPL) else if (RUN_PLAIN_IMPL)
{ {
TEST_CYCLE() mom = cv::moments(src, binaryImage); TEST_CYCLE() mom = cv::moments(src, binaryImage);
cv::HuMoments(mom, dst);
SANITY_CHECK(dst);
} }
else else
OCL_PERF_ELSE OCL_PERF_ELSE
cv::HuMoments(mom, dst);
SANITY_CHECK(dst, 1e-3);
} }
This diff is collapsed.
This diff is collapsed.
...@@ -10,18 +10,19 @@ using namespace cvtest; ...@@ -10,18 +10,19 @@ using namespace cvtest;
using namespace testing; using namespace testing;
using namespace std; using namespace std;
PARAM_TEST_CASE(MomentsTest, MatType, bool) PARAM_TEST_CASE(MomentsTest, MatType, bool, bool)
{ {
int type; int type;
cv::Mat mat1; cv::Mat mat;
bool test_contours; bool test_contours;
bool binaryImage;
virtual void SetUp() virtual void SetUp()
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
test_contours = GET_PARAM(1); test_contours = GET_PARAM(1);
cv::Size size(10*MWIDTH, 10*MHEIGHT); cv::Size size(10 * MWIDTH, 10 * MHEIGHT);
mat1 = randomMat(size, type, 5, 16, false); mat = randomMat(size, type, 0, 256, false);
binaryImage = GET_PARAM(2);
} }
void Compare(Moments& cpu, Moments& gpu) void Compare(Moments& cpu, Moments& gpu)
...@@ -29,16 +30,13 @@ PARAM_TEST_CASE(MomentsTest, MatType, bool) ...@@ -29,16 +30,13 @@ PARAM_TEST_CASE(MomentsTest, MatType, bool)
Mat gpu_dst, cpu_dst; Mat gpu_dst, cpu_dst;
HuMoments(cpu, cpu_dst); HuMoments(cpu, cpu_dst);
HuMoments(gpu, gpu_dst); HuMoments(gpu, gpu_dst);
EXPECT_MAT_NEAR(gpu_dst,cpu_dst, .5); EXPECT_MAT_NEAR(gpu_dst,cpu_dst, 1e-3);
} }
}; };
OCL_TEST_P(MomentsTest, Mat) OCL_TEST_P(MomentsTest, Mat)
{ {
bool binaryImage = 0; oclMat src_d(mat);
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {
if(test_contours) if(test_contours)
...@@ -53,18 +51,16 @@ OCL_TEST_P(MomentsTest, Mat) ...@@ -53,18 +51,16 @@ OCL_TEST_P(MomentsTest, Mat)
for( size_t i = 0; i < contours.size(); i++ ) for( size_t i = 0; i < contours.size(); i++ )
{ {
Moments m = moments( contours[i], false ); Moments m = moments( contours[i], false );
Moments dm = ocl::ocl_moments( contours[i], false ); Moments dm = ocl::ocl_moments( contours[i]);
Compare(m, dm); Compare(m, dm);
} }
} }
cv::_InputArray _array(mat1); cv::Moments CvMom = cv::moments(mat, binaryImage);
cv::Moments CvMom = cv::moments(_array, binaryImage); cv::Moments oclMom = cv::ocl::ocl_moments(src_d, binaryImage);
cv::Moments oclMom = cv::ocl::ocl_moments(_array, binaryImage);
Compare(CvMom, oclMom); Compare(CvMom, oclMom);
} }
} }
INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MomentsTest, Combine( INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MomentsTest, Combine(
Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_64FC1), Values(true,false))); Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1, CV_64FC1), Values(false, true), Values(false, true)));
#endif // HAVE_OPENCL #endif // HAVE_OPENCL
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