opencv/modules/ocl/test/test_moments.cpp
Roman Donchenko 029fce10c9 Merge remote-tracking branch 'origin/2.4'
Conflicts:
	3rdparty/libjasper/CMakeLists.txt
	cmake/OpenCVDetectOpenCL.cmake
	modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst
	modules/imgproc/src/floodfill.cpp
	modules/ocl/include/opencv2/ocl/ocl.hpp
	modules/ocl/src/arithm.cpp
	modules/ocl/src/haar.cpp
	modules/ocl/src/imgproc.cpp
	modules/ocl/src/initialization.cpp
	modules/ocl/src/matrix_operations.cpp
	modules/ocl/src/mcwutil.cpp
	modules/ocl/src/opencl/arithm_bitwise_and_mask.cl
	modules/ocl/src/opencl/arithm_bitwise_and_scalar_mask.cl
	modules/ocl/src/opencl/arithm_bitwise_binary_mask.cl
	modules/ocl/src/opencl/arithm_bitwise_binary_scalar.cl
	modules/ocl/src/opencl/arithm_bitwise_binary_scalar_mask.cl
	modules/ocl/src/opencl/arithm_bitwise_or.cl
	modules/ocl/src/opencl/arithm_bitwise_or_scalar.cl
	modules/ocl/src/opencl/arithm_bitwise_or_scalar_mask.cl
	modules/ocl/src/opencl/arithm_bitwise_xor.cl
	modules/ocl/src/opencl/arithm_bitwise_xor_mask.cl
	modules/ocl/src/opencl/arithm_bitwise_xor_scalar.cl
	modules/ocl/src/stereobm.cpp
	modules/ocl/test/precomp.hpp
	modules/python/src2/api
	modules/ts/src/ts_func.cpp
	samples/gpu/bgfg_segm.cpp
2013-05-21 17:19:23 +04:00

72 lines
1.9 KiB
C++

#include "precomp.hpp"
#include <iomanip>
#ifdef HAVE_OPENCL
using namespace cv;
using namespace cv::ocl;
using namespace cvtest;
using namespace testing;
using namespace std;
extern string workdir;
PARAM_TEST_CASE(MomentsTest, MatType, bool)
{
int type;
cv::Mat mat1;
bool test_contours;
virtual void SetUp()
{
type = GET_PARAM(0);
test_contours = GET_PARAM(1);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(10*MWIDTH, 10*MHEIGHT);
mat1 = randomMat(rng, size, type, 5, 16, false);
}
void Compare(Moments& cpu, Moments& gpu)
{
Mat gpu_dst, cpu_dst;
HuMoments(cpu, cpu_dst);
HuMoments(gpu, gpu_dst);
EXPECT_MAT_NEAR(gpu_dst,cpu_dst, .5);
}
};
TEST_P(MomentsTest, Mat)
{
bool binaryImage = 0;
SetUp();
for(int j = 0; j < LOOP_TIMES; j++)
{
if(test_contours)
{
Mat src = imread( workdir + "../cpp/pic3.png", 1 );
Mat src_gray, canny_output;
cvtColor( src, src_gray, COLOR_BGR2GRAY );
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
Canny( src_gray, canny_output, 100, 200, 3 );
findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
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);
}
}
INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MomentsTest, Combine(
Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_64FC1), Values(true,false)));
#endif // HAVE_OPENCL