提交 e80f5bed 编写于 作者: A Andrey Pavlenko 提交者: OpenCV Buildbot

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

......@@ -1520,7 +1520,12 @@ namespace cv
float pos, oclMat &newFrame, oclMat &buf);
//! 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
{
......
......@@ -26,7 +26,7 @@
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// 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
// derived from this software without specific prior written permission.
......@@ -49,41 +49,42 @@
using namespace perf;
using std::tr1::tuple;
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,
::testing::Combine(OCL_TYPICAL_MAT_SIZES,
OCL_PERF_ENUM(CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1))) // TODO does not work properly (see below)
PERF_TEST_P(MomentsFixture, Moments,
::testing::Combine(OCL_TYPICAL_MAT_SIZES,
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 int type = get<1>(params);
const bool binaryImage = get<2>(params);
Mat src(srcSize, type), dst(7, 1, CV_64F);
const bool binaryImage = false;
cv::Moments mom;
declare.in(src, WARMUP_RNG).out(dst);
Mat src(srcSize, type), dst(7, 1, CV_64F);
randu(src, 0, 255);
oclMat src_d(src);
cv::Moments mom;
if (RUN_OCL_IMPL)
{
ocl::oclMat oclSrc(src);
OCL_TEST_CYCLE() mom = cv::ocl::ocl_moments(oclSrc, binaryImage); // TODO Use oclSrc
cv::HuMoments(mom, dst);
SANITY_CHECK(dst);
OCL_TEST_CYCLE() mom = cv::ocl::ocl_moments(src_d, binaryImage);
}
else if (RUN_PLAIN_IMPL)
{
TEST_CYCLE() mom = cv::moments(src, binaryImage);
cv::HuMoments(mom, dst);
SANITY_CHECK(dst);
}
else
OCL_PERF_ELSE
cv::HuMoments(mom, dst);
SANITY_CHECK(dst, 1e-3);
}
此差异已折叠。
此差异已折叠。
......@@ -10,18 +10,19 @@ using namespace cvtest;
using namespace testing;
using namespace std;
PARAM_TEST_CASE(MomentsTest, MatType, bool)
PARAM_TEST_CASE(MomentsTest, MatType, bool, bool)
{
int type;
cv::Mat mat1;
cv::Mat mat;
bool test_contours;
bool binaryImage;
virtual void SetUp()
{
type = GET_PARAM(0);
test_contours = GET_PARAM(1);
cv::Size size(10*MWIDTH, 10*MHEIGHT);
mat1 = randomMat(size, type, 5, 16, false);
cv::Size size(10 * MWIDTH, 10 * MHEIGHT);
mat = randomMat(size, type, 0, 256, false);
binaryImage = GET_PARAM(2);
}
void Compare(Moments& cpu, Moments& gpu)
......@@ -29,16 +30,13 @@ PARAM_TEST_CASE(MomentsTest, MatType, bool)
Mat gpu_dst, cpu_dst;
HuMoments(cpu, cpu_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)
{
bool binaryImage = 0;
oclMat src_d(mat);
for(int j = 0; j < LOOP_TIMES; j++)
{
if(test_contours)
......@@ -53,18 +51,16 @@ OCL_TEST_P(MomentsTest, Mat)
for( size_t i = 0; i < contours.size(); i++ )
{
Moments m = moments( contours[i], false );
Moments dm = ocl::ocl_moments( contours[i], false );
Moments dm = ocl::ocl_moments( contours[i]);
Compare(m, dm);
}
}
cv::_InputArray _array(mat1);
cv::Moments CvMom = cv::moments(_array, binaryImage);
cv::Moments oclMom = cv::ocl::ocl_moments(_array, binaryImage);
cv::Moments CvMom = cv::moments(mat, binaryImage);
cv::Moments oclMom = cv::ocl::ocl_moments(src_d, binaryImage);
Compare(CvMom, oclMom);
}
}
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册