Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/gapi/src/backends/cpu/gcpucore.cpp
16344 views
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 Intel Corporation
6
7
8
#include "precomp.hpp"
9
10
#include "opencv2/gapi/core.hpp"
11
#include "opencv2/gapi/cpu/core.hpp"
12
#include "backends/cpu/gcpucore.hpp"
13
14
GAPI_OCV_KERNEL(GCPUAdd, cv::gapi::core::GAdd)
15
{
16
static void run(const cv::Mat& a, const cv::Mat& b, int dtype, cv::Mat& out)
17
{
18
cv::add(a, b, out, cv::noArray(), dtype);
19
}
20
};
21
22
GAPI_OCV_KERNEL(GCPUAddC, cv::gapi::core::GAddC)
23
{
24
static void run(const cv::Mat& a, const cv::Scalar& b, int dtype, cv::Mat& out)
25
{
26
cv::add(a, b, out, cv::noArray(), dtype);
27
}
28
};
29
30
GAPI_OCV_KERNEL(GCPUSub, cv::gapi::core::GSub)
31
{
32
static void run(const cv::Mat& a, const cv::Mat& b, int dtype, cv::Mat& out)
33
{
34
cv::subtract(a, b, out, cv::noArray(), dtype);
35
}
36
};
37
38
GAPI_OCV_KERNEL(GCPUSubC, cv::gapi::core::GSubC)
39
{
40
static void run(const cv::Mat& a, const cv::Scalar& b, int dtype, cv::Mat& out)
41
{
42
cv::subtract(a, b, out, cv::noArray(), dtype);
43
}
44
};
45
46
GAPI_OCV_KERNEL(GCPUSubRC, cv::gapi::core::GSubRC)
47
{
48
static void run(const cv::Scalar& a, const cv::Mat& b, int dtype, cv::Mat& out)
49
{
50
cv::subtract(a, b, out, cv::noArray(), dtype);
51
}
52
};
53
54
GAPI_OCV_KERNEL(GCPUMul, cv::gapi::core::GMul)
55
{
56
static void run(const cv::Mat& a, const cv::Mat& b, double scale, int dtype, cv::Mat& out)
57
{
58
cv::multiply(a, b, out, scale, dtype);
59
}
60
};
61
62
GAPI_OCV_KERNEL(GCPUMulCOld, cv::gapi::core::GMulCOld)
63
{
64
static void run(const cv::Mat& a, double b, int dtype, cv::Mat& out)
65
{
66
cv::multiply(a, b, out, 1, dtype);
67
}
68
};
69
70
GAPI_OCV_KERNEL(GCPUMulC, cv::gapi::core::GMulC)
71
{
72
static void run(const cv::Mat& a, const cv::Scalar& b, int dtype, cv::Mat& out)
73
{
74
cv::multiply(a, b, out, 1, dtype);
75
}
76
};
77
78
GAPI_OCV_KERNEL(GCPUDiv, cv::gapi::core::GDiv)
79
{
80
static void run(const cv::Mat& a, const cv::Mat& b, double scale, int dtype, cv::Mat& out)
81
{
82
cv::divide(a, b, out, scale, dtype);
83
}
84
};
85
86
GAPI_OCV_KERNEL(GCPUDivC, cv::gapi::core::GDivC)
87
{
88
static void run(const cv::Mat& a, const cv::Scalar& b, double scale, int dtype, cv::Mat& out)
89
{
90
cv::divide(a, b, out, scale, dtype);
91
}
92
};
93
94
GAPI_OCV_KERNEL(GCPUDivRC, cv::gapi::core::GDivRC)
95
{
96
static void run(const cv::Scalar& a, const cv::Mat& b, double scale, int dtype, cv::Mat& out)
97
{
98
cv::divide(a, b, out, scale, dtype);
99
}
100
};
101
102
GAPI_OCV_KERNEL(GCPUMask, cv::gapi::core::GMask)
103
{
104
static void run(const cv::Mat& in, const cv::Mat& mask, cv::Mat& out)
105
{
106
out = cv::Mat::zeros(in.size(), in.type());
107
in.copyTo(out, mask);
108
}
109
};
110
111
GAPI_OCV_KERNEL(GCPUMean, cv::gapi::core::GMean)
112
{
113
static void run(const cv::Mat& in, cv::Scalar& out)
114
{
115
out = cv::mean(in);
116
}
117
};
118
119
GAPI_OCV_KERNEL(GCPUPolarToCart, cv::gapi::core::GPolarToCart)
120
{
121
static void run(const cv::Mat& magn, const cv::Mat& angle, bool angleInDegrees, cv::Mat& outx, cv::Mat& outy)
122
{
123
cv::polarToCart(magn, angle, outx, outy, angleInDegrees);
124
}
125
};
126
127
GAPI_OCV_KERNEL(GCPUCartToPolar, cv::gapi::core::GCartToPolar)
128
{
129
static void run(const cv::Mat& x, const cv::Mat& y, bool angleInDegrees, cv::Mat& outmagn, cv::Mat& outangle)
130
{
131
cv::cartToPolar(x, y, outmagn, outangle, angleInDegrees);
132
}
133
};
134
135
GAPI_OCV_KERNEL(GCPUCmpGT, cv::gapi::core::GCmpGT)
136
{
137
static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
138
{
139
cv::compare(a, b, out, cv::CMP_GT);
140
}
141
};
142
143
GAPI_OCV_KERNEL(GCPUCmpGE, cv::gapi::core::GCmpGE)
144
{
145
static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
146
{
147
cv::compare(a, b, out, cv::CMP_GE);
148
}
149
};
150
151
GAPI_OCV_KERNEL(GCPUCmpLE, cv::gapi::core::GCmpLE)
152
{
153
static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
154
{
155
cv::compare(a, b, out, cv::CMP_LE);
156
}
157
};
158
159
GAPI_OCV_KERNEL(GCPUCmpLT, cv::gapi::core::GCmpLT)
160
{
161
static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
162
{
163
cv::compare(a, b, out, cv::CMP_LT);
164
}
165
};
166
167
GAPI_OCV_KERNEL(GCPUCmpEQ, cv::gapi::core::GCmpEQ)
168
{
169
static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
170
{
171
cv::compare(a, b, out, cv::CMP_EQ);
172
}
173
};
174
175
GAPI_OCV_KERNEL(GCPUCmpNE, cv::gapi::core::GCmpNE)
176
{
177
static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
178
{
179
cv::compare(a, b, out, cv::CMP_NE);
180
}
181
};
182
183
GAPI_OCV_KERNEL(GCPUCmpGTScalar, cv::gapi::core::GCmpGTScalar)
184
{
185
static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
186
{
187
cv::compare(a, b, out, cv::CMP_GT);
188
}
189
};
190
191
GAPI_OCV_KERNEL(GCPUCmpGEScalar, cv::gapi::core::GCmpGEScalar)
192
{
193
static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
194
{
195
cv::compare(a, b, out, cv::CMP_GE);
196
}
197
};
198
199
GAPI_OCV_KERNEL(GCPUCmpLEScalar, cv::gapi::core::GCmpLEScalar)
200
{
201
static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
202
{
203
cv::compare(a, b, out, cv::CMP_LE);
204
}
205
};
206
207
GAPI_OCV_KERNEL(GCPUCmpLTScalar, cv::gapi::core::GCmpLTScalar)
208
{
209
static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
210
{
211
cv::compare(a, b, out, cv::CMP_LT);
212
}
213
};
214
215
GAPI_OCV_KERNEL(GCPUCmpEQScalar, cv::gapi::core::GCmpEQScalar)
216
{
217
static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
218
{
219
cv::compare(a, b, out, cv::CMP_EQ);
220
}
221
};
222
223
GAPI_OCV_KERNEL(GCPUCmpNEScalar, cv::gapi::core::GCmpNEScalar)
224
{
225
static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
226
{
227
cv::compare(a, b, out, cv::CMP_NE);
228
}
229
};
230
231
GAPI_OCV_KERNEL(GCPUAnd, cv::gapi::core::GAnd)
232
{
233
static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
234
{
235
cv::bitwise_and(a, b, out);
236
}
237
};
238
239
GAPI_OCV_KERNEL(GCPUAndS, cv::gapi::core::GAndS)
240
{
241
static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
242
{
243
cv::bitwise_and(a, b, out);
244
}
245
};
246
247
GAPI_OCV_KERNEL(GCPUOr, cv::gapi::core::GOr)
248
{
249
static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
250
{
251
cv::bitwise_or(a, b, out);
252
}
253
};
254
255
GAPI_OCV_KERNEL(GCPUOrS, cv::gapi::core::GOrS)
256
{
257
static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
258
{
259
cv::bitwise_or(a, b, out);
260
}
261
};
262
263
GAPI_OCV_KERNEL(GCPUXor, cv::gapi::core::GXor)
264
{
265
static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)
266
{
267
cv::bitwise_xor(a, b, out);
268
}
269
};
270
271
GAPI_OCV_KERNEL(GCPUXorS, cv::gapi::core::GXorS)
272
{
273
static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)
274
{
275
cv::bitwise_xor(a, b, out);
276
}
277
};
278
279
GAPI_OCV_KERNEL(GCPUNot, cv::gapi::core::GNot)
280
{
281
static void run(const cv::Mat& a, cv::Mat& out)
282
{
283
cv::bitwise_not(a, out);
284
}
285
};
286
287
GAPI_OCV_KERNEL(GCPUSelect, cv::gapi::core::GSelect)
288
{
289
static void run(const cv::Mat& src1, const cv::Mat& src2, const cv::Mat& mask, cv::Mat& out)
290
{
291
src2.copyTo(out);
292
src1.copyTo(out, mask);
293
}
294
};
295
296
GAPI_OCV_KERNEL(GCPUMin, cv::gapi::core::GMin)
297
{
298
static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
299
{
300
out = cv::min(in1, in2);
301
}
302
};
303
304
GAPI_OCV_KERNEL(GCPUMax, cv::gapi::core::GMax)
305
{
306
static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
307
{
308
out = cv::max(in1, in2);
309
}
310
};
311
312
GAPI_OCV_KERNEL(GCPUAbsDiff, cv::gapi::core::GAbsDiff)
313
{
314
static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
315
{
316
cv::absdiff(in1, in2, out);
317
}
318
};
319
320
GAPI_OCV_KERNEL(GCPUAbsDiffC, cv::gapi::core::GAbsDiffC)
321
{
322
static void run(const cv::Mat& in1, const cv::Scalar& in2, cv::Mat& out)
323
{
324
cv::absdiff(in1, in2, out);
325
}
326
};
327
328
GAPI_OCV_KERNEL(GCPUSum, cv::gapi::core::GSum)
329
{
330
static void run(const cv::Mat& in, cv::Scalar& out)
331
{
332
out = cv::sum(in);
333
}
334
};
335
336
GAPI_OCV_KERNEL(GCPUAddW, cv::gapi::core::GAddW)
337
{
338
static void run(const cv::Mat& in1, double alpha, const cv::Mat& in2, double beta, double gamma, int dtype, cv::Mat& out)
339
{
340
cv::addWeighted(in1, alpha, in2, beta, gamma, out, dtype);
341
}
342
};
343
344
GAPI_OCV_KERNEL(GCPUNormL1, cv::gapi::core::GNormL1)
345
{
346
static void run(const cv::Mat& in, cv::Scalar& out)
347
{
348
out = cv::norm(in, cv::NORM_L1);
349
}
350
};
351
352
GAPI_OCV_KERNEL(GCPUNormL2, cv::gapi::core::GNormL2)
353
{
354
static void run(const cv::Mat& in, cv::Scalar& out)
355
{
356
out = cv::norm(in, cv::NORM_L2);
357
}
358
};
359
360
GAPI_OCV_KERNEL(GCPUNormInf, cv::gapi::core::GNormInf)
361
{
362
static void run(const cv::Mat& in, cv::Scalar& out)
363
{
364
out = cv::norm(in, cv::NORM_INF);
365
}
366
};
367
368
GAPI_OCV_KERNEL(GCPUIntegral, cv::gapi::core::GIntegral)
369
{
370
static void run(const cv::Mat& in, int sdepth, int sqdepth, cv::Mat& out, cv::Mat& outSq)
371
{
372
cv::integral(in, out, outSq, sdepth, sqdepth);
373
}
374
};
375
376
GAPI_OCV_KERNEL(GCPUThreshold, cv::gapi::core::GThreshold)
377
{
378
static void run(const cv::Mat& in, const cv::Scalar& a, const cv::Scalar& b, int type, cv::Mat& out)
379
{
380
cv::threshold(in, out, a.val[0], b.val[0], type);
381
}
382
};
383
384
GAPI_OCV_KERNEL(GCPUThresholdOT, cv::gapi::core::GThresholdOT)
385
{
386
static void run(const cv::Mat& in, const cv::Scalar& b, int type, cv::Mat& out, cv::Scalar& outScalar)
387
{
388
outScalar = cv::threshold(in, out, b.val[0], b.val[0], type);
389
}
390
};
391
392
393
GAPI_OCV_KERNEL(GCPUInRange, cv::gapi::core::GInRange)
394
{
395
static void run(const cv::Mat& in, const cv::Scalar& low, const cv::Scalar& up, cv::Mat& out)
396
{
397
cv::inRange(in, low, up, out);
398
}
399
};
400
401
GAPI_OCV_KERNEL(GCPUSplit3, cv::gapi::core::GSplit3)
402
{
403
static void run(const cv::Mat& in, cv::Mat &m1, cv::Mat &m2, cv::Mat &m3)
404
{
405
std::vector<cv::Mat> outMats = {m1, m2, m3};
406
cv::split(in, outMats);
407
408
// Write back FIXME: Write a helper or avoid this nonsence completely!
409
m1 = outMats[0];
410
m2 = outMats[1];
411
m3 = outMats[2];
412
}
413
};
414
415
GAPI_OCV_KERNEL(GCPUSplit4, cv::gapi::core::GSplit4)
416
{
417
static void run(const cv::Mat& in, cv::Mat &m1, cv::Mat &m2, cv::Mat &m3, cv::Mat &m4)
418
{
419
std::vector<cv::Mat> outMats = {m1, m2, m3, m4};
420
cv::split(in, outMats);
421
422
// Write back FIXME: Write a helper or avoid this nonsence completely!
423
m1 = outMats[0];
424
m2 = outMats[1];
425
m3 = outMats[2];
426
m4 = outMats[3];
427
}
428
};
429
430
GAPI_OCV_KERNEL(GCPUMerge3, cv::gapi::core::GMerge3)
431
{
432
static void run(const cv::Mat& in1, const cv::Mat& in2, const cv::Mat& in3, cv::Mat &out)
433
{
434
std::vector<cv::Mat> inMats = {in1, in2, in3};
435
cv::merge(inMats, out);
436
}
437
};
438
439
GAPI_OCV_KERNEL(GCPUMerge4, cv::gapi::core::GMerge4)
440
{
441
static void run(const cv::Mat& in1, const cv::Mat& in2, const cv::Mat& in3, const cv::Mat& in4, cv::Mat &out)
442
{
443
std::vector<cv::Mat> inMats = {in1, in2, in3, in4};
444
cv::merge(inMats, out);
445
}
446
};
447
448
GAPI_OCV_KERNEL(GCPUResize, cv::gapi::core::GResize)
449
{
450
static void run(const cv::Mat& in, cv::Size sz, double fx, double fy, int interp, cv::Mat &out)
451
{
452
cv::resize(in, out, sz, fx, fy, interp);
453
}
454
};
455
456
GAPI_OCV_KERNEL(GCPURemap, cv::gapi::core::GRemap)
457
{
458
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)
459
{
460
cv::remap(in, out, x, y, a, b, s);
461
}
462
};
463
464
GAPI_OCV_KERNEL(GCPUFlip, cv::gapi::core::GFlip)
465
{
466
static void run(const cv::Mat& in, int code, cv::Mat& out)
467
{
468
cv::flip(in, out, code);
469
}
470
};
471
472
GAPI_OCV_KERNEL(GCPUCrop, cv::gapi::core::GCrop)
473
{
474
static void run(const cv::Mat& in, cv::Rect rect, cv::Mat& out)
475
{
476
cv::Mat(in, rect).copyTo(out);
477
}
478
};
479
480
GAPI_OCV_KERNEL(GCPUConcatHor, cv::gapi::core::GConcatHor)
481
{
482
static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
483
{
484
cv::hconcat(in1, in2, out);
485
}
486
};
487
488
GAPI_OCV_KERNEL(GCPUConcatVert, cv::gapi::core::GConcatVert)
489
{
490
static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
491
{
492
cv::vconcat(in1, in2, out);
493
}
494
};
495
496
GAPI_OCV_KERNEL(GCPULUT, cv::gapi::core::GLUT)
497
{
498
static void run(const cv::Mat& in, const cv::Mat& lut, cv::Mat& out)
499
{
500
cv::LUT(in, lut, out);
501
}
502
};
503
504
GAPI_OCV_KERNEL(GCPUConvertTo, cv::gapi::core::GConvertTo)
505
{
506
static void run(const cv::Mat& in, int rtype, double alpha, double beta, cv::Mat& out)
507
{
508
in.convertTo(out, rtype, alpha, beta);
509
}
510
};
511
512
cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()
513
{
514
static auto pkg = cv::gapi::kernels
515
< GCPUAdd
516
, GCPUAddC
517
, GCPUSub
518
, GCPUSubC
519
, GCPUSubRC
520
, GCPUMul
521
, GCPUMulC
522
, GCPUMulCOld
523
, GCPUDiv
524
, GCPUDivC
525
, GCPUDivRC
526
, GCPUMean
527
, GCPUMask
528
, GCPUPolarToCart
529
, GCPUCartToPolar
530
, GCPUCmpGT
531
, GCPUCmpGE
532
, GCPUCmpLE
533
, GCPUCmpLT
534
, GCPUCmpEQ
535
, GCPUCmpNE
536
, GCPUCmpGTScalar
537
, GCPUCmpGEScalar
538
, GCPUCmpLEScalar
539
, GCPUCmpLTScalar
540
, GCPUCmpEQScalar
541
, GCPUCmpNEScalar
542
, GCPUAnd
543
, GCPUAndS
544
, GCPUOr
545
, GCPUOrS
546
, GCPUXor
547
, GCPUXorS
548
, GCPUNot
549
, GCPUSelect
550
, GCPUMin
551
, GCPUMax
552
, GCPUAbsDiff
553
, GCPUAbsDiffC
554
, GCPUSum
555
, GCPUAddW
556
, GCPUNormL1
557
, GCPUNormL2
558
, GCPUNormInf
559
, GCPUIntegral
560
, GCPUThreshold
561
, GCPUThresholdOT
562
, GCPUInRange
563
, GCPUSplit3
564
, GCPUSplit4
565
, GCPUResize
566
, GCPUMerge3
567
, GCPUMerge4
568
, GCPURemap
569
, GCPUFlip
570
, GCPUCrop
571
, GCPUConcatHor
572
, GCPUConcatVert
573
, GCPULUT
574
, GCPUConvertTo
575
>();
576
return pkg;
577
}
578
579