opencv/modules/ocl/test/test_moments.cpp

68 lines
1.8 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-05-09 17:57:13 +08:00
PARAM_TEST_CASE(MomentsTest, MatType, bool)
2013-02-27 13:45:16 +08:00
{
int type;
cv::Mat mat1;
bool test_contours;
virtual void SetUp()
{
type = GET_PARAM(0);
test_contours = GET_PARAM(1);
cv::Size size(10*MWIDTH, 10*MHEIGHT);
2013-10-03 00:18:48 +08:00
mat1 = randomMat(size, type, 5, 16, false);
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, .5);
2013-02-27 13:45:16 +08:00
}
};
2013-05-09 17:57:13 +08:00
OCL_TEST_P(MomentsTest, Mat)
2013-02-27 13:45:16 +08:00
{
bool binaryImage = 0;
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 );
Moments dm = ocl::ocl_moments( contours[i], false );
Compare(m, dm);
}
}
cv::_InputArray _array(mat1);
cv::Moments CvMom = cv::moments(_array, binaryImage);
cv::Moments oclMom = cv::ocl::ocl_moments(_array, binaryImage);
Compare(CvMom, oclMom);
}
}
2013-05-09 17:57:13 +08:00
INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MomentsTest, Combine(
2013-02-27 13:45:16 +08:00
Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_64FC1), Values(true,false)));
2013-02-27 13:45:16 +08:00
#endif // HAVE_OPENCL