Path: blob/master/modules/gapi/src/backends/cpu/gcpucore.cpp
16344 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3//4// Copyright (C) 2018 Intel Corporation567#include "precomp.hpp"89#include "opencv2/gapi/core.hpp"10#include "opencv2/gapi/cpu/core.hpp"11#include "backends/cpu/gcpucore.hpp"1213GAPI_OCV_KERNEL(GCPUAdd, cv::gapi::core::GAdd)14{15static void run(const cv::Mat& a, const cv::Mat& b, int dtype, cv::Mat& out)16{17cv::add(a, b, out, cv::noArray(), dtype);18}19};2021GAPI_OCV_KERNEL(GCPUAddC, cv::gapi::core::GAddC)22{23static void run(const cv::Mat& a, const cv::Scalar& b, int dtype, cv::Mat& out)24{25cv::add(a, b, out, cv::noArray(), dtype);26}27};2829GAPI_OCV_KERNEL(GCPUSub, cv::gapi::core::GSub)30{31static void run(const cv::Mat& a, const cv::Mat& b, int dtype, cv::Mat& out)32{33cv::subtract(a, b, out, cv::noArray(), dtype);34}35};3637GAPI_OCV_KERNEL(GCPUSubC, cv::gapi::core::GSubC)38{39static void run(const cv::Mat& a, const cv::Scalar& b, int dtype, cv::Mat& out)40{41cv::subtract(a, b, out, cv::noArray(), dtype);42}43};4445GAPI_OCV_KERNEL(GCPUSubRC, cv::gapi::core::GSubRC)46{47static void run(const cv::Scalar& a, const cv::Mat& b, int dtype, cv::Mat& out)48{49cv::subtract(a, b, out, cv::noArray(), dtype);50}51};5253GAPI_OCV_KERNEL(GCPUMul, cv::gapi::core::GMul)54{55static void run(const cv::Mat& a, const cv::Mat& b, double scale, int dtype, cv::Mat& out)56{57cv::multiply(a, b, out, scale, dtype);58}59};6061GAPI_OCV_KERNEL(GCPUMulCOld, cv::gapi::core::GMulCOld)62{63static void run(const cv::Mat& a, double b, int dtype, cv::Mat& out)64{65cv::multiply(a, b, out, 1, dtype);66}67};6869GAPI_OCV_KERNEL(GCPUMulC, cv::gapi::core::GMulC)70{71static void run(const cv::Mat& a, const cv::Scalar& b, int dtype, cv::Mat& out)72{73cv::multiply(a, b, out, 1, dtype);74}75};7677GAPI_OCV_KERNEL(GCPUDiv, cv::gapi::core::GDiv)78{79static void run(const cv::Mat& a, const cv::Mat& b, double scale, int dtype, cv::Mat& out)80{81cv::divide(a, b, out, scale, dtype);82}83};8485GAPI_OCV_KERNEL(GCPUDivC, cv::gapi::core::GDivC)86{87static void run(const cv::Mat& a, const cv::Scalar& b, double scale, int dtype, cv::Mat& out)88{89cv::divide(a, b, out, scale, dtype);90}91};9293GAPI_OCV_KERNEL(GCPUDivRC, cv::gapi::core::GDivRC)94{95static void run(const cv::Scalar& a, const cv::Mat& b, double scale, int dtype, cv::Mat& out)96{97cv::divide(a, b, out, scale, dtype);98}99};100101GAPI_OCV_KERNEL(GCPUMask, cv::gapi::core::GMask)102{103static void run(const cv::Mat& in, const cv::Mat& mask, cv::Mat& out)104{105out = cv::Mat::zeros(in.size(), in.type());106in.copyTo(out, mask);107}108};109110GAPI_OCV_KERNEL(GCPUMean, cv::gapi::core::GMean)111{112static void run(const cv::Mat& in, cv::Scalar& out)113{114out = cv::mean(in);115}116};117118GAPI_OCV_KERNEL(GCPUPolarToCart, cv::gapi::core::GPolarToCart)119{120static void run(const cv::Mat& magn, const cv::Mat& angle, bool angleInDegrees, cv::Mat& outx, cv::Mat& outy)121{122cv::polarToCart(magn, angle, outx, outy, angleInDegrees);123}124};125126GAPI_OCV_KERNEL(GCPUCartToPolar, cv::gapi::core::GCartToPolar)127{128static void run(const cv::Mat& x, const cv::Mat& y, bool angleInDegrees, cv::Mat& outmagn, cv::Mat& outangle)129{130cv::cartToPolar(x, y, outmagn, outangle, angleInDegrees);131}132};133134GAPI_OCV_KERNEL(GCPUCmpGT, cv::gapi::core::GCmpGT)135{136static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)137{138cv::compare(a, b, out, cv::CMP_GT);139}140};141142GAPI_OCV_KERNEL(GCPUCmpGE, cv::gapi::core::GCmpGE)143{144static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)145{146cv::compare(a, b, out, cv::CMP_GE);147}148};149150GAPI_OCV_KERNEL(GCPUCmpLE, cv::gapi::core::GCmpLE)151{152static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)153{154cv::compare(a, b, out, cv::CMP_LE);155}156};157158GAPI_OCV_KERNEL(GCPUCmpLT, cv::gapi::core::GCmpLT)159{160static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)161{162cv::compare(a, b, out, cv::CMP_LT);163}164};165166GAPI_OCV_KERNEL(GCPUCmpEQ, cv::gapi::core::GCmpEQ)167{168static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)169{170cv::compare(a, b, out, cv::CMP_EQ);171}172};173174GAPI_OCV_KERNEL(GCPUCmpNE, cv::gapi::core::GCmpNE)175{176static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)177{178cv::compare(a, b, out, cv::CMP_NE);179}180};181182GAPI_OCV_KERNEL(GCPUCmpGTScalar, cv::gapi::core::GCmpGTScalar)183{184static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)185{186cv::compare(a, b, out, cv::CMP_GT);187}188};189190GAPI_OCV_KERNEL(GCPUCmpGEScalar, cv::gapi::core::GCmpGEScalar)191{192static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)193{194cv::compare(a, b, out, cv::CMP_GE);195}196};197198GAPI_OCV_KERNEL(GCPUCmpLEScalar, cv::gapi::core::GCmpLEScalar)199{200static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)201{202cv::compare(a, b, out, cv::CMP_LE);203}204};205206GAPI_OCV_KERNEL(GCPUCmpLTScalar, cv::gapi::core::GCmpLTScalar)207{208static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)209{210cv::compare(a, b, out, cv::CMP_LT);211}212};213214GAPI_OCV_KERNEL(GCPUCmpEQScalar, cv::gapi::core::GCmpEQScalar)215{216static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)217{218cv::compare(a, b, out, cv::CMP_EQ);219}220};221222GAPI_OCV_KERNEL(GCPUCmpNEScalar, cv::gapi::core::GCmpNEScalar)223{224static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)225{226cv::compare(a, b, out, cv::CMP_NE);227}228};229230GAPI_OCV_KERNEL(GCPUAnd, cv::gapi::core::GAnd)231{232static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)233{234cv::bitwise_and(a, b, out);235}236};237238GAPI_OCV_KERNEL(GCPUAndS, cv::gapi::core::GAndS)239{240static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)241{242cv::bitwise_and(a, b, out);243}244};245246GAPI_OCV_KERNEL(GCPUOr, cv::gapi::core::GOr)247{248static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)249{250cv::bitwise_or(a, b, out);251}252};253254GAPI_OCV_KERNEL(GCPUOrS, cv::gapi::core::GOrS)255{256static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)257{258cv::bitwise_or(a, b, out);259}260};261262GAPI_OCV_KERNEL(GCPUXor, cv::gapi::core::GXor)263{264static void run(const cv::Mat& a, const cv::Mat& b, cv::Mat& out)265{266cv::bitwise_xor(a, b, out);267}268};269270GAPI_OCV_KERNEL(GCPUXorS, cv::gapi::core::GXorS)271{272static void run(const cv::Mat& a, const cv::Scalar& b, cv::Mat& out)273{274cv::bitwise_xor(a, b, out);275}276};277278GAPI_OCV_KERNEL(GCPUNot, cv::gapi::core::GNot)279{280static void run(const cv::Mat& a, cv::Mat& out)281{282cv::bitwise_not(a, out);283}284};285286GAPI_OCV_KERNEL(GCPUSelect, cv::gapi::core::GSelect)287{288static void run(const cv::Mat& src1, const cv::Mat& src2, const cv::Mat& mask, cv::Mat& out)289{290src2.copyTo(out);291src1.copyTo(out, mask);292}293};294295GAPI_OCV_KERNEL(GCPUMin, cv::gapi::core::GMin)296{297static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)298{299out = cv::min(in1, in2);300}301};302303GAPI_OCV_KERNEL(GCPUMax, cv::gapi::core::GMax)304{305static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)306{307out = cv::max(in1, in2);308}309};310311GAPI_OCV_KERNEL(GCPUAbsDiff, cv::gapi::core::GAbsDiff)312{313static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)314{315cv::absdiff(in1, in2, out);316}317};318319GAPI_OCV_KERNEL(GCPUAbsDiffC, cv::gapi::core::GAbsDiffC)320{321static void run(const cv::Mat& in1, const cv::Scalar& in2, cv::Mat& out)322{323cv::absdiff(in1, in2, out);324}325};326327GAPI_OCV_KERNEL(GCPUSum, cv::gapi::core::GSum)328{329static void run(const cv::Mat& in, cv::Scalar& out)330{331out = cv::sum(in);332}333};334335GAPI_OCV_KERNEL(GCPUAddW, cv::gapi::core::GAddW)336{337static void run(const cv::Mat& in1, double alpha, const cv::Mat& in2, double beta, double gamma, int dtype, cv::Mat& out)338{339cv::addWeighted(in1, alpha, in2, beta, gamma, out, dtype);340}341};342343GAPI_OCV_KERNEL(GCPUNormL1, cv::gapi::core::GNormL1)344{345static void run(const cv::Mat& in, cv::Scalar& out)346{347out = cv::norm(in, cv::NORM_L1);348}349};350351GAPI_OCV_KERNEL(GCPUNormL2, cv::gapi::core::GNormL2)352{353static void run(const cv::Mat& in, cv::Scalar& out)354{355out = cv::norm(in, cv::NORM_L2);356}357};358359GAPI_OCV_KERNEL(GCPUNormInf, cv::gapi::core::GNormInf)360{361static void run(const cv::Mat& in, cv::Scalar& out)362{363out = cv::norm(in, cv::NORM_INF);364}365};366367GAPI_OCV_KERNEL(GCPUIntegral, cv::gapi::core::GIntegral)368{369static void run(const cv::Mat& in, int sdepth, int sqdepth, cv::Mat& out, cv::Mat& outSq)370{371cv::integral(in, out, outSq, sdepth, sqdepth);372}373};374375GAPI_OCV_KERNEL(GCPUThreshold, cv::gapi::core::GThreshold)376{377static void run(const cv::Mat& in, const cv::Scalar& a, const cv::Scalar& b, int type, cv::Mat& out)378{379cv::threshold(in, out, a.val[0], b.val[0], type);380}381};382383GAPI_OCV_KERNEL(GCPUThresholdOT, cv::gapi::core::GThresholdOT)384{385static void run(const cv::Mat& in, const cv::Scalar& b, int type, cv::Mat& out, cv::Scalar& outScalar)386{387outScalar = cv::threshold(in, out, b.val[0], b.val[0], type);388}389};390391392GAPI_OCV_KERNEL(GCPUInRange, cv::gapi::core::GInRange)393{394static void run(const cv::Mat& in, const cv::Scalar& low, const cv::Scalar& up, cv::Mat& out)395{396cv::inRange(in, low, up, out);397}398};399400GAPI_OCV_KERNEL(GCPUSplit3, cv::gapi::core::GSplit3)401{402static void run(const cv::Mat& in, cv::Mat &m1, cv::Mat &m2, cv::Mat &m3)403{404std::vector<cv::Mat> outMats = {m1, m2, m3};405cv::split(in, outMats);406407// Write back FIXME: Write a helper or avoid this nonsence completely!408m1 = outMats[0];409m2 = outMats[1];410m3 = outMats[2];411}412};413414GAPI_OCV_KERNEL(GCPUSplit4, cv::gapi::core::GSplit4)415{416static void run(const cv::Mat& in, cv::Mat &m1, cv::Mat &m2, cv::Mat &m3, cv::Mat &m4)417{418std::vector<cv::Mat> outMats = {m1, m2, m3, m4};419cv::split(in, outMats);420421// Write back FIXME: Write a helper or avoid this nonsence completely!422m1 = outMats[0];423m2 = outMats[1];424m3 = outMats[2];425m4 = outMats[3];426}427};428429GAPI_OCV_KERNEL(GCPUMerge3, cv::gapi::core::GMerge3)430{431static void run(const cv::Mat& in1, const cv::Mat& in2, const cv::Mat& in3, cv::Mat &out)432{433std::vector<cv::Mat> inMats = {in1, in2, in3};434cv::merge(inMats, out);435}436};437438GAPI_OCV_KERNEL(GCPUMerge4, cv::gapi::core::GMerge4)439{440static void run(const cv::Mat& in1, const cv::Mat& in2, const cv::Mat& in3, const cv::Mat& in4, cv::Mat &out)441{442std::vector<cv::Mat> inMats = {in1, in2, in3, in4};443cv::merge(inMats, out);444}445};446447GAPI_OCV_KERNEL(GCPUResize, cv::gapi::core::GResize)448{449static void run(const cv::Mat& in, cv::Size sz, double fx, double fy, int interp, cv::Mat &out)450{451cv::resize(in, out, sz, fx, fy, interp);452}453};454455GAPI_OCV_KERNEL(GCPURemap, cv::gapi::core::GRemap)456{457static void run(const cv::Mat& in, const cv::Mat& x, const cv::Mat& y, int a, int b, cv::Scalar s, cv::Mat& out)458{459cv::remap(in, out, x, y, a, b, s);460}461};462463GAPI_OCV_KERNEL(GCPUFlip, cv::gapi::core::GFlip)464{465static void run(const cv::Mat& in, int code, cv::Mat& out)466{467cv::flip(in, out, code);468}469};470471GAPI_OCV_KERNEL(GCPUCrop, cv::gapi::core::GCrop)472{473static void run(const cv::Mat& in, cv::Rect rect, cv::Mat& out)474{475cv::Mat(in, rect).copyTo(out);476}477};478479GAPI_OCV_KERNEL(GCPUConcatHor, cv::gapi::core::GConcatHor)480{481static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)482{483cv::hconcat(in1, in2, out);484}485};486487GAPI_OCV_KERNEL(GCPUConcatVert, cv::gapi::core::GConcatVert)488{489static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)490{491cv::vconcat(in1, in2, out);492}493};494495GAPI_OCV_KERNEL(GCPULUT, cv::gapi::core::GLUT)496{497static void run(const cv::Mat& in, const cv::Mat& lut, cv::Mat& out)498{499cv::LUT(in, lut, out);500}501};502503GAPI_OCV_KERNEL(GCPUConvertTo, cv::gapi::core::GConvertTo)504{505static void run(const cv::Mat& in, int rtype, double alpha, double beta, cv::Mat& out)506{507in.convertTo(out, rtype, alpha, beta);508}509};510511cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()512{513static auto pkg = cv::gapi::kernels514< GCPUAdd515, GCPUAddC516, GCPUSub517, GCPUSubC518, GCPUSubRC519, GCPUMul520, GCPUMulC521, GCPUMulCOld522, GCPUDiv523, GCPUDivC524, GCPUDivRC525, GCPUMean526, GCPUMask527, GCPUPolarToCart528, GCPUCartToPolar529, GCPUCmpGT530, GCPUCmpGE531, GCPUCmpLE532, GCPUCmpLT533, GCPUCmpEQ534, GCPUCmpNE535, GCPUCmpGTScalar536, GCPUCmpGEScalar537, GCPUCmpLEScalar538, GCPUCmpLTScalar539, GCPUCmpEQScalar540, GCPUCmpNEScalar541, GCPUAnd542, GCPUAndS543, GCPUOr544, GCPUOrS545, GCPUXor546, GCPUXorS547, GCPUNot548, GCPUSelect549, GCPUMin550, GCPUMax551, GCPUAbsDiff552, GCPUAbsDiffC553, GCPUSum554, GCPUAddW555, GCPUNormL1556, GCPUNormL2557, GCPUNormInf558, GCPUIntegral559, GCPUThreshold560, GCPUThresholdOT561, GCPUInRange562, GCPUSplit3563, GCPUSplit4564, GCPUResize565, GCPUMerge3566, GCPUMerge4567, GCPURemap568, GCPUFlip569, GCPUCrop570, GCPUConcatHor571, GCPUConcatVert572, GCPULUT573, GCPUConvertTo574>();575return pkg;576}577578579