added cv::copyMakeBorder to T-API
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
// */
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencl_kernels.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@@ -701,12 +702,73 @@ void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, cv::Size srcroi,
|
||||
|
||||
}
|
||||
|
||||
namespace cv {
|
||||
|
||||
static bool ocl_copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom,
|
||||
int left, int right, int borderType, const Scalar& value )
|
||||
{
|
||||
int type = _src.type(), cn = CV_MAT_CN(type);
|
||||
bool isolated = (borderType & BORDER_ISOLATED) != 0;
|
||||
borderType &= ~cv::BORDER_ISOLATED;
|
||||
|
||||
if ( !(borderType == BORDER_CONSTANT || borderType == BORDER_REPLICATE || borderType == BORDER_REFLECT ||
|
||||
borderType == BORDER_WRAP || borderType == BORDER_REFLECT_101) ||
|
||||
cn == 3 || cn > 4)
|
||||
return false;
|
||||
|
||||
const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", "BORDER_WRAP", "BORDER_REFLECT_101" };
|
||||
ocl::Kernel k("copyMakeBorder", ocl::core::copymakeborder_oclsrc,
|
||||
format("-D T=%s -D %s", ocl::memopTypeToStr(type), borderMap[borderType]));
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
UMat src = _src.getUMat();
|
||||
if( src.isSubmatrix() && !isolated )
|
||||
{
|
||||
Size wholeSize;
|
||||
Point ofs;
|
||||
src.locateROI(wholeSize, ofs);
|
||||
int dtop = std::min(ofs.y, top);
|
||||
int dbottom = std::min(wholeSize.height - src.rows - ofs.y, bottom);
|
||||
int dleft = std::min(ofs.x, left);
|
||||
int dright = std::min(wholeSize.width - src.cols - ofs.x, right);
|
||||
src.adjustROI(dtop, dbottom, dleft, dright);
|
||||
top -= dtop;
|
||||
left -= dleft;
|
||||
bottom -= dbottom;
|
||||
right -= dright;
|
||||
}
|
||||
|
||||
_dst.create(src.rows + top + bottom, src.cols + left + right, type);
|
||||
UMat dst = _dst.getUMat();
|
||||
|
||||
if (top == 0 && left == 0 && bottom == 0 && right == 0)
|
||||
{
|
||||
if(src.u != dst.u || src.step != dst.step)
|
||||
src.copyTo(dst);
|
||||
return true;
|
||||
}
|
||||
|
||||
k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst),
|
||||
top, left, ocl::KernelArg::Constant(Mat(1, 1, type, value)));
|
||||
|
||||
size_t globalsize[2] = { dst.cols, dst.rows };
|
||||
return k.run(2, globalsize, NULL, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom,
|
||||
int left, int right, int borderType, const Scalar& value )
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 );
|
||||
|
||||
if (ocl::useOpenCL() && _dst.isUMat() && _src.dims() <= 2 &&
|
||||
ocl_copyMakeBorder(_src, _dst, top, bottom, left, right, borderType, value))
|
||||
return;
|
||||
|
||||
Mat src = _src.getMat();
|
||||
|
||||
if( src.isSubmatrix() && (borderType & BORDER_ISOLATED) == 0 )
|
||||
{
|
||||
Size wholeSize;
|
||||
|
Reference in New Issue
Block a user