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-2020 Intel Corporation
10 #include <opencv2/gapi/core.hpp>
11 #include <opencv2/gapi/ocl/core.hpp>
12 #include "backends/ocl/goclcore.hpp"
14 GAPI_OCL_KERNEL(GOCLAdd, cv::gapi::core::GAdd)
16 static void run(const cv::UMat& a, const cv::UMat& b, int dtype, cv::UMat& out)
18 cv::add(a, b, out, cv::noArray(), dtype);
22 GAPI_OCL_KERNEL(GOCLAddC, cv::gapi::core::GAddC)
24 static void run(const cv::UMat& a, const cv::Scalar& b, int dtype, cv::UMat& out)
26 cv::add(a, b, out, cv::noArray(), dtype);
30 GAPI_OCL_KERNEL(GOCLSub, cv::gapi::core::GSub)
32 static void run(const cv::UMat& a, const cv::UMat& b, int dtype, cv::UMat& out)
34 cv::subtract(a, b, out, cv::noArray(), dtype);
38 GAPI_OCL_KERNEL(GOCLSubC, cv::gapi::core::GSubC)
40 static void run(const cv::UMat& a, const cv::Scalar& b, int dtype, cv::UMat& out)
42 cv::subtract(a, b, out, cv::noArray(), dtype);
46 GAPI_OCL_KERNEL(GOCLSubRC, cv::gapi::core::GSubRC)
48 static void run(const cv::Scalar& a, const cv::UMat& b, int dtype, cv::UMat& out)
50 cv::subtract(a, b, out, cv::noArray(), dtype);
54 GAPI_OCL_KERNEL(GOCLMul, cv::gapi::core::GMul)
56 static void run(const cv::UMat& a, const cv::UMat& b, double scale, int dtype, cv::UMat& out)
58 cv::multiply(a, b, out, scale, dtype);
62 GAPI_OCL_KERNEL(GOCLMulCOld, cv::gapi::core::GMulCOld)
64 static void run(const cv::UMat& a, double b, int dtype, cv::UMat& out)
66 cv::multiply(a, b, out, 1, dtype);
70 GAPI_OCL_KERNEL(GOCLMulC, cv::gapi::core::GMulC)
72 static void run(const cv::UMat& a, const cv::Scalar& b, int dtype, cv::UMat& out)
74 cv::multiply(a, b, out, 1, dtype);
78 GAPI_OCL_KERNEL(GOCLDiv, cv::gapi::core::GDiv)
80 static void run(const cv::UMat& a, const cv::UMat& b, double scale, int dtype, cv::UMat& out)
82 cv::divide(a, b, out, scale, dtype);
86 GAPI_OCL_KERNEL(GOCLDivC, cv::gapi::core::GDivC)
88 static void run(const cv::UMat& a, const cv::Scalar& b, double scale, int dtype, cv::UMat& out)
90 cv::divide(a, b, out, scale, dtype);
94 GAPI_OCL_KERNEL(GOCLDivRC, cv::gapi::core::GDivRC)
96 static void run(const cv::Scalar& a, const cv::UMat& b, double scale, int dtype, cv::UMat& out)
98 cv::divide(a, b, out, scale, dtype);
102 GAPI_OCL_KERNEL(GOCLMask, cv::gapi::core::GMask)
104 static void run(const cv::UMat& in, const cv::UMat& mask, cv::UMat& out)
106 out = cv::UMat::zeros(in.size(), in.type());
107 in.copyTo(out, mask);
112 GAPI_OCL_KERNEL(GOCLMean, cv::gapi::core::GMean)
114 static void run(const cv::UMat& in, cv::Scalar& out)
120 GAPI_OCL_KERNEL(GOCLPolarToCart, cv::gapi::core::GPolarToCart)
122 static void run(const cv::UMat& magn, const cv::UMat& angle, bool angleInDegrees, cv::UMat& outx, cv::UMat& outy)
124 cv::polarToCart(magn, angle, outx, outy, angleInDegrees);
128 GAPI_OCL_KERNEL(GOCLCartToPolar, cv::gapi::core::GCartToPolar)
130 static void run(const cv::UMat& x, const cv::UMat& y, bool angleInDegrees, cv::UMat& outmagn, cv::UMat& outangle)
132 cv::cartToPolar(x, y, outmagn, outangle, angleInDegrees);
136 GAPI_OCL_KERNEL(GOCLCmpGT, cv::gapi::core::GCmpGT)
138 static void run(const cv::UMat& a, const cv::UMat& b, cv::UMat& out)
140 cv::compare(a, b, out, cv::CMP_GT);
144 GAPI_OCL_KERNEL(GOCLCmpGE, cv::gapi::core::GCmpGE)
146 static void run(const cv::UMat& a, const cv::UMat& b, cv::UMat& out)
148 cv::compare(a, b, out, cv::CMP_GE);
152 GAPI_OCL_KERNEL(GOCLCmpLE, cv::gapi::core::GCmpLE)
154 static void run(const cv::UMat& a, const cv::UMat& b, cv::UMat& out)
156 cv::compare(a, b, out, cv::CMP_LE);
160 GAPI_OCL_KERNEL(GOCLCmpLT, cv::gapi::core::GCmpLT)
162 static void run(const cv::UMat& a, const cv::UMat& b, cv::UMat& out)
164 cv::compare(a, b, out, cv::CMP_LT);
168 GAPI_OCL_KERNEL(GOCLCmpEQ, cv::gapi::core::GCmpEQ)
170 static void run(const cv::UMat& a, const cv::UMat& b, cv::UMat& out)
172 cv::compare(a, b, out, cv::CMP_EQ);
176 GAPI_OCL_KERNEL(GOCLCmpNE, cv::gapi::core::GCmpNE)
178 static void run(const cv::UMat& a, const cv::UMat& b, cv::UMat& out)
180 cv::compare(a, b, out, cv::CMP_NE);
184 GAPI_OCL_KERNEL(GOCLCmpGTScalar, cv::gapi::core::GCmpGTScalar)
186 static void run(const cv::UMat& a, const cv::Scalar& b, cv::UMat& out)
188 cv::compare(a, b, out, cv::CMP_GT);
192 GAPI_OCL_KERNEL(GOCLCmpGEScalar, cv::gapi::core::GCmpGEScalar)
194 static void run(const cv::UMat& a, const cv::Scalar& b, cv::UMat& out)
196 cv::compare(a, b, out, cv::CMP_GE);
200 GAPI_OCL_KERNEL(GOCLCmpLEScalar, cv::gapi::core::GCmpLEScalar)
202 static void run(const cv::UMat& a, const cv::Scalar& b, cv::UMat& out)
204 cv::compare(a, b, out, cv::CMP_LE);
208 GAPI_OCL_KERNEL(GOCLCmpLTScalar, cv::gapi::core::GCmpLTScalar)
210 static void run(const cv::UMat& a, const cv::Scalar& b, cv::UMat& out)
212 cv::compare(a, b, out, cv::CMP_LT);
216 GAPI_OCL_KERNEL(GOCLCmpEQScalar, cv::gapi::core::GCmpEQScalar)
218 static void run(const cv::UMat& a, const cv::Scalar& b, cv::UMat& out)
220 cv::compare(a, b, out, cv::CMP_EQ);
224 GAPI_OCL_KERNEL(GOCLCmpNEScalar, cv::gapi::core::GCmpNEScalar)
226 static void run(const cv::UMat& a, const cv::Scalar& b, cv::UMat& out)
228 cv::compare(a, b, out, cv::CMP_NE);
232 GAPI_OCL_KERNEL(GOCLAnd, cv::gapi::core::GAnd)
234 static void run(const cv::UMat& a, const cv::UMat& b, cv::UMat& out)
236 cv::bitwise_and(a, b, out);
240 GAPI_OCL_KERNEL(GOCLAndS, cv::gapi::core::GAndS)
242 static void run(const cv::UMat& a, const cv::Scalar& b, cv::UMat& out)
244 cv::bitwise_and(a, b, out);
248 GAPI_OCL_KERNEL(GOCLOr, cv::gapi::core::GOr)
250 static void run(const cv::UMat& a, const cv::UMat& b, cv::UMat& out)
252 cv::bitwise_or(a, b, out);
256 GAPI_OCL_KERNEL(GOCLOrS, cv::gapi::core::GOrS)
258 static void run(const cv::UMat& a, const cv::Scalar& b, cv::UMat& out)
260 cv::bitwise_or(a, b, out);
264 GAPI_OCL_KERNEL(GOCLXor, cv::gapi::core::GXor)
266 static void run(const cv::UMat& a, const cv::UMat& b, cv::UMat& out)
268 cv::bitwise_xor(a, b, out);
272 GAPI_OCL_KERNEL(GOCLXorS, cv::gapi::core::GXorS)
274 static void run(const cv::UMat& a, const cv::Scalar& b, cv::UMat& out)
276 cv::bitwise_xor(a, b, out);
280 GAPI_OCL_KERNEL(GOCLNot, cv::gapi::core::GNot)
282 static void run(const cv::UMat& a, cv::UMat& out)
284 cv::bitwise_not(a, out);
288 GAPI_OCL_KERNEL(GOCLSelect, cv::gapi::core::GSelect)
290 static void run(const cv::UMat& src1, const cv::UMat& src2, const cv::UMat& mask, cv::UMat& out)
293 src1.copyTo(out, mask);
297 ////TODO: doesn't compiled with UMat
298 //GAPI_OCL_KERNEL(GOCLMin, cv::gapi::core::GMin)
300 // static void run(const cv::UMat& in1, const cv::UMat& in2, cv::UMat& out)
302 // out = cv::min(in1, in2);
306 ////TODO: doesn't compiled with UMat
307 //GAPI_OCL_KERNEL(GOCLMax, cv::gapi::core::GMax)
309 // static void run(const cv::UMat& in1, const cv::UMat& in2, cv::UMat& out)
311 // out = cv::max(in1, in2);
316 GAPI_OCL_KERNEL(GOCLAbsDiff, cv::gapi::core::GAbsDiff)
318 static void run(const cv::UMat& in1, const cv::UMat& in2, cv::UMat& out)
320 cv::absdiff(in1, in2, out);
324 GAPI_OCL_KERNEL(GOCLAbsDiffC, cv::gapi::core::GAbsDiffC)
326 static void run(const cv::UMat& in1, const cv::Scalar& in2, cv::UMat& out)
328 cv::absdiff(in1, in2, out);
332 GAPI_OCL_KERNEL(GOCLSum, cv::gapi::core::GSum)
334 static void run(const cv::UMat& in, cv::Scalar& out)
340 GAPI_OCL_KERNEL(GOCLCountNonZero, cv::gapi::core::GCountNonZero)
342 static void run(const cv::UMat& in, int& out)
344 out = cv::countNonZero(in);
348 GAPI_OCL_KERNEL(GOCLAddW, cv::gapi::core::GAddW)
350 static void run(const cv::UMat& in1, double alpha, const cv::UMat& in2, double beta, double gamma, int dtype, cv::UMat& out)
352 cv::addWeighted(in1, alpha, in2, beta, gamma, out, dtype);
357 GAPI_OCL_KERNEL(GOCLNormL1, cv::gapi::core::GNormL1)
359 static void run(const cv::UMat& in, cv::Scalar& out)
361 out = cv::norm(in, cv::NORM_L1);
365 GAPI_OCL_KERNEL(GOCLNormL2, cv::gapi::core::GNormL2)
367 static void run(const cv::UMat& in, cv::Scalar& out)
369 out = cv::norm(in, cv::NORM_L2);
373 GAPI_OCL_KERNEL(GOCLNormInf, cv::gapi::core::GNormInf)
375 static void run(const cv::UMat& in, cv::Scalar& out)
377 out = cv::norm(in, cv::NORM_INF);
381 GAPI_OCL_KERNEL(GOCLIntegral, cv::gapi::core::GIntegral)
383 static void run(const cv::UMat& in, int sdepth, int sqdepth, cv::UMat& out, cv::UMat& outSq)
385 cv::integral(in, out, outSq, sdepth, sqdepth);
389 GAPI_OCL_KERNEL(GOCLThreshold, cv::gapi::core::GThreshold)
391 static void run(const cv::UMat& in, const cv::Scalar& a, const cv::Scalar& b, int type, cv::UMat& out)
393 cv::threshold(in, out, a.val[0], b.val[0], type);
397 GAPI_OCL_KERNEL(GOCLThresholdOT, cv::gapi::core::GThresholdOT)
399 static void run(const cv::UMat& in, const cv::Scalar& b, int type, cv::UMat& out, cv::Scalar& outScalar)
401 outScalar = cv::threshold(in, out, b.val[0], b.val[0], type);
406 GAPI_OCL_KERNEL(GOCLInRange, cv::gapi::core::GInRange)
408 static void run(const cv::UMat& in, const cv::Scalar& low, const cv::Scalar& up, cv::UMat& out)
410 cv::inRange(in, low, up, out);
414 GAPI_OCL_KERNEL(GOCLSplit3, cv::gapi::core::GSplit3)
416 static void run(const cv::UMat& in, cv::UMat &m1, cv::UMat &m2, cv::UMat &m3)
418 std::vector<cv::UMat> outMats = {m1, m2, m3};
419 cv::split(in, outMats);
421 // Write back FIXME: Write a helper or avoid this nonsense completely!
428 GAPI_OCL_KERNEL(GOCLSplit4, cv::gapi::core::GSplit4)
430 static void run(const cv::UMat& in, cv::UMat &m1, cv::UMat &m2, cv::UMat &m3, cv::UMat &m4)
432 std::vector<cv::UMat> outMats = {m1, m2, m3, m4};
433 cv::split(in, outMats);
435 // Write back FIXME: Write a helper or avoid this nonsense completely!
443 GAPI_OCL_KERNEL(GOCLMerge3, cv::gapi::core::GMerge3)
445 static void run(const cv::UMat& in1, const cv::UMat& in2, const cv::UMat& in3, cv::UMat &out)
447 std::vector<cv::UMat> inMats = {in1, in2, in3};
448 cv::merge(inMats, out);
452 GAPI_OCL_KERNEL(GOCLMerge4, cv::gapi::core::GMerge4)
454 static void run(const cv::UMat& in1, const cv::UMat& in2, const cv::UMat& in3, const cv::UMat& in4, cv::UMat &out)
456 std::vector<cv::UMat> inMats = {in1, in2, in3, in4};
457 cv::merge(inMats, out);
461 GAPI_OCL_KERNEL(GOCLResize, cv::gapi::core::GResize)
463 static void run(const cv::UMat& in, cv::Size sz, double fx, double fy, int interp, cv::UMat &out)
465 cv::resize(in, out, sz, fx, fy, interp);
469 GAPI_OCL_KERNEL(GOCLRemap, cv::gapi::core::GRemap)
471 static void run(const cv::UMat& in, const cv::Mat& x, const cv::Mat& y, int a, int b, cv::Scalar s, cv::UMat& out)
473 cv::remap(in, out, x, y, a, b, s);
477 GAPI_OCL_KERNEL(GOCLFlip, cv::gapi::core::GFlip)
479 static void run(const cv::UMat& in, int code, cv::UMat& out)
481 cv::flip(in, out, code);
485 GAPI_OCL_KERNEL(GOCLCrop, cv::gapi::core::GCrop)
487 static void run(const cv::UMat& in, cv::Rect rect, cv::UMat& out)
489 cv::UMat(in, rect).copyTo(out);
493 GAPI_OCL_KERNEL(GOCLCopy, cv::gapi::core::GCopy)
495 static void run(const cv::UMat& in, cv::UMat& out)
501 GAPI_OCL_KERNEL(GOCLConcatHor, cv::gapi::core::GConcatHor)
503 static void run(const cv::UMat& in1, const cv::UMat& in2, cv::UMat& out)
505 cv::hconcat(in1, in2, out);
509 GAPI_OCL_KERNEL(GOCLConcatVert, cv::gapi::core::GConcatVert)
511 static void run(const cv::UMat& in1, const cv::UMat& in2, cv::UMat& out)
513 cv::vconcat(in1, in2, out);
517 GAPI_OCL_KERNEL(GOCLLUT, cv::gapi::core::GLUT)
519 static void run(const cv::UMat& in, const cv::Mat& lut, cv::UMat& out)
521 cv::LUT(in, lut, out);
525 GAPI_OCL_KERNEL(GOCLConvertTo, cv::gapi::core::GConvertTo)
527 static void run(const cv::UMat& in, int rtype, double alpha, double beta, cv::UMat& out)
529 in.convertTo(out, rtype, alpha, beta);
533 cv::gapi::GKernelPackage cv::gapi::core::ocl::kernels()
535 static auto pkg = cv::gapi::kernels