Merge pull request #18451 from OrestChura:oc/count_non_zero
[platform/upstream/opencv.git] / modules / gapi / src / api / kernels_core.cpp
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.
4 //
5 // Copyright (C) 2018-2020 Intel Corporation
6
7
8 #include "precomp.hpp"
9
10 #include <opencv2/gapi/gcall.hpp>
11 #include <opencv2/gapi/gscalar.hpp>
12 #include <opencv2/gapi/gkernel.hpp>
13 #include <opencv2/gapi/core.hpp>
14
15 #include <tuple>
16 #include <numeric>
17
18 namespace cv { namespace gapi {
19
20 GMat add(const GMat& src1, const GMat& src2, int dtype)
21 {
22     return core::GAdd::on(src1, src2, dtype);
23 }
24
25 GMat addC(const GMat& src1, const GScalar& c, int dtype)
26 {
27     return core::GAddC::on(src1, c, dtype);
28 }
29
30 GMat addC(const GScalar& c, const GMat& src1, int dtype)
31 {
32     return core::GAddC::on(src1, c, dtype);
33 }
34
35 GMat sub(const GMat& src1, const GMat& src2, int dtype)
36 {
37     return core::GSub::on(src1, src2, dtype);
38 }
39
40 GMat subC(const GMat& src1, const GScalar& c, int dtype)
41 {
42     return core::GSubC::on(src1, c, dtype);
43 }
44
45 GMat subRC(const GScalar& c, const GMat& src, int dtype)
46 {
47     return core::GSubRC::on(c, src, dtype);
48 }
49
50 GMat mul(const GMat& src1, const GMat& src2, double scale, int dtype)
51 {
52     return core::GMul::on(src1, src2, scale, dtype);
53 }
54
55 GMat mulC(const GMat& src, double scale, int dtype)
56 {
57     return core::GMulCOld::on(src, scale, dtype);
58 }
59
60 GMat mulC(const GMat& src, const GScalar& multiplier, int dtype)
61 {
62     return core::GMulC::on(src, multiplier, dtype);
63 }
64
65 GMat mulC(const GScalar& multiplier, const GMat& src, int dtype)
66 {
67     return core::GMulC::on(src, multiplier, dtype);
68 }
69
70 GMat div(const GMat& src1, const GMat& src2, double scale, int dtype)
71 {
72     return core::GDiv::on(src1, src2, scale, dtype);
73 }
74
75 GMat divC(const GMat& src, const GScalar& divisor, double scale, int dtype)
76 {
77     return core::GDivC::on(src, divisor, scale, dtype);
78 }
79
80 GMat divRC(const GScalar& divident, const GMat& src, double scale, int dtype)
81 {
82     return core::GDivRC::on(divident, src, scale, dtype);
83 }
84
85 GScalar mean(const GMat& src)
86 {
87     return core::GMean::on(src);
88 }
89
90 GMat mask(const GMat& src, const GMat& mask)
91 {
92     return core::GMask::on(src, mask);
93 }
94
95 std::tuple<GMat, GMat> polarToCart(const GMat& magnitude, const GMat& angle,
96                                    bool angleInDegrees)
97 {
98     return core::GPolarToCart::on(magnitude, angle, angleInDegrees);
99 }
100
101 std::tuple<GMat, GMat> cartToPolar(const GMat& x, const GMat& y,
102                                    bool angleInDegrees)
103 {
104     return core::GCartToPolar::on(x, y, angleInDegrees);
105 }
106
107 GMat phase(const GMat &x, const GMat &y, bool angleInDegrees)
108 {
109     return core::GPhase::on(x, y, angleInDegrees);
110 }
111
112 GMat cmpGT(const GMat& src1, const GMat& src2)
113 {
114     return core::GCmpGT::on(src1, src2);
115 }
116
117 GMat cmpLT(const GMat& src1, const GMat& src2)
118 {
119     return core::GCmpLT::on(src1, src2);
120 }
121
122 GMat cmpGE(const GMat& src1, const GMat& src2)
123 {
124     return core::GCmpGE::on(src1, src2);
125 }
126
127 GMat cmpLE(const GMat& src1, const GMat& src2)
128 {
129     return core::GCmpLE::on(src1, src2);
130 }
131
132 GMat cmpEQ(const GMat& src1, const GMat& src2)
133 {
134     return core::GCmpEQ::on(src1, src2);
135 }
136
137 GMat cmpNE(const GMat& src1, const GMat& src2)
138 {
139     return core::GCmpNE::on(src1, src2);
140 }
141
142 GMat cmpGT(const GMat& src1, const GScalar& src2)
143 {
144     return core::GCmpGTScalar::on(src1, src2);
145 }
146
147 GMat cmpLT(const GMat& src1, const GScalar& src2)
148 {
149     return core::GCmpLTScalar::on(src1, src2);
150 }
151
152 GMat cmpGE(const GMat& src1, const GScalar& src2)
153 {
154     return core::GCmpGEScalar::on(src1, src2);
155 }
156
157 GMat cmpLE(const GMat& src1, const GScalar& src2)
158 {
159     return core::GCmpLEScalar::on(src1, src2);
160 }
161
162 GMat cmpEQ(const GMat& src1, const GScalar& src2)
163 {
164     return core::GCmpEQScalar::on(src1, src2);
165 }
166
167 GMat cmpNE(const GMat& src1, const GScalar& src2)
168 {
169     return core::GCmpNEScalar::on(src1, src2);
170 }
171
172 GMat min(const GMat& src1, const GMat& src2)
173 {
174     return core::GMin::on(src1, src2);
175 }
176
177 GMat max(const GMat& src1, const GMat& src2)
178 {
179     return core::GMax::on(src1, src2);
180 }
181
182 GMat absDiff(const GMat& src1, const GMat& src2)
183 {
184     return core::GAbsDiff::on(src1, src2);
185 }
186
187 GMat absDiffC(const GMat& src, const GScalar& c)
188 {
189     return core::GAbsDiffC::on(src, c);
190 }
191
192 GMat bitwise_and(const GMat& src1, const GMat& src2)
193 {
194     return core::GAnd::on(src1, src2);
195 }
196
197 GMat bitwise_and(const GMat& src1, const GScalar& src2)
198 {
199     return core::GAndS::on(src1, src2);
200 }
201
202 GMat bitwise_or(const GMat& src1, const GMat& src2)
203 {
204     return core::GOr::on(src1, src2);
205 }
206
207 GMat bitwise_or(const GMat& src1, const GScalar& src2)
208 {
209     return core::GOrS::on(src1, src2);
210 }
211
212 GMat bitwise_xor(const GMat& src1, const GMat& src2)
213 {
214     return core::GXor::on(src1, src2);
215 }
216
217 GMat bitwise_xor(const GMat& src1, const GScalar& src2)
218 {
219     return core::GXorS::on(src1, src2);
220 }
221
222 GMat bitwise_not(const GMat& src1)
223 {
224     return core::GNot::on(src1);
225 }
226
227 GMat select(const GMat& src1, const GMat& src2, const GMat& mask)
228 {
229     return core::GSelect::on(src1, src2, mask);
230 }
231
232 GScalar sum(const GMat& src)
233 {
234     return core::GSum::on(src);
235 }
236
237 GOpaque<int> countNonZero(const GMat& src)
238 {
239     return core::GCountNonZero::on(src);
240 }
241
242 GMat addWeighted(const GMat& src1, double alpha, const GMat& src2, double beta, double gamma, int dtype)
243 {
244     return core::GAddW::on(src1, alpha, src2, beta, gamma, dtype);
245 }
246
247 GScalar normL1(const GMat& src)
248 {
249     return core::GNormL1::on(src);
250 }
251
252 GScalar normL2(const GMat& src)
253 {
254     return core::GNormL2::on(src);
255 }
256
257 GScalar normInf(const GMat& src)
258 {
259     return core::GNormInf::on(src);
260 }
261
262 std::tuple<GMat, GMat> integral(const GMat& src, int sdepth, int sqdepth)
263 {
264     return core::GIntegral::on(src, sdepth, sqdepth);
265 }
266
267 GMat threshold(const GMat& src, const GScalar& thresh, const GScalar& maxval, int type)
268 {
269     GAPI_Assert(type != cv::THRESH_TRIANGLE && type != cv::THRESH_OTSU);
270     return core::GThreshold::on(src, thresh, maxval, type);
271 }
272
273 std::tuple<GMat, GScalar> threshold(const GMat& src, const GScalar& maxval, int type)
274 {
275     GAPI_Assert(type == cv::THRESH_TRIANGLE || type == cv::THRESH_OTSU);
276     return core::GThresholdOT::on(src, maxval, type);
277 }
278
279 GMat inRange(const GMat& src, const GScalar& threshLow, const GScalar& threshUp)
280 {
281     return core::GInRange::on(src, threshLow, threshUp);
282 }
283
284 std::tuple<GMat, GMat, GMat> split3(const GMat& src)
285 {
286     return core::GSplit3::on(src);
287 }
288
289 std::tuple<GMat, GMat, GMat, GMat> split4(const GMat& src)
290 {
291     return core::GSplit4::on(src);
292 }
293
294 GMat merge3(const GMat& src1, const GMat& src2, const GMat& src3)
295 {
296     return core::GMerge3::on(src1, src2, src3);
297 }
298
299 GMat merge4(const GMat& src1, const GMat& src2, const GMat& src3, const GMat& src4)
300 {
301     return core::GMerge4::on(src1, src2, src3, src4);
302 }
303
304 GMat resize(const GMat& src, const Size& dsize, double fx, double fy, int interpolation)
305 {
306     return core::GResize::on(src, dsize, fx, fy, interpolation);
307 }
308
309 GMatP resizeP(const GMatP& src, const Size& dsize, int interpolation)
310 {
311     return core::GResizeP::on(src, dsize, interpolation);
312 }
313
314 GMat remap(const GMat& src, const Mat& map1, const Mat& map2,
315            int interpolation, int borderMode,
316            const Scalar& borderValue)
317 {
318     return core::GRemap::on(src, map1, map2, interpolation, borderMode, borderValue);
319 }
320
321 GMat flip(const GMat& src, int flipCode)
322 {
323     return core::GFlip::on(src, flipCode);
324 }
325
326 GMat crop(const GMat& src, const Rect& rect)
327 {
328     return core::GCrop::on(src, rect);
329 }
330
331 GMat copy(const GMat& src)
332 {
333     return core::GCopy::on(src);
334 }
335
336 GMat concatHor(const GMat& src1, const GMat& src2)
337 {
338     return core::GConcatHor::on(src1, src2);
339 }
340
341 GMat concatHor(const std::vector<GMat>& v)
342 {
343     GAPI_Assert(v.size() >= 2);
344     return std::accumulate(v.begin()+1, v.end(), v[0], core::GConcatHor::on);
345 }
346
347 GMat concatVert(const GMat& src1, const GMat& src2)
348 {
349     return core::GConcatVert::on(src1, src2);
350 }
351
352 GMat concatVert(const std::vector<GMat>& v)
353 {
354     GAPI_Assert(v.size() >= 2);
355     return std::accumulate(v.begin()+1, v.end(), v[0], core::GConcatVert::on);
356 }
357
358 GMat LUT(const GMat& src, const Mat& lut)
359 {
360     return core::GLUT::on(src, lut);
361 }
362
363 GMat convertTo(const GMat& m, int rtype, double alpha, double beta)
364 {
365     return core::GConvertTo::on(m, rtype, alpha, beta);
366 }
367
368 GMat sqrt(const GMat& src)
369 {
370     return core::GSqrt::on(src);
371 }
372
373 GMat normalize(const GMat& _src, double a, double b,
374                int norm_type, int ddepth)
375 {
376     return core::GNormalize::on(_src, a, b, norm_type, ddepth);
377 }
378
379 GMat warpPerspective(const GMat& src, const Mat& M, const Size& dsize, int flags,
380                      int borderMode, const Scalar& borderValue)
381 {
382     return core::GWarpPerspective::on(src, M, dsize, flags, borderMode, borderValue);
383 }
384
385 GMat warpAffine(const GMat& src, const Mat& M, const Size& dsize, int flags,
386                 int borderMode, const Scalar& borderValue)
387 {
388     return core::GWarpAffine::on(src, M, dsize, flags, borderMode, borderValue);
389 }
390
391 GOpaque<Size> size(const GMat& src)
392 {
393     return core::GSize::on(src);
394 }
395
396 GOpaque<Size> size(const GOpaque<Rect>& r)
397 {
398     return core::GSizeR::on(r);
399 }
400
401 } //namespace gapi
402 } //namespace cv