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/cpu/imgproc.hpp"
12 #include "backends/cpu/gcpuimgproc.hpp"
14 GAPI_OCV_KERNEL(GCPUSepFilter, cv::gapi::imgproc::GSepFilter)
16 static void run(const cv::Mat& in, int ddepth, const cv::Mat& kernX, const cv::Mat& kernY, const cv::Point& anchor, const cv::Scalar& delta,
17 int border, const cv::Scalar& bordVal, cv::Mat &out)
19 if( border == cv::BORDER_CONSTANT )
22 int width_add = (kernY.cols - 1) / 2;
23 int height_add = (kernX.rows - 1) / 2;
24 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, border, bordVal);
25 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
26 cv::sepFilter2D(temp_in(rect), out, ddepth, kernX, kernY, anchor, delta.val[0], border);
29 cv::sepFilter2D(in, out, ddepth, kernX, kernY, anchor, delta.val[0], border);
33 GAPI_OCV_KERNEL(GCPUBoxFilter, cv::gapi::imgproc::GBoxFilter)
35 static void run(const cv::Mat& in, int ddepth, const cv::Size& ksize, const cv::Point& anchor, bool normalize, int borderType, const cv::Scalar& bordVal, cv::Mat &out)
37 if( borderType == cv::BORDER_CONSTANT )
40 int width_add = (ksize.width - 1) / 2;
41 int height_add = (ksize.height - 1) / 2;
42 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, borderType, bordVal);
43 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
44 cv::boxFilter(temp_in(rect), out, ddepth, ksize, anchor, normalize, borderType);
47 cv::boxFilter(in, out, ddepth, ksize, anchor, normalize, borderType);
51 GAPI_OCV_KERNEL(GCPUBlur, cv::gapi::imgproc::GBlur)
53 static void run(const cv::Mat& in, const cv::Size& ksize, const cv::Point& anchor, int borderType, const cv::Scalar& bordVal, cv::Mat &out)
55 if( borderType == cv::BORDER_CONSTANT )
58 int width_add = (ksize.width - 1) / 2;
59 int height_add = (ksize.height - 1) / 2;
60 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, borderType, bordVal);
61 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
62 cv::blur(temp_in(rect), out, ksize, anchor, borderType);
65 cv::blur(in, out, ksize, anchor, borderType);
70 GAPI_OCV_KERNEL(GCPUFilter2D, cv::gapi::imgproc::GFilter2D)
72 static void run(const cv::Mat& in, int ddepth, const cv::Mat& k, const cv::Point& anchor, const cv::Scalar& delta, int border,
73 const cv::Scalar& bordVal, cv::Mat &out)
75 if( border == cv::BORDER_CONSTANT )
78 int width_add = (k.cols - 1) / 2;
79 int height_add = (k.rows - 1) / 2;
80 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, border, bordVal );
81 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
82 cv::filter2D(temp_in(rect), out, ddepth, k, anchor, delta.val[0], border);
85 cv::filter2D(in, out, ddepth, k, anchor, delta.val[0], border);
89 GAPI_OCV_KERNEL(GCPUGaussBlur, cv::gapi::imgproc::GGaussBlur)
91 static void run(const cv::Mat& in, const cv::Size& ksize, double sigmaX, double sigmaY, int borderType, const cv::Scalar& bordVal, cv::Mat &out)
93 if( borderType == cv::BORDER_CONSTANT )
96 int width_add = (ksize.width - 1) / 2;
97 int height_add = (ksize.height - 1) / 2;
98 cv::copyMakeBorder(in, temp_in, height_add, height_add, width_add, width_add, borderType, bordVal );
99 cv::Rect rect = cv::Rect(height_add, width_add, in.cols, in.rows);
100 cv::GaussianBlur(temp_in(rect), out, ksize, sigmaX, sigmaY, borderType);
103 cv::GaussianBlur(in, out, ksize, sigmaX, sigmaY, borderType);
107 GAPI_OCV_KERNEL(GCPUMedianBlur, cv::gapi::imgproc::GMedianBlur)
109 static void run(const cv::Mat& in, int ksize, cv::Mat &out)
111 cv::medianBlur(in, out, ksize);
115 GAPI_OCV_KERNEL(GCPUErode, cv::gapi::imgproc::GErode)
117 static void run(const cv::Mat& in, const cv::Mat& kernel, const cv::Point& anchor, int iterations, int borderType, const cv::Scalar& borderValue, cv::Mat &out)
119 cv::erode(in, out, kernel, anchor, iterations, borderType, borderValue);
123 GAPI_OCV_KERNEL(GCPUDilate, cv::gapi::imgproc::GDilate)
125 static void run(const cv::Mat& in, const cv::Mat& kernel, const cv::Point& anchor, int iterations, int borderType, const cv::Scalar& borderValue, cv::Mat &out)
127 cv::dilate(in, out, kernel, anchor, iterations, borderType, borderValue);
131 GAPI_OCV_KERNEL(GCPUSobel, cv::gapi::imgproc::GSobel)
133 static void run(const cv::Mat& in, int ddepth, int dx, int dy, int ksize, double scale, double delta, int borderType,
134 const cv::Scalar& bordVal, cv::Mat &out)
136 if( borderType == cv::BORDER_CONSTANT )
139 int add = (ksize - 1) / 2;
140 cv::copyMakeBorder(in, temp_in, add, add, add, add, borderType, bordVal );
141 cv::Rect rect = cv::Rect(add, add, in.cols, in.rows);
142 cv::Sobel(temp_in(rect), out, ddepth, dx, dy, ksize, scale, delta, borderType);
145 cv::Sobel(in, out, ddepth, dx, dy, ksize, scale, delta, borderType);
149 GAPI_OCV_KERNEL(GCPUEqualizeHist, cv::gapi::imgproc::GEqHist)
151 static void run(const cv::Mat& in, cv::Mat &out)
153 cv::equalizeHist(in, out);
157 GAPI_OCV_KERNEL(GCPUCanny, cv::gapi::imgproc::GCanny)
159 static void run(const cv::Mat& in, double thr1, double thr2, int apSize, bool l2gradient, cv::Mat &out)
161 cv::Canny(in, out, thr1, thr2, apSize, l2gradient);
165 GAPI_OCV_KERNEL(GCPURGB2YUV, cv::gapi::imgproc::GRGB2YUV)
167 static void run(const cv::Mat& in, cv::Mat &out)
169 cv::cvtColor(in, out, cv::COLOR_RGB2YUV);
173 GAPI_OCV_KERNEL(GCPUYUV2RGB, cv::gapi::imgproc::GYUV2RGB)
175 static void run(const cv::Mat& in, cv::Mat &out)
177 cv::cvtColor(in, out, cv::COLOR_YUV2RGB);
181 GAPI_OCV_KERNEL(GCPURGB2Lab, cv::gapi::imgproc::GRGB2Lab)
183 static void run(const cv::Mat& in, cv::Mat &out)
185 cv::cvtColor(in, out, cv::COLOR_RGB2Lab);
189 GAPI_OCV_KERNEL(GCPUBGR2LUV, cv::gapi::imgproc::GBGR2LUV)
191 static void run(const cv::Mat& in, cv::Mat &out)
193 cv::cvtColor(in, out, cv::COLOR_BGR2Luv);
197 GAPI_OCV_KERNEL(GCPUBGR2YUV, cv::gapi::imgproc::GBGR2YUV)
199 static void run(const cv::Mat& in, cv::Mat &out)
201 cv::cvtColor(in, out, cv::COLOR_BGR2YUV);
205 GAPI_OCV_KERNEL(GCPULUV2BGR, cv::gapi::imgproc::GLUV2BGR)
207 static void run(const cv::Mat& in, cv::Mat &out)
209 cv::cvtColor(in, out, cv::COLOR_Luv2BGR);
213 GAPI_OCV_KERNEL(GCPUYUV2BGR, cv::gapi::imgproc::GYUV2BGR)
215 static void run(const cv::Mat& in, cv::Mat &out)
217 cv::cvtColor(in, out, cv::COLOR_YUV2BGR);
221 GAPI_OCV_KERNEL(GCPURGB2Gray, cv::gapi::imgproc::GRGB2Gray)
223 static void run(const cv::Mat& in, cv::Mat &out)
225 cv::cvtColor(in, out, cv::COLOR_RGB2GRAY);
229 GAPI_OCV_KERNEL(GCPUBGR2Gray, cv::gapi::imgproc::GBGR2Gray)
231 static void run(const cv::Mat& in, cv::Mat &out)
233 cv::cvtColor(in, out, cv::COLOR_BGR2GRAY);
237 GAPI_OCV_KERNEL(GCPURGB2GrayCustom, cv::gapi::imgproc::GRGB2GrayCustom)
239 static void run(const cv::Mat& in, float rY, float bY, float gY, cv::Mat &out)
242 cv::split(in, planes);
243 out = planes[0]*rY + planes[1]*bY + planes[2]*gY;
247 cv::gapi::GKernelPackage cv::gapi::imgproc::cpu::kernels()
249 static auto pkg = cv::gapi::kernels