Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resizeOnnx #3550

Open
wants to merge 6 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ignore dot files/directories
.*
!.gitignore

*.autosave
*.pyc
*.user
Expand Down
28 changes: 28 additions & 0 deletions modules/cudawarping/include/opencv2/cudawarping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,34 @@ supported for now.
*/
CV_EXPORTS_W void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null());

/** @brief onnx resize op
https://github.com/onnx/onnx/blob/main/docs/Operators.md#Resize
https://github.com/onnx/onnx/blob/main/onnx/reference/ops/op_resize.py

Not support `exclude_outside` and `extrapolation_value` yet.

To get a similar result to `cv::resize`, give dsize and:
INTER_NEAREST : ASYMMETRIC + NEAREST_FLOOR
INTER_LINEAR : HALF_PIXEL
INTER_CUBIC : HALF_PIXEL + cubicCoeff(-0.75)

@param src input image.
@param dst output image; it has the size dsize (when it is non-zero) or the size computed from src.size(), scale; the type of dst is the same as of src.
@param dsize output image size; if it equals to zero, it is computed as:
\f[\texttt{dsize = Size(int(scale.x * src.cols), int(scale.y * src.rows))}\f]
Either dsize or scale must be non-zero.
@param scale scale factor; use same definition as ONNX, if scale > 1, it's upsampling.
@param interpolation interpolation / coordiante, see #InterpolationFlags and #ResizeONNXFlags
@param cubicCoeff cubic sampling coeff; range \f[[-1.0, 0)\f]
@param roi crop region; if provided, the rois' coordinates are normalized in the coordinate system of the input image; it only takes effect with INTER_TF_CROP_RESIZE (ONNX tf_crop_and_resize)
@param stream Stream for the asynchronous version.

@sa resize, resizeOnnx
*/
CV_EXPORTS_W void resizeOnnx(InputArray src, OutputArray dst, Size dsize,
Point2d scale = Point2d(), int interpolation = INTER_LINEAR | INTER_HALF_PIXEL,
float cubicCoeff = -0.75f, Rect2d const& roi = Rect2d(), Stream& stream = Stream::Null());

/** @brief Applies an affine transformation to an image.

@param src Source image. CV_8U , CV_16U , CV_32S , or CV_32F depth and 1, 3, or 4 channels are
Expand Down
42 changes: 42 additions & 0 deletions modules/cudawarping/perf/perf_warping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,48 @@ PERF_TEST_P(Sz_Depth_Cn_Scale, ResizeArea,
}
}

//////////////////////////////////////////////////////////////////////
// ResizeOnnx

PERF_TEST_P(Sz_Depth_Cn_Scale, ResizeOnnxLinearAntialias,
Combine(CUDA_TYPICAL_MAT_SIZES,
Values(CV_8U, CV_16U, CV_32F),
CUDA_CHANNELS_1_3_4,
Values(0.8, 0.5, 0.3)))
{
declare.time(10.0);

const cv::Size size = GET_PARAM(0);
const int depth = GET_PARAM(1);
const int channels = GET_PARAM(2);
const int interpolation = cv::INTER_LINEAR | cv::INTER_ANTIALIAS;
const double f = GET_PARAM(3);
const Point2d scale = Point2d(f, f);

const int type = CV_MAKE_TYPE(depth, channels);

cv::Mat src(size, type);
declare.in(src, WARMUP_RNG);

if (PERF_RUN_CUDA())
{
const cv::cuda::GpuMat d_src(src);
cv::cuda::GpuMat dst;

TEST_CYCLE() cv::cuda::resizeOnnx(d_src, dst, cv::Size(), scale, interpolation);

CUDA_SANITY_CHECK(dst, 1);
}
else
{
cv::Mat dst;

TEST_CYCLE() cv::resizeOnnx(src, dst, cv::Size(), scale, interpolation);

CPU_SANITY_CHECK(dst);
}
}

//////////////////////////////////////////////////////////////////////
// WarpAffine

Expand Down
Loading