opencv/modules/ocl/test/test_moments.cpp

65 lines
1.9 KiB
C++
Raw Normal View History

#include "test_precomp.hpp"
2013-02-27 13:45:16 +08:00
#include <iomanip>
#ifdef HAVE_OPENCL
using namespace cv;
using namespace cv::ocl;
using namespace cvtest;
using namespace testing;
2013-10-29 18:05:29 +08:00
PARAM_TEST_CASE(MomentsTest, MatType, bool, bool)
2013-02-27 13:45:16 +08:00
{
int type;
2013-10-29 18:05:29 +08:00
cv::Mat mat;
2013-02-27 13:45:16 +08:00
bool test_contours;
2013-10-29 18:05:29 +08:00
bool binaryImage;
2013-02-27 13:45:16 +08:00
virtual void SetUp()
{
type = GET_PARAM(0);
test_contours = GET_PARAM(1);
2013-10-29 18:05:29 +08:00
cv::Size size(10 * MWIDTH, 10 * MHEIGHT);
mat = randomMat(size, type, 0, 256, false);
binaryImage = GET_PARAM(2);
2013-02-27 13:45:16 +08:00
}
2013-07-22 19:31:14 +08:00
void Compare(Moments& cpu_moments, Moments& gpu_moments)
2013-02-27 13:45:16 +08:00
{
Mat gpu_dst, cpu_dst;
2013-07-22 19:31:14 +08:00
HuMoments(cpu_moments, cpu_dst);
HuMoments(gpu_moments, gpu_dst);
EXPECT_MAT_NEAR(gpu_dst, cpu_dst, 1e-3);
2013-02-27 13:45:16 +08:00
}
};
OCL_TEST_P(MomentsTest, Mat)
2013-02-27 13:45:16 +08:00
{
2013-10-29 18:05:29 +08:00
oclMat src_d(mat);
2013-02-27 13:45:16 +08:00
for(int j = 0; j < LOOP_TIMES; j++)
{
if(test_contours)
{
Mat src = readImage( "cv/shared/pic3.png", IMREAD_GRAYSCALE );
2013-06-25 16:26:33 +08:00
ASSERT_FALSE(src.empty());
Mat canny_output;
2013-02-27 13:45:16 +08:00
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
2013-06-25 16:26:33 +08:00
Canny( src, canny_output, 100, 200, 3 );
2013-04-12 18:12:12 +08:00
findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
2013-02-27 13:45:16 +08:00
for( size_t i = 0; i < contours.size(); i++ )
{
Moments m = moments( contours[i], false );
2013-10-29 18:05:29 +08:00
Moments dm = ocl::ocl_moments( contours[i]);
2013-02-27 13:45:16 +08:00
Compare(m, dm);
}
}
2013-10-29 18:05:29 +08:00
cv::Moments CvMom = cv::moments(mat, binaryImage);
cv::Moments oclMom = cv::ocl::ocl_moments(src_d, binaryImage);
2013-02-27 13:45:16 +08:00
Compare(CvMom, oclMom);
}
}
2013-05-09 17:57:13 +08:00
INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MomentsTest, Combine(
2013-10-29 18:05:29 +08:00
Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1, CV_64FC1), Values(false, true), Values(false, true)));
2013-02-27 13:45:16 +08:00
#endif // HAVE_OPENCL