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 Intel Corporation
10 #include <opencv2/gapi/core.hpp>
11 #include <opencv2/gapi/cpu/core.hpp>
12 #include <opencv2/gapi/cpu/gcpukernel.hpp>
14 GAPI_OCV_KERNEL(GCPUAdd, cv::gapi::core::GAdd)
16 static void run(const cv::Mat& a, const cv::Mat& b, int dtype, cv::Mat& out)
18 cv::add(a, b, out, cv::noArray(), dtype);
22 GAPI_OCV_KERNEL(GCPUAddC, cv::gapi::core::GAddC)
24 static void run(const cv::Mat& a, const cv::Scalar& b, int dtype, cv::Mat& out)
26 cv::add(a, b, out, cv::noArray(), dtype);
30 GAPI_OCV_KERNEL(GCPUSub, cv::gapi::core::GSub)
32 static void run(const cv::Mat& a, const cv::Mat& b, int dtype, cv::Mat& out)
34 cv::subtract(a, b, out, cv::noArray(), dtype);
38 GAPI_OCV_KERNEL(GCPUSubC, cv::gapi::core::GSubC)
40 static void run(const cv::Mat& a, const cv::Scalar& b, int dtype, cv::Mat& out)
42 cv::subtract(a, b, out, cv::noArray(), dtype);
46 GAPI_OCV_KERNEL(GCPUSubRC, cv::gapi::core::GSubRC)
48 static void run(const cv::Scalar& a, const cv::Mat& b, int dtype, cv::Mat& out)
50 cv::subtract(a, b, out, cv::noArray(), dtype);
54 GAPI_OCV_KERNEL(GCPUMul, cv::gapi::core::GMul)
56 static void run(const cv::Mat& a, const cv::Mat& b, double scale, int dtype, cv::Mat& out)
58 cv::multiply(a, b, out, scale, dtype);
62 GAPI_OCV_KERNEL(GCPUMulCOld, cv::gapi::core::GMulCOld)
64 static void run(const cv::Mat& a, double b, int dtype, cv::Mat& out)
66 cv::multiply(a, b, out, 1, dtype);
70 GAPI_OCV_KERNEL(GCPUMulC, cv::gapi::core::GMulC)
72 static void run(const cv::Mat& a, const cv::Scalar& b, int dtype, cv::Mat& out)
74 cv::multiply(a, b, out, 1, dtype);
78 GAPI_OCV_KERNEL(GCPUDiv, cv::gapi::core::GDiv)
80 static void run(const cv::Mat& a, const cv::Mat& b, double scale, int dtype, cv::Mat& out)
82 cv::divide(a, b, out, scale, dtype);
86 GAPI_OCV_KERNEL(GCPUDivC, cv::gapi::core::GDivC)
88 static void run(const cv::Mat& a, const cv::Scalar& b, double scale, int dtype, cv::Mat& out)
90 cv::divide(a, b, out, scale, dtype);
94 GAPI_OCV_KERNEL(GCPUDivRC, cv::gapi::core::GDivRC)
96 static void run(const cv::Scalar& a, const cv::Mat& b, double scale, int dtype, cv::Mat& out)
98 cv::divide(a, b, out, scale, dtype);
102 GAPI_OCV_KERNEL(GCPUMask, cv::gapi::core::GMask)
104 static void run(const cv::Mat& in, const cv::Mat& mask, cv::Mat& out)
106 out = cv::Mat::zeros(in.size(), in.type());
107 in.copyTo(out, mask);
111 GAPI_OCV_KERNEL(GCPUMean, cv::gapi::core::GMean)
113 static void run(const cv::Mat& in, cv::Scalar& out)
119 GAPI_OCV_KERNEL(GCPUPolarToCart, cv::gapi::core::GPolarToCart)
121 static void run(const cv::Mat& magn, const cv::Mat& angle, bool angleInDegrees, cv::Mat& outx, cv::Mat& outy)
123 cv::polarToCart(magn, angle, outx, outy, angleInDegrees);
127 GAPI_OCV_KERNEL(GCPUCartToPolar, cv::gapi::core::GCartToPolar)
129 static void run(const cv::Mat& x, const cv::Mat& y, bool angleInDegrees, cv::Mat& outmagn, cv::Mat& outangle)
131 cv::cartToPolar(x, y, outmagn, outangle, angleInDegrees);
135 GAPI_OCV_KERNEL(GCPUPhase, cv::gapi::core::GPhase)
137 static void run(const cv::Mat &x, const cv::Mat &y, bool angleInDegrees, cv::Mat &out)
139 cv::phase(x, y, out, angleInDegrees);
143 GAPI_OCV_KERNEL(GCPUCmpGT, cv::gapi::core::GCmpGT)
145 static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
147 cv::compare(a, b, out, cv::CMP_GT);
151 GAPI_OCV_KERNEL(GCPUCmpGE, cv::gapi::core::GCmpGE)
153 static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
155 cv::compare(a, b, out, cv::CMP_GE);
159 GAPI_OCV_KERNEL(GCPUCmpLE, cv::gapi::core::GCmpLE)
161 static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
163 cv::compare(a, b, out, cv::CMP_LE);
167 GAPI_OCV_KERNEL(GCPUCmpLT, cv::gapi::core::GCmpLT)
169 static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
171 cv::compare(a, b, out, cv::CMP_LT);
175 GAPI_OCV_KERNEL(GCPUCmpEQ, cv::gapi::core::GCmpEQ)
177 static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
179 cv::compare(a, b, out, cv::CMP_EQ);
183 GAPI_OCV_KERNEL(GCPUCmpNE, cv::gapi::core::GCmpNE)
185 static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
187 cv::compare(a, b, out, cv::CMP_NE);
191 GAPI_OCV_KERNEL(GCPUCmpGTScalar, cv::gapi::core::GCmpGTScalar)
193 static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
195 cv::compare(a, b, out, cv::CMP_GT);
199 GAPI_OCV_KERNEL(GCPUCmpGEScalar, cv::gapi::core::GCmpGEScalar)
201 static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
203 cv::compare(a, b, out, cv::CMP_GE);
207 GAPI_OCV_KERNEL(GCPUCmpLEScalar, cv::gapi::core::GCmpLEScalar)
209 static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
211 cv::compare(a, b, out, cv::CMP_LE);
215 GAPI_OCV_KERNEL(GCPUCmpLTScalar, cv::gapi::core::GCmpLTScalar)
217 static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
219 cv::compare(a, b, out, cv::CMP_LT);
223 GAPI_OCV_KERNEL(GCPUCmpEQScalar, cv::gapi::core::GCmpEQScalar)
225 static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
227 cv::compare(a, b, out, cv::CMP_EQ);
231 GAPI_OCV_KERNEL(GCPUCmpNEScalar, cv::gapi::core::GCmpNEScalar)
233 static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
235 cv::compare(a, b, out, cv::CMP_NE);
239 GAPI_OCV_KERNEL(GCPUAnd, cv::gapi::core::GAnd)
241 static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
243 cv::bitwise_and(a, b, out);
247 GAPI_OCV_KERNEL(GCPUAndS, cv::gapi::core::GAndS)
249 static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
251 cv::bitwise_and(a, b, out);
255 GAPI_OCV_KERNEL(GCPUOr, cv::gapi::core::GOr)
257 static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
259 cv::bitwise_or(a, b, out);
263 GAPI_OCV_KERNEL(GCPUOrS, cv::gapi::core::GOrS)
265 static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
267 cv::bitwise_or(a, b, out);
271 GAPI_OCV_KERNEL(GCPUXor, cv::gapi::core::GXor)
273 static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
275 cv::bitwise_xor(a, b, out);
279 GAPI_OCV_KERNEL(GCPUXorS, cv::gapi::core::GXorS)
281 static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
283 cv::bitwise_xor(a, b, out);
287 GAPI_OCV_KERNEL(GCPUNot, cv::gapi::core::GNot)
289 static void run(const cv::Mat& a, cv::Mat& out)
291 cv::bitwise_not(a, out);
295 GAPI_OCV_KERNEL(GCPUSelect, cv::gapi::core::GSelect)
297 static void run(const cv::Mat& src1, const cv::Mat& src2, const cv::Mat& mask, cv::Mat& out)
300 src1.copyTo(out, mask);
304 GAPI_OCV_KERNEL(GCPUMin, cv::gapi::core::GMin)
306 static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
308 out = cv::min(in1, in2);
312 GAPI_OCV_KERNEL(GCPUMax, cv::gapi::core::GMax)
314 static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
316 out = cv::max(in1, in2);
320 GAPI_OCV_KERNEL(GCPUAbsDiff, cv::gapi::core::GAbsDiff)
322 static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
324 cv::absdiff(in1, in2, out);
328 GAPI_OCV_KERNEL(GCPUAbsDiffC, cv::gapi::core::GAbsDiffC)
330 static void run(const cv::Mat& in1, const cv::Scalar& in2, cv::Mat& out)
332 cv::absdiff(in1, in2, out);
336 GAPI_OCV_KERNEL(GCPUSum, cv::gapi::core::GSum)
338 static void run(const cv::Mat& in, cv::Scalar& out)
344 GAPI_OCV_KERNEL(GCPUAddW, cv::gapi::core::GAddW)
346 static void run(const cv::Mat& in1, double alpha, const cv::Mat& in2, double beta, double gamma, int dtype, cv::Mat& out)
348 cv::addWeighted(in1, alpha, in2, beta, gamma, out, dtype);
352 GAPI_OCV_KERNEL(GCPUNormL1, cv::gapi::core::GNormL1)
354 static void run(const cv::Mat& in, cv::Scalar& out)
356 out = cv::norm(in, cv::NORM_L1);
360 GAPI_OCV_KERNEL(GCPUNormL2, cv::gapi::core::GNormL2)
362 static void run(const cv::Mat& in, cv::Scalar& out)
364 out = cv::norm(in, cv::NORM_L2);
368 GAPI_OCV_KERNEL(GCPUNormInf, cv::gapi::core::GNormInf)
370 static void run(const cv::Mat& in, cv::Scalar& out)
372 out = cv::norm(in, cv::NORM_INF);
376 GAPI_OCV_KERNEL(GCPUIntegral, cv::gapi::core::GIntegral)
378 static void run(const cv::Mat& in, int sdepth, int sqdepth, cv::Mat& out, cv::Mat& outSq)
380 cv::integral(in, out, outSq, sdepth, sqdepth);
384 GAPI_OCV_KERNEL(GCPUThreshold, cv::gapi::core::GThreshold)
386 static void run(const cv::Mat& in, const cv::Scalar& a, const cv::Scalar& b, int type, cv::Mat& out)
388 cv::threshold(in, out, a.val[0], b.val[0], type);
392 GAPI_OCV_KERNEL(GCPUThresholdOT, cv::gapi::core::GThresholdOT)
394 static void run(const cv::Mat& in, const cv::Scalar& b, int type, cv::Mat& out, cv::Scalar& outScalar)
396 outScalar = cv::threshold(in, out, b.val[0], b.val[0], type);
401 GAPI_OCV_KERNEL(GCPUInRange, cv::gapi::core::GInRange)
403 static void run(const cv::Mat& in, const cv::Scalar& low, const cv::Scalar& up, cv::Mat& out)
405 cv::inRange(in, low, up, out);
409 GAPI_OCV_KERNEL(GCPUSplit3, cv::gapi::core::GSplit3)
411 static void run(const cv::Mat& in, cv::Mat &m1, cv::Mat &m2, cv::Mat &m3)
413 std::vector<cv::Mat> outMats = {m1, m2, m3};
414 cv::split(in, outMats);
416 // Write back FIXME: Write a helper or avoid this nonsence completely!
423 GAPI_OCV_KERNEL(GCPUSplit4, cv::gapi::core::GSplit4)
425 static void run(const cv::Mat& in, cv::Mat &m1, cv::Mat &m2, cv::Mat &m3, cv::Mat &m4)
427 std::vector<cv::Mat> outMats = {m1, m2, m3, m4};
428 cv::split(in, outMats);
430 // Write back FIXME: Write a helper or avoid this nonsence completely!
438 GAPI_OCV_KERNEL(GCPUMerge3, cv::gapi::core::GMerge3)
440 static void run(const cv::Mat& in1, const cv::Mat& in2, const cv::Mat& in3, cv::Mat &out)
442 std::vector<cv::Mat> inMats = {in1, in2, in3};
443 cv::merge(inMats, out);
447 GAPI_OCV_KERNEL(GCPUMerge4, cv::gapi::core::GMerge4)
449 static void run(const cv::Mat& in1, const cv::Mat& in2, const cv::Mat& in3, const cv::Mat& in4, cv::Mat &out)
451 std::vector<cv::Mat> inMats = {in1, in2, in3, in4};
452 cv::merge(inMats, out);
456 GAPI_OCV_KERNEL(GCPUResize, cv::gapi::core::GResize)
458 static void run(const cv::Mat& in, cv::Size sz, double fx, double fy, int interp, cv::Mat &out)
460 cv::resize(in, out, sz, fx, fy, interp);
464 GAPI_OCV_KERNEL(GCPUResizeP, cv::gapi::core::GResizeP)
466 static void run(const cv::Mat& in, cv::Size out_sz, int interp, cv::Mat& out)
468 int inH = in.rows / 3;
470 int outH = out.rows / 3;
472 for (int i = 0; i < 3; i++) {
473 auto in_plane = in(cv::Rect(0, i*inH, inW, inH));
474 auto out_plane = out(cv::Rect(0, i*outH, outW, outH));
475 cv::resize(in_plane, out_plane, out_sz, 0, 0, interp);
480 GAPI_OCV_KERNEL(GCPURemap, cv::gapi::core::GRemap)
482 static void run(const cv::Mat& in, const cv::Mat& x, const cv::Mat& y, int a, int b, cv::Scalar s, cv::Mat& out)
484 cv::remap(in, out, x, y, a, b, s);
488 GAPI_OCV_KERNEL(GCPUFlip, cv::gapi::core::GFlip)
490 static void run(const cv::Mat& in, int code, cv::Mat& out)
492 cv::flip(in, out, code);
496 GAPI_OCV_KERNEL(GCPUCrop, cv::gapi::core::GCrop)
498 static void run(const cv::Mat& in, cv::Rect rect, cv::Mat& out)
500 cv::Mat(in, rect).copyTo(out);
504 GAPI_OCV_KERNEL(GCPUConcatHor, cv::gapi::core::GConcatHor)
506 static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
508 cv::hconcat(in1, in2, out);
512 GAPI_OCV_KERNEL(GCPUConcatVert, cv::gapi::core::GConcatVert)
514 static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
516 cv::vconcat(in1, in2, out);
520 GAPI_OCV_KERNEL(GCPULUT, cv::gapi::core::GLUT)
522 static void run(const cv::Mat& in, const cv::Mat& lut, cv::Mat& out)
524 cv::LUT(in, lut, out);
528 GAPI_OCV_KERNEL(GCPUConvertTo, cv::gapi::core::GConvertTo)
530 static void run(const cv::Mat& in, int rtype, double alpha, double beta, cv::Mat& out)
532 in.convertTo(out, rtype, alpha, beta);
536 GAPI_OCV_KERNEL(GCPUSqrt, cv::gapi::core::GSqrt)
538 static void run(const cv::Mat& in, cv::Mat &out)
544 GAPI_OCV_KERNEL(GCPUNormalize, cv::gapi::core::GNormalize)
546 static void run(const cv::Mat& src, double a, double b,
547 int norm_type, int ddepth, cv::Mat& out)
549 cv::normalize(src, out, a, b, norm_type, ddepth);
553 cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()
555 static auto pkg = cv::gapi::kernels