void run(int) { RNG& rng = theRNG(); for( int i = 0; i < 10; i++ ) { int m = rng.uniform(2, 11); int n = rng.uniform(2, 11); int depth = rng.uniform(0, 2) + CV_32F; Mat src8u(m, n, depth), src(m, n, depth), dst(m, n, CV_MAKETYPE(depth, 2)); Mat z = Mat::zeros(m, n, depth), dstz; randu(src8u, Scalar::all(0), Scalar::all(10)); src8u.convertTo(src, src.type()); dst = Scalar::all(123); Mat mv[] = {src, z}, srcz; merge(mv, 2, srcz); dft(srcz, dstz); dft(src, dst, DFT_COMPLEX_OUTPUT); if (cvtest::norm(dst, dstz, NORM_INF) > 1e-3) { cout << "actual:\n" << dst << endl << endl; cout << "reference:\n" << dstz << endl << endl; CV_Error(CV_StsError, ""); } } }
Moments ocl_moments(oclMat& src, bool binary) //for image { CV_Assert(src.oclchannels() == 1); if(src.type() == CV_64FC1 && !Context::getContext()->supportsFeature(FEATURE_CL_DOUBLE)) { CV_Error(CV_StsUnsupportedFormat, "Moments - double is not supported by your GPU!"); } if(binary) { oclMat mask; if(src.type() != CV_8UC1) { src.convertTo(mask, CV_8UC1); } oclMat src8u(src.size(), CV_8UC1); src8u.setTo(Scalar(255), mask); src = src8u; } const int TILE_SIZE = 256; CvMoments mom; memset(&mom, 0, sizeof(mom)); cv::Size size = src.size(); int blockx, blocky; blockx = (size.width + TILE_SIZE - 1)/TILE_SIZE; blocky = (size.height + TILE_SIZE - 1)/TILE_SIZE; oclMat dst_m; int tile_height = TILE_SIZE; size_t localThreads[3] = {1, tile_height, 1}; size_t globalThreads[3] = {blockx, size.height, 1}; if(Context::getContext()->supportsFeature(FEATURE_CL_DOUBLE)) { dst_m.create(blocky * 10, blockx, CV_64FC1); }else { dst_m.create(blocky * 10, blockx, CV_32FC1); } int src_step = (int)(src.step/src.elemSize()); int dstm_step = (int)(dst_m.step/dst_m.elemSize()); std::vector<std::pair<size_t , const void *> > args,args_sum; args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&src.data )); args.push_back( std::make_pair( sizeof(cl_int) , (void *)&src.rows )); args.push_back( std::make_pair( sizeof(cl_int) , (void *)&src.cols )); args.push_back( std::make_pair( sizeof(cl_int) , (void *)&src_step )); args.push_back( std::make_pair( sizeof(cl_mem) , (void *)&dst_m.data )); args.push_back( std::make_pair( sizeof(cl_int) , (void *)&dst_m.cols )); args.push_back( std::make_pair( sizeof(cl_int) , (void *)&dstm_step )); int binary_; if(binary) binary_ = 1; else binary_ = 0; args.push_back( std::make_pair( sizeof(cl_int) , (void *)&binary_)); char builOption[128]; if(binary || src.type() == CV_8UC1) { snprintf(builOption, 128, "-D CV_8UC1"); }else if(src.type() == CV_16UC1) { snprintf(builOption, 128, "-D CV_16UC1"); }else if(src.type() == CV_16SC1) { snprintf(builOption, 128, "-D CV_16SC1"); }else if(src.type() == CV_32FC1) { snprintf(builOption, 128, "-D CV_32FC1"); }else if(src.type() == CV_64FC1) { snprintf(builOption, 128, "-D CV_64FC1"); }else { CV_Error( CV_StsUnsupportedFormat, "" ); } openCLExecuteKernel(Context::getContext(), &moments, "CvMoments", globalThreads, localThreads, args, -1, -1, builOption); Mat tmp(dst_m); tmp.convertTo(tmp, CV_64FC1); double tmp_m[10] = {0}; for(int j = 0; j < tmp.rows; j += 10) { for(int i = 0; i < tmp.cols; i++) { tmp_m[0] += tmp.at<double>(j, i); tmp_m[1] += tmp.at<double>(j + 1, i); tmp_m[2] += tmp.at<double>(j + 2, i); tmp_m[3] += tmp.at<double>(j + 3, i); tmp_m[4] += tmp.at<double>(j + 4, i); tmp_m[5] += tmp.at<double>(j + 5, i); tmp_m[6] += tmp.at<double>(j + 6, i); tmp_m[7] += tmp.at<double>(j + 7, i); tmp_m[8] += tmp.at<double>(j + 8, i); tmp_m[9] += tmp.at<double>(j + 9, i); } } mom.m00 = tmp_m[0]; mom.m10 = tmp_m[1]; mom.m01 = tmp_m[2]; mom.m20 = tmp_m[3]; mom.m11 = tmp_m[4]; mom.m02 = tmp_m[5]; mom.m30 = tmp_m[6]; mom.m21 = tmp_m[7]; mom.m12 = tmp_m[8]; mom.m03 = tmp_m[9]; icvCompleteMomentState( &mom ); return mom; }