1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

HAL resize, warpAffine, warpPerspective interface

- added HAL documentation support
- added documentation to HAL replacement interface
- updated several HAL functions in imgproc module
This commit is contained in:
Maksim Shabunin
2016-03-22 16:52:23 +03:00
parent 06ea0aa02b
commit 5877debb6f
13 changed files with 866 additions and 311 deletions
+288 -10
View File
@@ -1,34 +1,312 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Copyright (C) 2015, Itseez Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef OPENCV_IMGPROC_HAL_REPLACEMENT_HPP
#define OPENCV_IMGPROC_HAL_REPLACEMENT_HPP
#include "opencv2/core/hal/interface.h"
#if defined __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-parameter"
#elif defined _MSC_VER
# pragma warning( push )
# pragma warning( disable: 4100 )
#endif
//! @addtogroup imgproc_hal_interface
//! @note Define your functions to override default implementations:
//! @code
//! #undef hal_add8u
//! #define hal_add8u my_add8u
//! @endcode
//! @{
/**
@brief Dummy structure storing filtering context
Users can convert this pointer to any type they want. Initialisation and destruction should be made in Init and Free function implementations correspondingly.
Example:
@code{.cpp}
int my_hal_filterInit(cvhalFilter2D **context, ...) {
context = static_cast<cvhalFilter2D*>(new MyFilterData());
//... init
}
int my_hal_filterFree(cvhalFilter2D *context) {
MyFilterData *c = static_cast<MyFilterData*>(context);
delete c;
}
@endcode
*/
struct cvhalFilter2D {};
inline int hal_ni_filterInit(cvhalFilter2D **, uchar *, size_t, int, int, int, int, int, int, int, int, double, int, int, bool, bool) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
inline int hal_ni_filter(cvhalFilter2D *, uchar *, size_t, uchar *, size_t, int, int, int, int, int, int) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
inline int hal_ni_filterFree(cvhalFilter2D *) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_filterInit
@param context double pointer to user-defined context
@param kernel_data pointer to kernel data
@param kernel_step kernel step
@param kernel_type kernel type (CV_8U, ...)
@param kernel_width kernel width
@param kernel_height kernel height
@param max_width max possible image width, can be used to allocate working buffers
@param max_height max possible image height
@param src_type source image type
@param dst_type destination image type
@param borderType border processing mode (CV_HAL_BORDER_REFLECT, ...)
@param delta added to pixel values
@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 allowSubmatrix indicates whether the submatrices will be allowed as source image
@param allowInplace indicates whether the inplace operation will be possible
@sa cv::filter2D, cv::hal::Filter2D
*/
inline int hal_ni_filterInit(cvhalFilter2D **context, uchar *kernel_data, size_t kernel_step, int kernel_type, int kernel_width, int kernel_height, int max_width, int max_height, int src_type, int dst_type, int borderType, double delta, int anchor_x, int anchor_y, bool allowSubmatrix, bool allowInplace) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_filter
@param context pointer to user-defined context
@param src_data source image data
@param src_step source image step
@param dst_data destination image data
@param dst_step destination image step
@param width images width
@param height images height
@param full_width full width of source image (outside the ROI)
@param full_height full height of source image (outside the ROI)
@param offset_x source image ROI offset X
@param offset_y source image ROI offset Y
@sa cv::filter2D, cv::hal::Filter2D
*/
inline int hal_ni_filter(cvhalFilter2D *context, uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step, int width, int height, int full_width, int full_height, int offset_x, int offset_y) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_filterFree
@param context pointer to user-defined context
@sa cv::filter2D, cv::hal::Filter2D
*/
inline int hal_ni_filterFree(cvhalFilter2D *context) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
//! @cond IGNORED
#define cv_hal_filterInit hal_ni_filterInit
#define cv_hal_filter hal_ni_filter
#define cv_hal_filterFree hal_ni_filterFree
//! @endcond
inline int hal_ni_sepFilterInit(cvhalFilter2D **, int, int, int, uchar *, size_t, int, int, uchar *, size_t, int, int, int, int, double, int) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
inline int hal_ni_sepFilter(cvhalFilter2D *, uchar *, size_t, uchar*, size_t, int, int, int, int, int, int) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
inline int hal_ni_sepFilterFree(cvhalFilter2D *) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_sepFilterInit
@param context double pointer to user-defined context
@param src_type source image type
@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 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 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; }
/**
@brief hal_sepFilter
@param context pointer to user-defined context
@param src_data source image data
@param src_step source image step
@param dst_data destination image data
@param dst_step destination image step
@param width images width
@param height images height
@param full_width full width of source image (outside the ROI)
@param full_height full height of source image (outside the ROI)
@param offset_x source image ROI offset X
@param offset_y source image ROI offset Y
@sa cv::sepFilter2D, cv::hal::SepFilter2D
*/
inline int hal_ni_sepFilter(cvhalFilter2D *context, uchar *src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int full_width, int full_height, int offset_x, int offset_y) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_sepFilterFree
@param context pointer to user-defined context
@sa cv::sepFilter2D, cv::hal::SepFilter2D
*/
inline int hal_ni_sepFilterFree(cvhalFilter2D *context) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
//! @cond IGNORED
#define cv_hal_sepFilterInit hal_ni_sepFilterInit
#define cv_hal_sepFilter hal_ni_sepFilter
#define cv_hal_sepFilterFree hal_ni_sepFilterFree
//! @endcond
inline int hal_ni_morphInit(cvhalFilter2D **, int, int, int, int, int, int, uchar *, size_t, int, int, int, int, int, const double[4], int, bool, bool) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
inline int hal_ni_morph(cvhalFilter2D *, uchar *, size_t, uchar *, size_t, int, int, int, int, int, int, int, int, int, int) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
inline int hal_ni_morphFree(cvhalFilter2D *) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_morphInit
@param context double pointer to user-defined context
@param operation morphology operation CV_HAL_MORPH_ERODE or CV_HAL_MORPH_DILATE
@param src_type source image type
@param dst_type destination image type
@param max_width max possible image width, can be used to allocate working buffers
@param max_height max possible image height
@param kernel_type kernel type (CV_8U, ...)
@param kernel_data pointer to kernel data
@param kernel_step kernel step
@param kernel_width kernel width
@param kernel_height kernel height
@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 borderType border processing mode (CV_HAL_BORDER_REFLECT, ...)
@param borderValue values to use for CV_HAL_BORDER_CONSTANT mode
@param iterations number of iterations
@param allowSubmatrix indicates whether the submatrices will be allowed as source image
@param allowInplace indicates whether the inplace operation will be possible
@sa cv::erode, cv::dilate, cv::morphologyEx, cv::hal::Morph
*/
inline int hal_ni_morphInit(cvhalFilter2D **context, int operation, int src_type, int dst_type, int max_width, int max_height, int kernel_type, uchar *kernel_data, size_t kernel_step, int kernel_width, int kernel_height, int anchor_x, int anchor_y, int borderType, const double borderValue[4], int iterations, bool allowSubmatrix, bool allowInplace) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_morph
@param context pointer to user-defined context
@param src_data source image data
@param src_step source image step
@param dst_data destination image data
@param dst_step destination image step
@param width images width
@param height images height
@param src_full_width full width of source image (outside the ROI)
@param src_full_height full height of source image (outside the ROI)
@param src_roi_x source image ROI X offset
@param src_roi_y source image ROI Y offset
@param dst_full_width full width of destination image
@param dst_full_height full height of destination image
@param dst_roi_x destination image ROI X offset
@param dst_roi_y destination image ROI Y offset
@sa cv::erode, cv::dilate, cv::morphologyEx, cv::hal::Morph
*/
inline int hal_ni_morph(cvhalFilter2D *context, uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step, int width, int height, int src_full_width, int src_full_height, int src_roi_x, int src_roi_y, int dst_full_width, int dst_full_height, int dst_roi_x, int dst_roi_y) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_morphFree
@param context pointer to user-defined context
@sa cv::erode, cv::dilate, cv::morphologyEx, cv::hal::Morph
*/
inline int hal_ni_morphFree(cvhalFilter2D *context) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
//! @cond IGNORED
#define cv_hal_morphInit hal_ni_morphInit
#define cv_hal_morph hal_ni_morph
#define cv_hal_morphFree hal_ni_morphFree
//! @endcond
/**
@brief hal_resize
@param src_type source and destination image type
@param src_data source image data
@param src_step source image step
@param src_width source image width
@param src_height source image height
@param dst_data destination image data
@param dst_step destination image step
@param dst_width destination image width
@param dst_height destination image height
@param inv_scale_x inversed scale X coefficient
@param inv_scale_y inversed scale Y coefficient
@param interpolation interpolation mode (CV_HAL_INTER_NEAREST, ...)
@sa cv::resize, cv::hal::resize
*/
inline int hal_ni_resize(int src_type, const uchar *src_data, size_t src_step, int src_width, int src_height, uchar *dst_data, size_t dst_step, int dst_width, int dst_height, double inv_scale_x, double inv_scale_y, int interpolation) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_warpAffine
@param src_type source and destination image type
@param src_data source image data
@param src_step source image step
@param src_width source image width
@param src_height source image height
@param dst_data destination image data
@param dst_step destination image step
@param dst_width destination image width
@param dst_height destination image height
@param M 3x2 matrix with transform coefficients
@param interpolation interpolation mode (CV_HAL_INTER_NEAREST, ...)
@param borderType border processing mode (CV_HAL_BORDER_REFLECT, ...)
@param borderValue values to use for CV_HAL_BORDER_CONSTANT mode
@sa cv::warpAffine, cv::hal::warpAffine
*/
inline int hal_ni_warpAffine(int src_type, const uchar *src_data, size_t src_step, int src_width, int src_height, uchar *dst_data, size_t dst_step, int dst_width, int dst_height, const double M[6], int interpolation, int borderType, const double borderValue[4]) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
/**
@brief hal_warpPerspectve
@param src_type source and destination image type
@param src_data source image data
@param src_step source image step
@param src_width source image width
@param src_height source image height
@param dst_data destination image data
@param dst_step destination image step
@param dst_width destination image width
@param dst_height destination image height
@param M 3x3 matrix with transform coefficients
@param interpolation interpolation mode (CV_HAL_INTER_NEAREST, ...)
@param borderType border processing mode (CV_HAL_BORDER_REFLECT, ...)
@param borderValue values to use for CV_HAL_BORDER_CONSTANT mode
@sa cv::warpPerspective, cv::hal::warpPerspective
*/
inline int hal_ni_warpPerspectve(int src_type, const uchar *src_data, size_t src_step, int src_width, int src_height, uchar *dst_data, size_t dst_step, int dst_width, int dst_height, const double M[9], int interpolation, int borderType, const double borderValue[4]) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
//! @cond IGNORED
#define cv_hal_resize hal_ni_resize
#define cv_hal_warpAffine hal_ni_warpAffine
#define cv_hal_warpPerspective hal_ni_warpPerspectve
//! @endcond
//! @}
#if defined __GNUC__
# pragma GCC diagnostic pop
#elif defined _MSC_VER
# pragma warning( pop )
#endif
#include "custom_hal.hpp"
#endif // OPENCV_IMGPROC_HAL_REPLACEMENT_HPP
#endif
+136 -92
View File
@@ -49,6 +49,7 @@
#include "precomp.hpp"
#include "opencl_kernels_imgproc.hpp"
#include "hal_replacement.hpp"
using namespace cv;
@@ -3091,8 +3092,8 @@ static bool ocl_resize( InputArray _src, OutputArray _dst, Size dsize,
#endif
#if IPP_VERSION_X100 >= 710
static bool ipp_resize_mt( Mat src, Mat dst,
double inv_scale_x, double inv_scale_y, int interpolation)
static bool ipp_resize_mt(Mat & src, Mat & dst,
double inv_scale_x, double inv_scale_y, int interpolation)
{
int mode = -1;
if (interpolation == INTER_LINEAR && src.rows >= 2 && src.cols >= 2)
@@ -3113,15 +3114,24 @@ static bool ipp_resize_mt( Mat src, Mat dst,
}
#endif
}
//==================================================================================================
namespace hal {
//////////////////////////////////////////////////////////////////////////////////////////
void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
double inv_scale_x, double inv_scale_y, int interpolation )
void resize(int src_type,
const uchar * src_data, size_t src_step, int src_width, int src_height,
uchar * dst_data, size_t dst_step, int dst_width, int dst_height,
double inv_scale_x, double inv_scale_y, int interpolation)
{
CV_Assert((dst_width * dst_height > 0) || (inv_scale_x > 0 && inv_scale_y > 0));
if (inv_scale_x < DBL_EPSILON || inv_scale_y < DBL_EPSILON)
{
inv_scale_x = static_cast<double>(dst_width) / src_width;
inv_scale_y = static_cast<double>(dst_height) / src_height;
}
CALL_HAL(resize, cv_hal_resize, src_type, src_data, src_step, src_width, src_height, dst_data, dst_step, dst_width, dst_height, inv_scale_x, inv_scale_y, interpolation);
static ResizeFunc linear_tab[] =
{
resizeGeneric_<
@@ -3226,24 +3236,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
resizeArea_<double, double>, 0
};
Size ssize = _src.size();
CV_Assert( ssize.area() > 0 );
CV_Assert( dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y > 0) );
if( dsize.area() == 0 )
{
dsize = Size(saturate_cast<int>(ssize.width*inv_scale_x),
saturate_cast<int>(ssize.height*inv_scale_y));
CV_Assert( dsize.area() > 0 );
}
else
{
inv_scale_x = (double)dsize.width/ssize.width;
inv_scale_y = (double)dsize.height/ssize.height;
}
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
int depth = CV_MAT_DEPTH(src_type), cn = CV_MAT_CN(src_type);
double scale_x = 1./inv_scale_x, scale_y = 1./inv_scale_y;
int iscale_x = saturate_cast<int>(scale_x);
@@ -3252,42 +3245,30 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
bool is_area_fast = std::abs(scale_x - iscale_x) < DBL_EPSILON &&
std::abs(scale_y - iscale_y) < DBL_EPSILON;
Size dsize = Size(saturate_cast<int>(src_width*inv_scale_x),
saturate_cast<int>(src_height*inv_scale_y));
CV_Assert( dsize.area() > 0 );
CV_OCL_RUN(_src.dims() <= 2 && _dst.isUMat() && _src.cols() > 10 && _src.rows() > 10,
ocl_resize(_src, _dst, dsize, inv_scale_x, inv_scale_y, interpolation))
Mat src = _src.getMat();
_dst.create(dsize, src.type());
Mat dst = _dst.getMat();
if (dsize == ssize) {
// Source and destination are of same size. Use simple copy.
src.copyTo(dst);
return;
}
#ifdef HAVE_TEGRA_OPTIMIZATION
if (tegra::useTegra() && tegra::resize(src, dst, (float)inv_scale_x, (float)inv_scale_y, interpolation))
return;
#endif
Mat src(Size(src_width, src_height), src_type, const_cast<uchar*>(src_data), src_step);
Mat dst(dsize, src_type, dst_data, dst_step);
#ifdef HAVE_IPP
int mode = -1;
if (interpolation == INTER_LINEAR && _src.rows() >= 2 && _src.cols() >= 2)
if (interpolation == INTER_LINEAR && src_height >= 2 && src_width >= 2)
mode = INTER_LINEAR;
else if (interpolation == INTER_CUBIC && _src.rows() >= 4 && _src.cols() >= 4)
else if (interpolation == INTER_CUBIC && src_height >= 4 && src_width >= 4)
mode = INTER_CUBIC;
const double IPP_RESIZE_EPS = 1e-10;
double ex = fabs((double)dsize.width / _src.cols() - inv_scale_x) / inv_scale_x;
double ey = fabs((double)dsize.height / _src.rows() - inv_scale_y) / inv_scale_y;
double ex = fabs((double)dsize.width / src_width - inv_scale_x) / inv_scale_x;
double ey = fabs((double)dsize.height / src_height - inv_scale_y) / inv_scale_y;
#endif
CV_IPP_RUN(IPP_VERSION_X100 >= 710 && ((ex < IPP_RESIZE_EPS && ey < IPP_RESIZE_EPS && depth != CV_64F) || (ex == 0 && ey == 0 && depth == CV_64F)) &&
(interpolation == INTER_LINEAR || interpolation == INTER_CUBIC) &&
!(interpolation == INTER_LINEAR && is_area_fast && iscale_x == 2 && iscale_y == 2 && depth == CV_8U) &&
mode >= 0 && (cn == 1 || cn == 3 || cn == 4) && (depth == CV_16U || depth == CV_16S || depth == CV_32F ||
(depth == CV_64F && mode == INTER_LINEAR)), ipp_resize_mt(src, dst, inv_scale_x, inv_scale_y, interpolation))
(depth == CV_64F && mode == INTER_LINEAR)),
ipp_resize_mt(src, dst, inv_scale_x, inv_scale_y, interpolation))
if( interpolation == INTER_NEAREST )
{
@@ -3311,7 +3292,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
if( is_area_fast )
{
int area = iscale_x*iscale_y;
size_t srcstep = src.step / src.elemSize1();
size_t srcstep = src_step / src.elemSize1();
AutoBuffer<int> _ofs(area + dsize.width*cn);
int* ofs = _ofs;
int* xofs = ofs + area;
@@ -3337,11 +3318,11 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
ResizeAreaFunc func = area_tab[depth];
CV_Assert( func != 0 && cn <= 4 );
AutoBuffer<DecimateAlpha> _xytab((ssize.width + ssize.height)*2);
DecimateAlpha* xtab = _xytab, *ytab = xtab + ssize.width*2;
AutoBuffer<DecimateAlpha> _xytab((src_width + src_height)*2);
DecimateAlpha* xtab = _xytab, *ytab = xtab + src_width*2;
int xtab_size = computeResizeAreaTab(ssize.width, dsize.width, cn, scale_x, xtab);
int ytab_size = computeResizeAreaTab(ssize.height, dsize.height, 1, scale_y, ytab);
int xtab_size = computeResizeAreaTab(src_width, dsize.width, cn, scale_x, xtab);
int ytab_size = computeResizeAreaTab(src_height, dsize.height, 1, scale_y, ytab);
AutoBuffer<int> _tabofs(dsize.height + 1);
int* tabofs = _tabofs;
@@ -3409,11 +3390,11 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
fx = 0, sx = 0;
}
if( sx + ksize2 >= ssize.width )
if( sx + ksize2 >= src_width )
{
xmax = std::min( xmax, dx );
if( sx >= ssize.width-1 && (interpolation != INTER_CUBIC && interpolation != INTER_LANCZOS4))
fx = 0, sx = ssize.width-1;
if( sx >= src_width-1 && (interpolation != INTER_CUBIC && interpolation != INTER_LANCZOS4))
fx = 0, sx = src_width-1;
}
for( k = 0, sx *= cn; k < cn; k++ )
@@ -3486,6 +3467,46 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
fixpt ? (void*)ibeta : (void*)beta, xmin, xmax, ksize );
}
} // cv::hal::
} // cv::
//==================================================================================================
void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
double inv_scale_x, double inv_scale_y, int interpolation )
{
Size ssize = _src.size();
CV_Assert( ssize.area() > 0 );
CV_Assert( dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y > 0) );
if( dsize.area() == 0 )
{
dsize = Size(saturate_cast<int>(ssize.width*inv_scale_x),
saturate_cast<int>(ssize.height*inv_scale_y));
CV_Assert( dsize.area() > 0 );
}
else
{
inv_scale_x = (double)dsize.width/ssize.width;
inv_scale_y = (double)dsize.height/ssize.height;
}
CV_OCL_RUN(_src.dims() <= 2 && _dst.isUMat() && _src.cols() > 10 && _src.rows() > 10,
ocl_resize(_src, _dst, dsize, inv_scale_x, inv_scale_y, interpolation))
Mat src = _src.getMat();
_dst.create(dsize, src.type());
Mat dst = _dst.getMat();
if (dsize == ssize) {
// Source and destination are of same size. Use simple copy.
src.copyTo(dst);
return;
}
hal::resize(src.type(), src.data, src.step, src.cols, src.rows, dst.data, dst.step, dst.cols, dst.rows, inv_scale_x, inv_scale_y, interpolation);
}
/****************************************************************************************\
* General warping (affine, perspective, remap) *
@@ -5232,7 +5253,7 @@ class WarpAffineInvoker :
{
public:
WarpAffineInvoker(const Mat &_src, Mat &_dst, int _interpolation, int _borderType,
const Scalar &_borderValue, int *_adelta, int *_bdelta, double *_M) :
const Scalar &_borderValue, int *_adelta, int *_bdelta, const double *_M) :
ParallelLoopBody(), src(_src), dst(_dst), interpolation(_interpolation),
borderType(_borderType), borderValue(_borderValue), adelta(_adelta), bdelta(_bdelta),
M(_M)
@@ -5410,7 +5431,7 @@ private:
int interpolation, borderType;
Scalar borderValue;
int *adelta, *bdelta;
double *M;
const double *M;
};
@@ -5569,8 +5590,40 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0,
#endif
namespace hal {
void warpAffine(int src_type,
const uchar * src_data, size_t src_step, int src_width, int src_height,
uchar * dst_data, size_t dst_step, int dst_width, int dst_height,
const double M[6], int interpolation, int borderType, const double borderValue[4])
{
CALL_HAL(warpAffine, cv_hal_warpAffine, src_type, src_data, src_step, src_width, src_height, dst_data, dst_step, dst_width, dst_height, M, interpolation, borderType, borderValue);
Mat src(Size(src_width, src_height), src_type, const_cast<uchar*>(src_data), src_step);
Mat dst(Size(dst_width, dst_height), src_type, dst_data, dst_step);
int x;
AutoBuffer<int> _abdelta(dst.cols*2);
int* adelta = &_abdelta[0], *bdelta = adelta + dst.cols;
const int AB_BITS = MAX(10, (int)INTER_BITS);
const int AB_SCALE = 1 << AB_BITS;
for( x = 0; x < dst.cols; x++ )
{
adelta[x] = saturate_cast<int>(M[0]*x*AB_SCALE);
bdelta[x] = saturate_cast<int>(M[3]*x*AB_SCALE);
}
Range range(0, dst.rows);
WarpAffineInvoker invoker(src, dst, interpolation, borderType,
Scalar(borderValue[0], borderValue[1], borderValue[2], borderValue[3]),
adelta, bdelta, M);
parallel_for_(range, invoker, dst.total()/(double)(1<<16));
}
} // hal::
} // cv::
void cv::warpAffine( InputArray _src, OutputArray _dst,
InputArray _M0, Size dsize,
@@ -5596,11 +5649,6 @@ void cv::warpAffine( InputArray _src, OutputArray _dst,
CV_Assert( (M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 2 && M0.cols == 3 );
M0.convertTo(matM, matM.type());
#ifdef HAVE_TEGRA_OPTIMIZATION
if( tegra::useTegra() && tegra::warpAffine(src, dst, M, flags, borderType, borderValue) )
return;
#endif
if( !(flags & WARP_INVERSE_MAP) )
{
double D = M[0]*M[4] - M[1]*M[3];
@@ -5613,12 +5661,6 @@ void cv::warpAffine( InputArray _src, OutputArray _dst,
M[2] = b1; M[5] = b2;
}
int x;
AutoBuffer<int> _abdelta(dst.cols*2);
int* adelta = &_abdelta[0], *bdelta = adelta + dst.cols;
const int AB_BITS = MAX(10, (int)INTER_BITS);
const int AB_SCALE = 1 << AB_BITS;
#if defined (HAVE_IPP) && IPP_VERSION_X100 >= 810 && IPP_DISABLE_BLOCK
CV_IPP_CHECK()
{
@@ -5683,16 +5725,8 @@ void cv::warpAffine( InputArray _src, OutputArray _dst,
}
#endif
for( x = 0; x < dst.cols; x++ )
{
adelta[x] = saturate_cast<int>(M[0]*x*AB_SCALE);
bdelta[x] = saturate_cast<int>(M[3]*x*AB_SCALE);
}
Range range(0, dst.rows);
WarpAffineInvoker invoker(src, dst, interpolation, borderType,
borderValue, adelta, bdelta, M);
parallel_for_(range, invoker, dst.total()/(double)(1<<16));
hal::warpAffine(src.type(), src.data, src.step, src.cols, src.rows, dst.data, dst.step, dst.cols, dst.rows,
M, interpolation, borderType, borderValue.val);
}
@@ -5703,7 +5737,7 @@ class WarpPerspectiveInvoker :
public ParallelLoopBody
{
public:
WarpPerspectiveInvoker(const Mat &_src, Mat &_dst, double *_M, int _interpolation,
WarpPerspectiveInvoker(const Mat &_src, Mat &_dst, const double *_M, int _interpolation,
int _borderType, const Scalar &_borderValue) :
ParallelLoopBody(), src(_src), dst(_dst), M(_M), interpolation(_interpolation),
borderType(_borderType), borderValue(_borderValue)
@@ -6037,12 +6071,11 @@ public:
private:
Mat src;
Mat dst;
double* M;
const double* M;
int interpolation, borderType;
Scalar borderValue;
};
#if defined (HAVE_IPP) && IPP_VERSION_X100 >= 810 && IPP_DISABLE_BLOCK
class IPPWarpPerspectiveInvoker :
public ParallelLoopBody
@@ -6095,8 +6128,26 @@ private:
const IPPWarpPerspectiveInvoker& operator= (const IPPWarpPerspectiveInvoker&);
};
#endif
namespace hal {
void warpPerspectve(int src_type,
const uchar * src_data, size_t src_step, int src_width, int src_height,
uchar * dst_data, size_t dst_step, int dst_width, int dst_height,
const double M[9], int interpolation, int borderType, const double borderValue[4])
{
CALL_HAL(warpPerspective, cv_hal_warpPerspective, src_type, src_data, src_step, src_width, src_height, dst_data, dst_step, dst_width, dst_height, M, interpolation, borderType, borderValue);
Mat src(Size(src_width, src_height), src_type, const_cast<uchar*>(src_data), src_step);
Mat dst(Size(dst_width, dst_height), src_type, dst_data, dst_step);
Range range(0, dst.rows);
WarpPerspectiveInvoker invoker(src, dst, M, interpolation, borderType, Scalar(borderValue[0], borderValue[1], borderValue[2], borderValue[3]));
parallel_for_(range, invoker, dst.total()/(double)(1<<16));
}
} // hal::
} // cv::
void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0,
Size dsize, int flags, int borderType, const Scalar& borderValue )
{
@@ -6122,12 +6173,6 @@ void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0,
CV_Assert( (M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 3 && M0.cols == 3 );
M0.convertTo(matM, matM.type());
#ifdef HAVE_TEGRA_OPTIMIZATION
if( tegra::useTegra() && tegra::warpPerspective(src, dst, M, flags, borderType, borderValue) )
return;
#endif
#if defined (HAVE_IPP) && IPP_VERSION_X100 >= 810 && IPP_DISABLE_BLOCK
CV_IPP_CHECK()
{
@@ -6190,9 +6235,8 @@ void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0,
if( !(flags & WARP_INVERSE_MAP) )
invert(matM, matM);
Range range(0, dst.rows);
WarpPerspectiveInvoker invoker(src, dst, M, interpolation, borderType, borderValue);
parallel_for_(range, invoker, dst.total()/(double)(1<<16));
hal::warpPerspectve(src.type(), src.data, src.step, src.cols, src.rows, dst.data, dst.step, dst.cols, dst.rows,
matM.ptr<double>(), interpolation, borderType, borderValue.val);
}
+8 -8
View File
@@ -1079,7 +1079,7 @@ namespace cv
// ===== 1. replacement implementation
struct ReplacementMorphImpl : public hal::MorphContext
struct ReplacementMorphImpl : public hal::Morph
{
cvhalFilter2D * ctx;
bool isInitialized;
@@ -1184,7 +1184,7 @@ INIT_TRAIT(CV_32FC4, 32f, 32f_C4R, 4, zero[4] = {0})
//--------------------------------------
struct IppMorphBaseImpl : public hal::MorphContext
struct IppMorphBaseImpl : public hal::Morph
{
virtual bool init(int _op, int _src_type, int dst_type, int max_width, int max_height,
int kernel_type, uchar * kernel_data, size_t kernel_step, int kernel_width, int kernel_height,
@@ -1379,7 +1379,7 @@ static IppMorphBaseImpl * createIppImpl(int type)
// ===== 3. Fallback implementation
struct OcvMorphImpl : public hal::MorphContext
struct OcvMorphImpl : public hal::Morph
{
Ptr<FilterEngine> f;
int iterations;
@@ -1425,7 +1425,7 @@ struct OcvMorphImpl : public hal::MorphContext
namespace hal {
Ptr<MorphContext> MorphContext ::create(int op, int src_type, int dst_type, int max_width, int max_height,
Ptr<Morph> Morph ::create(int op, int src_type, int dst_type, int max_width, int max_height,
int kernel_type, uchar * kernel_data, size_t kernel_step, int kernel_width, int kernel_height,
int anchor_x, int anchor_y,
int borderType, const double borderValue[4],
@@ -1438,7 +1438,7 @@ Ptr<MorphContext> MorphContext ::create(int op, int src_type, int dst_type, int
anchor_x, anchor_y,
borderType, borderValue, iterations, isSubmatrix, allowInplace))
{
return Ptr<MorphContext>(impl);
return Ptr<Morph>(impl);
}
delete impl;
}
@@ -1453,7 +1453,7 @@ Ptr<MorphContext> MorphContext ::create(int op, int src_type, int dst_type, int
anchor_x, anchor_y,
borderType, borderValue, iterations, isSubmatrix, allowInplace))
{
return Ptr<MorphContext>(impl);
return Ptr<Morph>(impl);
}
delete impl;
}
@@ -1465,7 +1465,7 @@ Ptr<MorphContext> MorphContext ::create(int op, int src_type, int dst_type, int
kernel_type, kernel_data, kernel_step, kernel_width, kernel_height,
anchor_x, anchor_y,
borderType, borderValue, iterations, isSubmatrix, allowInplace);
return Ptr<MorphContext>(impl);
return Ptr<Morph>(impl);
}
}
@@ -1858,7 +1858,7 @@ static void morphOp( int op, InputArray _src, OutputArray _dst,
Size d_wsz(dst.cols, dst.rows);
dst.locateROI(d_wsz, d_ofs);
Ptr<hal::MorphContext> ctx = hal::MorphContext::create(op, src.type(), dst.type(), src.cols, src.rows,
Ptr<hal::Morph> ctx = hal::Morph::create(op, src.type(), dst.type(), src.cols, src.rows,
kernel.type(), kernel.data, kernel.step, kernel.cols, kernel.rows,
anchor.x, anchor.y, borderType, borderValue.val, iterations,
src.isSubmatrix(), src.data == dst.data);