static bool matchTemplate_SQDIFF_NORMED(InputArray _image, InputArray _templ, OutputArray _result) { matchTemplate(_image, _templ, _result, CV_TM_CCORR); int type = _image.type(), cn = CV_MAT_CN(type); ocl::Kernel k("matchTemplate_SQDIFF_NORMED", ocl::imgproc::match_template_oclsrc, format("-D SQDIFF_NORMED -D T=%s -D cn=%d", ocl::typeToStr(type), cn)); if (k.empty()) return false; UMat image = _image.getUMat(), templ = _templ.getUMat(); _result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F); UMat result = _result.getUMat(); UMat image_sums, image_sqsums; integral(image.reshape(1), image_sums, image_sqsums, CV_32F, CV_32F); UMat templ_sqsum; if (!sumTemplate(_templ, templ_sqsum)) return false; k.args(ocl::KernelArg::ReadOnlyNoSize(image_sqsums), ocl::KernelArg::ReadWrite(result), templ.rows, templ.cols, ocl::KernelArg::PtrReadOnly(templ_sqsum)); size_t globalsize[2] = { result.cols, result.rows }; return k.run(2, globalsize, NULL, false); }
static bool convolve_32F(InputArray _image, InputArray _templ, OutputArray _result) { _result.create(_image.rows() - _templ.rows() + 1, _image.cols() - _templ.cols() + 1, CV_32F); if (_image.channels() == 1) return(convolve_dft(_image, _templ, _result)); else { UMat image = _image.getUMat(); UMat templ = _templ.getUMat(); UMat result_(image.rows-templ.rows+1,(image.cols-templ.cols+1)*image.channels(), CV_32F); bool ok = convolve_dft(image.reshape(1), templ.reshape(1), result_); if (ok==false) return false; UMat result = _result.getUMat(); return (extractFirstChannel_32F(result_, _result, _image.channels())); } }
static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double & result ) { const ocl::Device & d = ocl::Device::getDefault(); #ifdef __ANDROID__ if (d.isNVidia()) return false; #endif const int cn = _src.channels(); if (cn > 4) return false; int type = _src.type(), depth = CV_MAT_DEPTH(type); bool doubleSupport = d.doubleFPConfig() > 0, haveMask = _mask.kind() != _InputArray::NONE; if ( !(normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR) || (!doubleSupport && depth == CV_64F)) return false; UMat src = _src.getUMat(); if (normType == NORM_INF) { if (!ocl_minMaxIdx(_src, NULL, &result, NULL, NULL, _mask, std::max(depth, CV_32S), depth != CV_8U && depth != CV_16U)) return false; } else if (normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR) { Scalar sc; bool unstype = depth == CV_8U || depth == CV_16U; if ( !ocl_sum(haveMask ? src : src.reshape(1), sc, normType == NORM_L2 || normType == NORM_L2SQR ? OCL_OP_SUM_SQR : (unstype ? OCL_OP_SUM : OCL_OP_SUM_ABS), _mask) ) return false; double s = 0.0; for (int i = 0; i < (haveMask ? cn : 1); ++i) s += sc[i]; result = normType == NORM_L1 || normType == NORM_L2SQR ? s : std::sqrt(s); } return true; }
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, OutputArrayOfArrays internals) { std::vector<UMat> inputs; std::vector<UMat> outputs; inps.getUMatVector(inputs); outs.getUMatVector(outputs); for (size_t i = 0; i < inputs.size(); i++) { UMat srcBlob = inputs[i]; void *src_handle = inputs[i].handle(ACCESS_READ); void *dst_handle = outputs[i].handle(ACCESS_WRITE); if (src_handle != dst_handle) { MatShape outShape = shape(outputs[i]); UMat umat = srcBlob.reshape(1, (int)outShape.size(), &outShape[0]); umat.copyTo(outputs[i]); } } outs.assign(outputs); return true; }