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/core.hpp"
11 #include "opencv2/gapi/gpu/core.hpp"
12 #include "backends/gpu/ggpucore.hpp"
14 GAPI_GPU_KERNEL(GGPUAdd, 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_GPU_KERNEL(GGPUAddC, 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_GPU_KERNEL(GGPUSub, 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_GPU_KERNEL(GGPUSubC, 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_GPU_KERNEL(GGPUSubRC, 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_GPU_KERNEL(GGPUMul, 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_GPU_KERNEL(GGPUMulCOld, 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_GPU_KERNEL(GGPUMulC, 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_GPU_KERNEL(GGPUDiv, 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_GPU_KERNEL(GGPUDivC, 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_GPU_KERNEL(GGPUDivRC, 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_GPU_KERNEL(GGPUMask, 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_GPU_KERNEL(GGPUMean, cv::gapi::core::GMean)
114 static void run(const cv::UMat& in, cv::Scalar& out)
120 GAPI_GPU_KERNEL(GGPUPolarToCart, 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_GPU_KERNEL(GGPUCartToPolar, 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_GPU_KERNEL(GGPUCmpGT, 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_GPU_KERNEL(GGPUCmpGE, 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_GPU_KERNEL(GGPUCmpLE, 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_GPU_KERNEL(GGPUCmpLT, 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_GPU_KERNEL(GGPUCmpEQ, 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_GPU_KERNEL(GGPUCmpNE, 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_GPU_KERNEL(GGPUCmpGTScalar, 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_GPU_KERNEL(GGPUCmpGEScalar, 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_GPU_KERNEL(GGPUCmpLEScalar, 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_GPU_KERNEL(GGPUCmpLTScalar, 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_GPU_KERNEL(GGPUCmpEQScalar, 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_GPU_KERNEL(GGPUCmpNEScalar, 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_GPU_KERNEL(GGPUAnd, 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_GPU_KERNEL(GGPUAndS, 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_GPU_KERNEL(GGPUOr, 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_GPU_KERNEL(GGPUOrS, 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_GPU_KERNEL(GGPUXor, 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_GPU_KERNEL(GGPUXorS, 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_GPU_KERNEL(GGPUNot, cv::gapi::core::GNot)
282 static void run(const cv::UMat& a, cv::UMat& out)
284 cv::bitwise_not(a, out);
288 GAPI_GPU_KERNEL(GGPUSelect, 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_GPU_KERNEL(GGPUMin, 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_GPU_KERNEL(GGPUMax, 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_GPU_KERNEL(GGPUAbsDiff, 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_GPU_KERNEL(GGPUAbsDiffC, 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_GPU_KERNEL(GGPUSum, cv::gapi::core::GSum)
334 static void run(const cv::UMat& in, cv::Scalar& out)
340 GAPI_GPU_KERNEL(GGPUAddW, cv::gapi::core::GAddW)
342 static void run(const cv::UMat& in1, double alpha, const cv::UMat& in2, double beta, double gamma, int dtype, cv::UMat& out)
344 cv::addWeighted(in1, alpha, in2, beta, gamma, out, dtype);
349 GAPI_GPU_KERNEL(GGPUNormL1, cv::gapi::core::GNormL1)
351 static void run(const cv::UMat& in, cv::Scalar& out)
353 out = cv::norm(in, cv::NORM_L1);
357 GAPI_GPU_KERNEL(GGPUNormL2, cv::gapi::core::GNormL2)
359 static void run(const cv::UMat& in, cv::Scalar& out)
361 out = cv::norm(in, cv::NORM_L2);
365 GAPI_GPU_KERNEL(GGPUNormInf, cv::gapi::core::GNormInf)
367 static void run(const cv::UMat& in, cv::Scalar& out)
369 out = cv::norm(in, cv::NORM_INF);
373 GAPI_GPU_KERNEL(GGPUIntegral, cv::gapi::core::GIntegral)
375 static void run(const cv::UMat& in, int sdepth, int sqdepth, cv::UMat& out, cv::UMat& outSq)
377 cv::integral(in, out, outSq, sdepth, sqdepth);
381 GAPI_GPU_KERNEL(GGPUThreshold, cv::gapi::core::GThreshold)
383 static void run(const cv::UMat& in, const cv::Scalar& a, const cv::Scalar& b, int type, cv::UMat& out)
385 cv::threshold(in, out, a.val[0], b.val[0], type);
389 GAPI_GPU_KERNEL(GGPUThresholdOT, cv::gapi::core::GThresholdOT)
391 static void run(const cv::UMat& in, const cv::Scalar& b, int type, cv::UMat& out, cv::Scalar& outScalar)
393 outScalar = cv::threshold(in, out, b.val[0], b.val[0], type);
398 GAPI_GPU_KERNEL(GGPUInRange, cv::gapi::core::GInRange)
400 static void run(const cv::UMat& in, const cv::Scalar& low, const cv::Scalar& up, cv::UMat& out)
402 cv::inRange(in, low, up, out);
406 GAPI_GPU_KERNEL(GGPUSplit3, cv::gapi::core::GSplit3)
408 static void run(const cv::UMat& in, cv::UMat &m1, cv::UMat &m2, cv::UMat &m3)
410 std::vector<cv::UMat> outMats = {m1, m2, m3};
411 cv::split(in, outMats);
413 // Write back FIXME: Write a helper or avoid this nonsence completely!
420 GAPI_GPU_KERNEL(GGPUSplit4, cv::gapi::core::GSplit4)
422 static void run(const cv::UMat& in, cv::UMat &m1, cv::UMat &m2, cv::UMat &m3, cv::UMat &m4)
424 std::vector<cv::UMat> outMats = {m1, m2, m3, m4};
425 cv::split(in, outMats);
427 // Write back FIXME: Write a helper or avoid this nonsence completely!
435 GAPI_GPU_KERNEL(GGPUMerge3, cv::gapi::core::GMerge3)
437 static void run(const cv::UMat& in1, const cv::UMat& in2, const cv::UMat& in3, cv::UMat &out)
439 std::vector<cv::UMat> inMats = {in1, in2, in3};
440 cv::merge(inMats, out);
444 GAPI_GPU_KERNEL(GGPUMerge4, cv::gapi::core::GMerge4)
446 static void run(const cv::UMat& in1, const cv::UMat& in2, const cv::UMat& in3, const cv::UMat& in4, cv::UMat &out)
448 std::vector<cv::UMat> inMats = {in1, in2, in3, in4};
449 cv::merge(inMats, out);
453 GAPI_GPU_KERNEL(GGPUResize, cv::gapi::core::GResize)
455 static void run(const cv::UMat& in, cv::Size sz, double fx, double fy, int interp, cv::UMat &out)
457 cv::resize(in, out, sz, fx, fy, interp);
461 GAPI_GPU_KERNEL(GGPURemap, cv::gapi::core::GRemap)
463 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)
465 cv::remap(in, out, x, y, a, b, s);
469 GAPI_GPU_KERNEL(GGPUFlip, cv::gapi::core::GFlip)
471 static void run(const cv::UMat& in, int code, cv::UMat& out)
473 cv::flip(in, out, code);
477 GAPI_GPU_KERNEL(GGPUCrop, cv::gapi::core::GCrop)
479 static void run(const cv::UMat& in, cv::Rect rect, cv::UMat& out)
481 cv::UMat(in, rect).copyTo(out);
485 GAPI_GPU_KERNEL(GGPUConcatHor, cv::gapi::core::GConcatHor)
487 static void run(const cv::UMat& in1, const cv::UMat& in2, cv::UMat& out)
489 cv::hconcat(in1, in2, out);
493 GAPI_GPU_KERNEL(GGPUConcatVert, cv::gapi::core::GConcatVert)
495 static void run(const cv::UMat& in1, const cv::UMat& in2, cv::UMat& out)
497 cv::vconcat(in1, in2, out);
501 GAPI_GPU_KERNEL(GGPULUT, cv::gapi::core::GLUT)
503 static void run(const cv::UMat& in, const cv::Mat& lut, cv::UMat& out)
505 cv::LUT(in, lut, out);
509 GAPI_GPU_KERNEL(GGPUConvertTo, cv::gapi::core::GConvertTo)
511 static void run(const cv::UMat& in, int rtype, double alpha, double beta, cv::UMat& out)
513 in.convertTo(out, rtype, alpha, beta);
517 cv::gapi::GKernelPackage cv::gapi::core::gpu::kernels()
519 static auto pkg = cv::gapi::kernels