|
|
@ -42,7 +42,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "precomp.hpp" |
|
|
|
#include "precomp.hpp" |
|
|
|
#include <limits.h> |
|
|
|
#include <limits.h> |
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
#include "opencl_kernels.hpp" |
|
|
|
#include "opencl_kernels.hpp" |
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************\
|
|
|
|
/****************************************************************************************\
|
|
|
@ -1291,9 +1290,10 @@ static bool ocl_morphology_op(InputArray _src, OutputArray _dst, Mat kernel, |
|
|
|
{ |
|
|
|
{ |
|
|
|
CV_Assert(op == MORPH_ERODE || op == MORPH_DILATE); |
|
|
|
CV_Assert(op == MORPH_ERODE || op == MORPH_DILATE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); |
|
|
|
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0; |
|
|
|
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0; |
|
|
|
|
|
|
|
|
|
|
|
if (_src.depth() == CV_64F && !doubleSupport) |
|
|
|
if (depth == CV_64F && !doubleSupport) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
UMat kernel8U; |
|
|
|
UMat kernel8U; |
|
|
@ -1324,13 +1324,14 @@ static bool ocl_morphology_op(InputArray _src, OutputArray _dst, Mat kernel, |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
static const char * const op2str[] = { "ERODE", "DILATE" }; |
|
|
|
static const char * const op2str[] = { "ERODE", "DILATE" }; |
|
|
|
String buildOptions = format("-D RADIUSX=%d -D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D %s%s%s -D GENTYPE=%s -D DEPTH_%d", |
|
|
|
String buildOptions = format("-D RADIUSX=%d -D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D %s%s%s" |
|
|
|
anchor.x, anchor.y, (int)localThreads[0], (int)localThreads[1], op2str[op], |
|
|
|
" -D T=%s -D DEPTH_%d -D cn=%d -D T1=%s", anchor.x, anchor.y, |
|
|
|
|
|
|
|
(int)localThreads[0], (int)localThreads[1], op2str[op], |
|
|
|
doubleSupport ? " -D DOUBLE_SUPPORT" : "", rectKernel ? " -D RECTKERNEL" : "", |
|
|
|
doubleSupport ? " -D DOUBLE_SUPPORT" : "", rectKernel ? " -D RECTKERNEL" : "", |
|
|
|
ocl::typeToStr(_src.type()), _src.depth() ); |
|
|
|
ocl::typeToStr(_src.type()), _src.depth(), cn, ocl::typeToStr(depth)); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<ocl::Kernel> kernels; |
|
|
|
std::vector<ocl::Kernel> kernels; |
|
|
|
for (int i = 0; i<iterations; i++) |
|
|
|
for (int i = 0; i < iterations; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ocl::Kernel k("morph", ocl::imgproc::morph_oclsrc, buildOptions); |
|
|
|
ocl::Kernel k("morph", ocl::imgproc::morph_oclsrc, buildOptions); |
|
|
|
if (k.empty()) |
|
|
|
if (k.empty()) |
|
|
@ -1341,33 +1342,27 @@ static bool ocl_morphology_op(InputArray _src, OutputArray _dst, Mat kernel, |
|
|
|
_dst.create(src.size(), src.type()); |
|
|
|
_dst.create(src.size(), src.type()); |
|
|
|
UMat dst = _dst.getUMat(); |
|
|
|
UMat dst = _dst.getUMat(); |
|
|
|
|
|
|
|
|
|
|
|
if( iterations== 1 && src.u != dst.u) |
|
|
|
if (iterations == 1 && src.u != dst.u) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Size wholesize; |
|
|
|
Size wholesize; |
|
|
|
Point ofs; |
|
|
|
Point ofs; |
|
|
|
src.locateROI(wholesize, ofs); |
|
|
|
src.locateROI(wholesize, ofs); |
|
|
|
int wholecols = wholesize.width, wholerows = wholesize.height; |
|
|
|
int wholecols = wholesize.width, wholerows = wholesize.height; |
|
|
|
|
|
|
|
|
|
|
|
int idxArg = 0; |
|
|
|
kernels[0].args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::WriteOnlyNoSize(dst), |
|
|
|
idxArg = kernels[0].set(idxArg, ocl::KernelArg::ReadOnlyNoSize(src)); |
|
|
|
ofs.x, ofs.y, src.cols, src.rows, ocl::KernelArg::PtrReadOnly(kernel8U), |
|
|
|
idxArg = kernels[0].set(idxArg, ocl::KernelArg::WriteOnlyNoSize(dst)); |
|
|
|
wholecols, wholerows); |
|
|
|
idxArg = kernels[0].set(idxArg, ofs.x); |
|
|
|
|
|
|
|
idxArg = kernels[0].set(idxArg, ofs.y); |
|
|
|
|
|
|
|
idxArg = kernels[0].set(idxArg, src.cols); |
|
|
|
|
|
|
|
idxArg = kernels[0].set(idxArg, src.rows); |
|
|
|
|
|
|
|
idxArg = kernels[0].set(idxArg, ocl::KernelArg::PtrReadOnly(kernel8U)); |
|
|
|
|
|
|
|
idxArg = kernels[0].set(idxArg, wholecols); |
|
|
|
|
|
|
|
idxArg = kernels[0].set(idxArg, wholerows); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return kernels[0].run(2, globalThreads, localThreads, false); |
|
|
|
return kernels[0].run(2, globalThreads, localThreads, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i< iterations; i++) |
|
|
|
for (int i = 0; i < iterations; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UMat source; |
|
|
|
UMat source; |
|
|
|
Size wholesize; |
|
|
|
Size wholesize; |
|
|
|
Point ofs; |
|
|
|
Point ofs; |
|
|
|
if( i == 0) |
|
|
|
|
|
|
|
|
|
|
|
if (i == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int cols = src.cols, rows = src.rows; |
|
|
|
int cols = src.cols, rows = src.rows; |
|
|
|
src.locateROI(wholesize,ofs); |
|
|
|
src.locateROI(wholesize,ofs); |
|
|
@ -1385,20 +1380,11 @@ static bool ocl_morphology_op(InputArray _src, OutputArray _dst, Mat kernel, |
|
|
|
dst.adjustROI(-ofs.y, -wholesize.height + rows + ofs.y, -ofs.x, -wholesize.width + cols + ofs.x); |
|
|
|
dst.adjustROI(-ofs.y, -wholesize.height + rows + ofs.y, -ofs.x, -wholesize.width + cols + ofs.x); |
|
|
|
source.adjustROI(-ofs.y, -wholesize.height + rows + ofs.y, -ofs.x, -wholesize.width + cols + ofs.x); |
|
|
|
source.adjustROI(-ofs.y, -wholesize.height + rows + ofs.y, -ofs.x, -wholesize.width + cols + ofs.x); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
source.locateROI(wholesize, ofs); |
|
|
|
source.locateROI(wholesize, ofs); |
|
|
|
int wholecols = wholesize.width, wholerows = wholesize.height; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int idxArg = 0; |
|
|
|
kernels[i].args(ocl::KernelArg::ReadOnlyNoSize(source), ocl::KernelArg::WriteOnlyNoSize(dst), |
|
|
|
idxArg = kernels[i].set(idxArg, ocl::KernelArg::ReadOnlyNoSize(source)); |
|
|
|
ofs.x, ofs.y, source.cols, source.rows, ocl::KernelArg::PtrReadOnly(kernel8U), |
|
|
|
idxArg = kernels[i].set(idxArg, ocl::KernelArg::WriteOnlyNoSize(dst)); |
|
|
|
wholesize.width, wholesize.height); |
|
|
|
idxArg = kernels[i].set(idxArg, ofs.x); |
|
|
|
|
|
|
|
idxArg = kernels[i].set(idxArg, ofs.y); |
|
|
|
|
|
|
|
idxArg = kernels[i].set(idxArg, source.cols); |
|
|
|
|
|
|
|
idxArg = kernels[i].set(idxArg, source.rows); |
|
|
|
|
|
|
|
idxArg = kernels[i].set(idxArg, ocl::KernelArg::PtrReadOnly(kernel8U)); |
|
|
|
|
|
|
|
idxArg = kernels[i].set(idxArg, wholecols); |
|
|
|
|
|
|
|
idxArg = kernels[i].set(idxArg, wholerows); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!kernels[i].run(2, globalThreads, localThreads, false)) |
|
|
|
if (!kernels[i].run(2, globalThreads, localThreads, false)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -1427,13 +1413,13 @@ static void morphOp( int op, InputArray _src, OutputArray _dst, |
|
|
|
return; |
|
|
|
return; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if( iterations == 0 || kernel.rows*kernel.cols == 1 ) |
|
|
|
if (iterations == 0 || kernel.rows*kernel.cols == 1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_src.copyTo(_dst); |
|
|
|
_src.copyTo(_dst); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( !kernel.data ) |
|
|
|
if (!kernel.data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
kernel = getStructuringElement(MORPH_RECT, Size(1+iterations*2,1+iterations*2)); |
|
|
|
kernel = getStructuringElement(MORPH_RECT, Size(1+iterations*2,1+iterations*2)); |
|
|
|
anchor = Point(iterations, iterations); |
|
|
|
anchor = Point(iterations, iterations); |
|
|
@ -1450,7 +1436,7 @@ static void morphOp( int op, InputArray _src, OutputArray _dst, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CV_OCL_RUN(_dst.isUMat() && _src.size() == _dst.size() && src_type == dst_type && |
|
|
|
CV_OCL_RUN(_dst.isUMat() && _src.size() == _dst.size() && src_type == dst_type && |
|
|
|
_src.dims() <= 2 && (src_cn == 1 || src_cn == 4) && |
|
|
|
_src.dims() <= 2 && src_cn <= 4 && |
|
|
|
(src_depth == CV_8U || src_depth == CV_32F || src_depth == CV_64F ) && |
|
|
|
(src_depth == CV_8U || src_depth == CV_32F || src_depth == CV_64F ) && |
|
|
|
borderType == cv::BORDER_CONSTANT && borderValue == morphologyDefaultBorderValue() && |
|
|
|
borderType == cv::BORDER_CONSTANT && borderValue == morphologyDefaultBorderValue() && |
|
|
|
(op == MORPH_ERODE || op == MORPH_DILATE), |
|
|
|
(op == MORPH_ERODE || op == MORPH_DILATE), |
|
|
|