1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
5 #ifndef OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_RESIZE_HPP
6 #define OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_RESIZE_HPP
8 #include "../../op_cuda.hpp"
10 #include "../csl/stream.hpp"
12 #include "../kernels/resize.hpp"
16 namespace cv { namespace dnn { namespace cuda4dnn {
18 enum class InterpolationType {
24 class ResizeOp final : public CUDABackendNode {
26 using wrapper_type = GetCUDABackendWrapperType<T>;
28 ResizeOp(csl::Stream stream_, InterpolationType type_, float scaleHeight_, float scaleWidth_)
29 : stream(std::move(stream_)), type{ type_ }, scaleHeight{ scaleHeight_ }, scaleWidth{ scaleWidth_ }
34 const std::vector<cv::Ptr<BackendWrapper>>& inputs,
35 const std::vector<cv::Ptr<BackendWrapper>>& outputs,
36 csl::Workspace& workspace) override
38 CV_Assert(inputs.size() == 1 && outputs.size() == 1);
40 auto input_wrapper = inputs[0].dynamicCast<wrapper_type>();
41 auto input = input_wrapper->getView();
43 auto output_wrapper = outputs[0].dynamicCast<wrapper_type>();
44 auto output = output_wrapper->getSpan();
46 if (type == InterpolationType::NEAREST_NEIGHBOUR)
47 kernels::resize_nn<T>(stream, output, input);
48 else if (type == InterpolationType::BILINEAR)
49 kernels::resize_bilinear<T>(stream, output, input, scaleHeight, scaleWidth);
54 InterpolationType type;
55 float scaleHeight, scaleWidth; /* for bilinear interpolation */
58 }}} /* namespace cv::dnn::cuda4dnn */
60 #endif /* OPENCV_DNN_SRC_CUDA4DNN_PRIMITIVES_RESIZE_HPP */