Merge pull request #7221 from terfendail:sepfilter_vec_kernel

This commit is contained in:
Maksim Shabunin 2016-09-06 20:41:28 +00:00
commit c16f96cb5b
4 changed files with 35 additions and 37 deletions

View File

@ -1178,12 +1178,12 @@ struct SepFilterCtx
CAROTENE_NS::BORDER_MODE border;
};
inline int TEGRA_SEPFILTERINIT(cvhalFilter2D **context, int src_type, int dst_type, int kernel_type,
uchar *kernelx_data, size_t , int kernelx_width, int kernelx_height,
uchar *kernely_data, size_t kernely_step, int kernely_width, int kernely_height,
uchar *kernelx_data, int kernelx_length,
uchar *kernely_data, int kernely_length,
int anchor_x, int anchor_y, double delta, int borderType)
{
if(!context || !kernelx_data || !kernely_data || src_type != CV_8UC1 || dst_type != CV_16SC1 ||
!(kernelx_width == 3 && kernelx_height == 1) || !(kernely_width == 1 && kernely_height == 3) ||
kernelx_length != 3 || kernely_length != 3 ||
delta != 0 || anchor_x != 1 || anchor_y != 1)
return CV_HAL_ERROR_NOT_IMPLEMENTED;
@ -1225,24 +1225,24 @@ inline int TEGRA_SEPFILTERINIT(cvhalFilter2D **context, int src_type, int dst_ty
ctx->kernelx_data[1]=kernelx_data[1];
ctx->kernelx_data[2]=kernelx_data[2];
ctx->kernely_data[0]=kernely_data[0];
ctx->kernely_data[1]=kernely_data[kernely_step];
ctx->kernely_data[2]=kernely_data[2*kernely_step];
ctx->kernely_data[1]=kernely_data[1];
ctx->kernely_data[2]=kernely_data[2];
break;
case CV_8SC1:
ctx->kernelx_data[0]=((char*)kernelx_data)[0];
ctx->kernelx_data[1]=((char*)kernelx_data)[1];
ctx->kernelx_data[2]=((char*)kernelx_data)[2];
ctx->kernely_data[0]=((char*)kernely_data)[0];
ctx->kernely_data[1]=((char*)(kernely_data+kernely_step))[0];
ctx->kernely_data[2]=((char*)(kernely_data+2*kernely_step))[0];
ctx->kernely_data[1]=((char*)kernely_data)[1];
ctx->kernely_data[2]=((char*)kernely_data)[2];
break;
case CV_16UC1:
ctx->kernelx_data[0]=((int16_t*)kernelx_data)[0];
ctx->kernelx_data[1]=((int16_t*)kernelx_data)[1];
ctx->kernelx_data[2]=((int16_t*)kernelx_data)[2];
ctx->kernely_data[0]=((int16_t*)kernely_data)[0];
ctx->kernely_data[1]=((int16_t*)(kernely_data+kernely_step))[0];
ctx->kernely_data[2]=((int16_t*)(kernely_data+2*kernely_step))[0];
ctx->kernely_data[1]=((int16_t*)kernely_data)[1];
ctx->kernely_data[2]=((int16_t*)kernely_data)[2];
default:
delete ctx;
return CV_HAL_ERROR_NOT_IMPLEMENTED;

View File

@ -30,10 +30,8 @@ struct CV_EXPORTS Filter2D
struct CV_EXPORTS SepFilter2D
{
static Ptr<hal::SepFilter2D> create(int stype, int dtype, int ktype,
uchar * kernelx_data, size_t kernelx_step,
int kernelx_width, int kernelx_height,
uchar * kernely_data, size_t kernely_step,
int kernely_width, int kernely_height,
uchar * kernelx_data, int kernelx_len,
uchar * kernely_data, int kernely_len,
int anchor_x, int anchor_y,
double delta, int borderType);
virtual void apply(uchar * src_data, size_t src_step,

View File

@ -4823,13 +4823,13 @@ struct ReplacementSepFilter : public hal::SepFilter2D
bool isInitialized;
ReplacementSepFilter() : ctx(0), isInitialized(false) {}
bool init(int stype, int dtype, int ktype,
uchar * kernelx_data, size_t kernelx_step, int kernelx_width, int kernelx_height,
uchar * kernely_data, size_t kernely_step, int kernely_width, int kernely_height,
uchar * kernelx_data, int kernelx_len,
uchar * kernely_data, int kernely_len,
int anchor_x, int anchor_y, double delta, int borderType)
{
int res = cv_hal_sepFilterInit(&ctx, stype, dtype, ktype,
kernelx_data, kernelx_step, kernelx_width, kernelx_height,
kernely_data, kernely_step, kernely_width, kernely_height,
kernelx_data, kernelx_len,
kernely_data, kernely_len,
anchor_x, anchor_y, delta, borderType);
isInitialized = (res == CV_HAL_ERROR_OK);
return isInitialized;
@ -4862,14 +4862,14 @@ struct OcvSepFilter : public hal::SepFilter2D
int src_type;
int dst_type;
bool init(int stype, int dtype, int ktype,
uchar * kernelx_data, size_t kernelx_step, int kernelx_width, int kernelx_height,
uchar * kernely_data, size_t kernely_step, int kernely_width, int kernely_height,
uchar * kernelx_data, int kernelx_len,
uchar * kernely_data, int kernely_len,
int anchor_x, int anchor_y, double delta, int borderType)
{
src_type = stype;
dst_type = dtype;
Mat kernelX(Size(kernelx_width, kernelx_height), ktype, kernelx_data, kernelx_step);
Mat kernelY(Size(kernely_width, kernely_height), ktype, kernely_data, kernely_step);
Mat kernelX(Size(kernelx_len, 1), ktype, kernelx_data);
Mat kernelY(Size(kernely_len, 1), ktype, kernely_data);
f = createSeparableLinearFilter( stype, dtype, kernelX, kernelY,
Point(anchor_x, anchor_y),
@ -4958,15 +4958,15 @@ Ptr<hal::Filter2D> Filter2D::create(uchar* kernel_data, size_t kernel_step, int
//---------------------------------------------------------------
Ptr<SepFilter2D> SepFilter2D::create(int stype, int dtype, int ktype,
uchar * kernelx_data, size_t kernelx_step, int kernelx_width, int kernelx_height,
uchar * kernely_data, size_t kernely_step, int kernely_width, int kernely_height,
uchar * kernelx_data, int kernelx_len,
uchar * kernely_data, int kernely_len,
int anchor_x, int anchor_y, double delta, int borderType)
{
{
ReplacementSepFilter * impl = new ReplacementSepFilter();
if (impl->init(stype, dtype, ktype,
kernelx_data, kernelx_step, kernelx_width, kernelx_height,
kernely_data, kernely_step, kernely_width, kernely_height,
kernelx_data, kernelx_len,
kernely_data, kernely_len,
anchor_x, anchor_y, delta, borderType))
{
return Ptr<hal::SepFilter2D>(impl);
@ -4976,8 +4976,8 @@ Ptr<SepFilter2D> SepFilter2D::create(int stype, int dtype, int ktype,
{
OcvSepFilter * impl = new OcvSepFilter();
impl->init(stype, dtype, ktype,
kernelx_data, kernelx_step, kernelx_width, kernelx_height,
kernely_data, kernely_step, kernely_width, kernely_height,
kernelx_data, kernelx_len,
kernely_data, kernely_len,
anchor_x, anchor_y, delta, borderType);
return Ptr<hal::SepFilter2D>(impl);
}
@ -5041,11 +5041,15 @@ void cv::sepFilter2D( InputArray _src, OutputArray _dst, int ddepth,
if( (borderType & BORDER_ISOLATED) == 0 )
src.locateROI( wsz, ofs );
CV_Assert(kernelX.type() == kernelY.type());
CV_Assert( kernelX.type() == kernelY.type() &&
(kernelX.cols == 1 || kernelX.rows == 1) &&
(kernelY.cols == 1 || kernelY.rows == 1) );
Mat contKernelX = kernelX.isContinuous() ? kernelX : kernelX.clone();
Mat contKernelY = kernelY.isContinuous() ? kernelY : kernelY.clone();
Ptr<hal::SepFilter2D> c = hal::SepFilter2D::create(src.type(), dst.type(), kernelX.type(),
kernelX.data, kernelX.step, kernelX.cols, kernelX.rows,
kernelY.data, kernelY.step, kernelY.cols, kernelY.rows,
contKernelX.data, kernelX.cols + kernelX.rows - 1,
contKernelY.data, kernelY.cols + kernelY.rows - 1,
anchor.x, anchor.y, delta, borderType & ~BORDER_ISOLATED);
c->apply(src.data, src.step, dst.data, dst.step, dst.cols, dst.rows, wsz.width, wsz.height, ofs.x, ofs.y);
}

View File

@ -140,20 +140,16 @@ inline int hal_ni_filterFree(cvhalFilter2D *context) { return CV_HAL_ERROR_NOT_I
@param dst_type destination image type
@param kernel_type kernels type
@param kernelx_data pointer to x-kernel data
@param kernelx_step x-kernel step
@param kernelx_width x-kernel width
@param kernelx_height x-kernel height
@param kernelx_length x-kernel vector length
@param kernely_data pointer to y-kernel data
@param kernely_step y-kernel step
@param kernely_width y-kernel width
@param kernely_height y-kernel height
@param kernely_length y-kernel vector length
@param anchor_x relative X position of center point within the kernel
@param anchor_y relative Y position of center point within the kernel
@param delta added to pixel values
@param borderType border processing mode (CV_HAL_BORDER_REFLECT, ...)
@sa cv::sepFilter2D, cv::hal::SepFilter2D
*/
inline int hal_ni_sepFilterInit(cvhalFilter2D **context, int src_type, int dst_type, int kernel_type, uchar *kernelx_data, size_t kernelx_step, int kernelx_width, int kernelx_height, uchar *kernely_data, size_t kernely_step, int kernely_width, int kernely_height, int anchor_x, int anchor_y, double delta, int borderType) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
inline int hal_ni_sepFilterInit(cvhalFilter2D **context, int src_type, int dst_type, int kernel_type, uchar *kernelx_data, int kernelx_length, uchar *kernely_data, int kernely_length, int anchor_x, int anchor_y, double delta, int borderType) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_sepFilter
@param context pointer to user-defined context