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 // Copyright (C) 2018-2019 Intel Corporation
10 #include "opencv2/gapi/imgproc.hpp"
11 #include "opencv2/gapi/gpu/imgproc.hpp"
12 #include "backends/gpu/ggpuimgproc.hpp"
15 GAPI_GPU_KERNEL(GGPUSepFilter, cv::gapi::imgproc::GSepFilter)
17 static void run(const cv::UMat& in, int ddepth, const cv::Mat& kernX, const cv::Mat& kernY, const cv::Point& anchor, const cv::Scalar& delta,
18 int border, const cv::Scalar& bordVal, cv::UMat &out)
20 if( border == cv::BORDER_CONSTANT )
23 int width_add = (kernY.cols - 1) / 2;
24 int height_add = (kernX.rows - 1) / 2;
25 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, border, bordVal);
26 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
27 cv::sepFilter2D(temp_in(rect), out, ddepth, kernX, kernY, anchor, delta.val[0], border);
30 cv::sepFilter2D(in, out, ddepth, kernX, kernY, anchor, delta.val[0], border);
34 GAPI_GPU_KERNEL(GGPUBoxFilter, cv::gapi::imgproc::GBoxFilter)
36 static void run(const cv::UMat& in, int ddepth, const cv::Size& ksize, const cv::Point& anchor, bool normalize, int borderType, const cv::Scalar& bordVal, cv::UMat &out)
38 if( borderType == cv::BORDER_CONSTANT )
41 int width_add = (ksize.width - 1) / 2;
42 int height_add = (ksize.height - 1) / 2;
43 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, borderType, bordVal);
44 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
45 cv::boxFilter(temp_in(rect), out, ddepth, ksize, anchor, normalize, borderType);
48 cv::boxFilter(in, out, ddepth, ksize, anchor, normalize, borderType);
52 GAPI_GPU_KERNEL(GGPUBlur, cv::gapi::imgproc::GBlur)
54 static void run(const cv::UMat& in, const cv::Size& ksize, const cv::Point& anchor, int borderType, const cv::Scalar& bordVal, cv::UMat &out)
56 if( borderType == cv::BORDER_CONSTANT )
59 int width_add = (ksize.width - 1) / 2;
60 int height_add = (ksize.height - 1) / 2;
61 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, borderType, bordVal);
62 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
63 cv::blur(temp_in(rect), out, ksize, anchor, borderType);
66 cv::blur(in, out, ksize, anchor, borderType);
71 GAPI_GPU_KERNEL(GGPUFilter2D, cv::gapi::imgproc::GFilter2D)
73 static void run(const cv::UMat& in, int ddepth, const cv::Mat& k, const cv::Point& anchor, const cv::Scalar& delta, int border,
74 const cv::Scalar& bordVal, cv::UMat &out)
76 if( border == cv::BORDER_CONSTANT )
79 int width_add = (k.cols - 1) / 2;
80 int height_add = (k.rows - 1) / 2;
81 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, border, bordVal );
82 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
83 cv::filter2D(temp_in(rect), out, ddepth, k, anchor, delta.val[0], border);
86 cv::filter2D(in, out, ddepth, k, anchor, delta.val[0], border);
90 GAPI_GPU_KERNEL(GGPUGaussBlur, cv::gapi::imgproc::GGaussBlur)
92 static void run(const cv::UMat& in, const cv::Size& ksize, double sigmaX, double sigmaY, int borderType, const cv::Scalar& bordVal, cv::UMat &out)
94 if( borderType == cv::BORDER_CONSTANT )
97 int width_add = (ksize.width - 1) / 2;
98 int height_add = (ksize.height - 1) / 2;
99 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, borderType, bordVal );
100 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
101 cv::GaussianBlur(temp_in(rect), out, ksize, sigmaX, sigmaY, borderType);
104 cv::GaussianBlur(in, out, ksize, sigmaX, sigmaY, borderType);
108 GAPI_GPU_KERNEL(GGPUMedianBlur, cv::gapi::imgproc::GMedianBlur)
110 static void run(const cv::UMat& in, int ksize, cv::UMat &out)
112 cv::medianBlur(in, out, ksize);
116 GAPI_GPU_KERNEL(GGPUErode, cv::gapi::imgproc::GErode)
118 static void run(const cv::UMat& in, const cv::Mat& kernel, const cv::Point& anchor, int iterations, int borderType, const cv::Scalar& borderValue, cv::UMat &out)
120 cv::erode(in, out, kernel, anchor, iterations, borderType, borderValue);
124 GAPI_GPU_KERNEL(GGPUDilate, cv::gapi::imgproc::GDilate)
126 static void run(const cv::UMat& in, const cv::Mat& kernel, const cv::Point& anchor, int iterations, int borderType, const cv::Scalar& borderValue, cv::UMat &out)
128 cv::dilate(in, out, kernel, anchor, iterations, borderType, borderValue);
132 GAPI_GPU_KERNEL(GGPUSobel, cv::gapi::imgproc::GSobel)
134 static void run(const cv::UMat& in, int ddepth, int dx, int dy, int ksize, double scale, double delta, int borderType,
135 const cv::Scalar& bordVal, cv::UMat &out)
137 if( borderType == cv::BORDER_CONSTANT )
140 int add = (ksize - 1) / 2;
141 cv::copyMakeBorder(in, temp_in, add, add, add, add, borderType, bordVal );
142 cv::Rect rect = cv::Rect(add, add, in.cols, in.rows);
143 cv::Sobel(temp_in(rect), out, ddepth, dx, dy, ksize, scale, delta, borderType);
146 cv::Sobel(in, out, ddepth, dx, dy, ksize, scale, delta, borderType);
150 GAPI_GPU_KERNEL(GGPUEqualizeHist, cv::gapi::imgproc::GEqHist)
152 static void run(const cv::UMat& in, cv::UMat &out)
154 cv::equalizeHist(in, out);
158 GAPI_GPU_KERNEL(GGPUCanny, cv::gapi::imgproc::GCanny)
160 static void run(const cv::UMat& in, double thr1, double thr2, int apSize, bool l2gradient, cv::UMat &out)
162 cv::Canny(in, out, thr1, thr2, apSize, l2gradient);
166 GAPI_GPU_KERNEL(GGPURGB2YUV, cv::gapi::imgproc::GRGB2YUV)
168 static void run(const cv::UMat& in, cv::UMat &out)
170 cv::cvtColor(in, out, cv::COLOR_RGB2YUV);
174 GAPI_GPU_KERNEL(GGPUYUV2RGB, cv::gapi::imgproc::GYUV2RGB)
176 static void run(const cv::UMat& in, cv::UMat &out)
178 cv::cvtColor(in, out, cv::COLOR_YUV2RGB);
182 GAPI_GPU_KERNEL(GGPURGB2Lab, cv::gapi::imgproc::GRGB2Lab)
184 static void run(const cv::UMat& in, cv::UMat &out)
186 cv::cvtColor(in, out, cv::COLOR_RGB2Lab);
190 GAPI_GPU_KERNEL(GGPUBGR2LUV, cv::gapi::imgproc::GBGR2LUV)
192 static void run(const cv::UMat& in, cv::UMat &out)
194 cv::cvtColor(in, out, cv::COLOR_BGR2Luv);
198 GAPI_GPU_KERNEL(GGPUBGR2YUV, cv::gapi::imgproc::GBGR2YUV)
200 static void run(const cv::UMat& in, cv::UMat &out)
202 cv::cvtColor(in, out, cv::COLOR_BGR2YUV);
206 GAPI_GPU_KERNEL(GGPULUV2BGR, cv::gapi::imgproc::GLUV2BGR)
208 static void run(const cv::UMat& in, cv::UMat &out)
210 cv::cvtColor(in, out, cv::COLOR_Luv2BGR);
214 GAPI_GPU_KERNEL(GGPUYUV2BGR, cv::gapi::imgproc::GYUV2BGR)
216 static void run(const cv::UMat& in, cv::UMat &out)
218 cv::cvtColor(in, out, cv::COLOR_YUV2BGR);
222 GAPI_GPU_KERNEL(GGPURGB2Gray, cv::gapi::imgproc::GRGB2Gray)
224 static void run(const cv::UMat& in, cv::UMat &out)
226 cv::cvtColor(in, out, cv::COLOR_RGB2GRAY);
230 GAPI_GPU_KERNEL(GGPUBGR2Gray, cv::gapi::imgproc::GBGR2Gray)
232 static void run(const cv::UMat& in, cv::UMat &out)
234 cv::cvtColor(in, out, cv::COLOR_BGR2GRAY);
238 GAPI_GPU_KERNEL(GGPURGB2GrayCustom, cv::gapi::imgproc::GRGB2GrayCustom)
241 static void run(const cv::UMat& in, float rY, float bY, float gY, cv::UMat &out)
244 cv::split(in.getMat(cv::ACCESS_READ), planes);
245 cv::Mat tmp_out = (planes[0]*rY + planes[1]*bY + planes[2]*gY);
251 cv::gapi::GKernelPackage cv::gapi::imgproc::gpu::kernels()
253 static auto pkg = cv::gapi::kernels