From 55f2370f36367e7f253f1a896c16ab9c6bcef949 Mon Sep 17 00:00:00 2001 From: Anatoliy Talamanov Date: Mon, 13 Jan 2020 14:54:10 +0300 Subject: [PATCH] Merge pull request #16221 from TolyaTalamanov:at/fix-g_typed_kernel_m G-API: Fix G_TYPED_KERNEL_M macro * Fix G_TYPED_KERNEL_M macro * Fixes * Fix windows build * Fix doxygen * Added several macros * Add overloads for G_TYPED_KERNEL --- modules/gapi/include/opencv2/gapi/gkernel.hpp | 102 +++++++++++++++++- .../include/opencv2/gapi/render/render.hpp | 4 +- modules/gapi/test/gapi_sample_pipelines.cpp | 24 ++++- 3 files changed, 122 insertions(+), 8 deletions(-) diff --git a/modules/gapi/include/opencv2/gapi/gkernel.hpp b/modules/gapi/include/opencv2/gapi/gkernel.hpp index 222356ac23..91f57318ff 100644 --- a/modules/gapi/include/opencv2/gapi/gkernel.hpp +++ b/modules/gapi/include/opencv2/gapi/gkernel.hpp @@ -240,8 +240,13 @@ public: }; \ //! @endcond +#define GET_G_TYPED_KERNEL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, NAME, ...) NAME +#define COMBINE_SIGNATURE(...) __VA_ARGS__ +// Ensure correct __VA_ARGS__ expansion on Windows +#define __WRAP_VAARGS(x) x + /** - * Declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) + * Helper for G_TYPED_KERNEL declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) * for more details. * * @param Class type name for this operation. @@ -249,27 +254,118 @@ public: * return type is a single value. * @param Id string identifier for the operation. Must be unique. */ -#define G_TYPED_KERNEL(Class, API, Id) \ +#define G_TYPED_KERNEL_HELPER(Class, API, Id) \ G_ID_HELPER_BODY(Class, Id) \ struct Class final: public cv::GKernelType, \ public G_ID_HELPER_CLASS(Class) // {body} is to be defined by user +#define G_TYPED_KERNEL_HELPER_2(Class, _1, _2, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2), Id) + +#define G_TYPED_KERNEL_HELPER_3(Class, _1, _2, _3, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3), Id) + +#define G_TYPED_KERNEL_HELPER_4(Class, _1, _2, _3, _4, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4), Id) + +#define G_TYPED_KERNEL_HELPER_5(Class, _1, _2, _3, _4, _5, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5), Id) + +#define G_TYPED_KERNEL_HELPER_6(Class, _1, _2, _3, _4, _5, _6, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6), Id) + +#define G_TYPED_KERNEL_HELPER_7(Class, _1, _2, _3, _4, _5, _6, _7, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7), Id) + +#define G_TYPED_KERNEL_HELPER_8(Class, _1, _2, _3, _4, _5, _6, _7, _8, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8), Id) + +#define G_TYPED_KERNEL_HELPER_9(Class, _1, _2, _3, _4, _5, _6, _7, _8, _9, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8, _9), Id) + +#define G_TYPED_KERNEL_HELPER_10(Class, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, Id) \ +G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10), Id) + /** * Declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) * for more details. * * @param Class type name for this operation. + */ +#define G_TYPED_KERNEL(Class, ...) __WRAP_VAARGS(GET_G_TYPED_KERNEL(__VA_ARGS__, \ + G_TYPED_KERNEL_HELPER_10, \ + G_TYPED_KERNEL_HELPER_9, \ + G_TYPED_KERNEL_HELPER_8, \ + G_TYPED_KERNEL_HELPER_7, \ + G_TYPED_KERNEL_HELPER_6, \ + G_TYPED_KERNEL_HELPER_5, \ + G_TYPED_KERNEL_HELPER_4, \ + G_TYPED_KERNEL_HELPER_3, \ + G_TYPED_KERNEL_HELPER_2, \ + G_TYPED_KERNEL_HELPER)(Class, __VA_ARGS__)) \ + +/** + * Helper for G_TYPED_KERNEL_M declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) + * for more details. + * + * @param Class type name for this operation. * @param API an `std::function<>`-like signature for the operation; * return type is a tuple of multiple values. * @param Id string identifier for the operation. Must be unique. */ -#define G_TYPED_KERNEL_M(Class, API, Id) \ +#define G_TYPED_KERNEL_M_HELPER(Class, API, Id) \ G_ID_HELPER_BODY(Class, Id) \ struct Class final: public cv::GKernelTypeM, \ public G_ID_HELPER_CLASS(Class) // {body} is to be defined by user +#define G_TYPED_KERNEL_M_HELPER_2(Class, _1, _2, Id) \ + G_TYPED_KERNEL_M_HELPER(Class, COMBINE_SIGNATURE(_1, _2), Id) + +#define G_TYPED_KERNEL_M_HELPER_3(Class, _1, _2, _3, Id) \ + G_TYPED_KERNEL_M_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3), Id) + +#define G_TYPED_KERNEL_M_HELPER_4(Class, _1, _2, _3, _4, Id) \ + G_TYPED_KERNEL_M_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4), Id) + +#define G_TYPED_KERNEL_M_HELPER_5(Class, _1, _2, _3, _4, _5, Id) \ + G_TYPED_KERNEL_M_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5), Id) + +#define G_TYPED_KERNEL_M_HELPER_6(Class, _1, _2, _3, _4, _5, _6, Id) \ + G_TYPED_KERNEL_M_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6), Id) + +#define G_TYPED_KERNEL_M_HELPER_7(Class, _1, _2, _3, _4, _5, _6, _7, Id) \ + G_TYPED_KERNEL_M_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7), Id) + +#define G_TYPED_KERNEL_M_HELPER_8(Class, _1, _2, _3, _4, _5, _6, _7, _8, Id) \ + G_TYPED_KERNEL_M_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8), Id) + +#define G_TYPED_KERNEL_M_HELPER_9(Class, _1, _2, _3, _4, _5, _6, _7, _8, _9, Id) \ + G_TYPED_KERNEL_M_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8, _9), Id) + +#define G_TYPED_KERNEL_M_HELPER_10(Class, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, Id) \ + G_TYPED_KERNEL_M_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10), Id) + +/** + * Declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) + * for more details. + * + * @param Class type name for this operation. + */ +#define G_TYPED_KERNEL_M(Class, ...) __WRAP_VAARGS(GET_G_TYPED_KERNEL(__VA_ARGS__, \ + G_TYPED_KERNEL_M_HELPER_10, \ + G_TYPED_KERNEL_M_HELPER_9, \ + G_TYPED_KERNEL_M_HELPER_8, \ + G_TYPED_KERNEL_M_HELPER_7, \ + G_TYPED_KERNEL_M_HELPER_6, \ + G_TYPED_KERNEL_M_HELPER_5, \ + G_TYPED_KERNEL_M_HELPER_4, \ + G_TYPED_KERNEL_M_HELPER_3, \ + G_TYPED_KERNEL_M_HELPER_2, \ + G_TYPED_KERNEL_M_HELPER)(Class, __VA_ARGS__)) \ +// {body} is to be defined by user + #define G_API_OP G_TYPED_KERNEL #define G_API_OP_M G_TYPED_KERNEL_M diff --git a/modules/gapi/include/opencv2/gapi/render/render.hpp b/modules/gapi/include/opencv2/gapi/render/render.hpp index 3cf2f6bb0c..7bdc57a093 100644 --- a/modules/gapi/include/opencv2/gapi/render/render.hpp +++ b/modules/gapi/include/opencv2/gapi/render/render.hpp @@ -286,7 +286,7 @@ struct Mosaic * @brief Mosaic constructor * * @param mos_ Coordinates of the mosaic - * @param cellSz_ Cell size (same for X, Y). Note: mos size must be multiple of cell size + * @param cellSz_ Cell size (same for X, Y) * @param decim_ Decimation (0 stands for no decimation) */ Mosaic(const cv::Rect& mos_, @@ -298,7 +298,7 @@ struct Mosaic /*@{*/ cv::Rect mos; //!< Coordinates of the mosaic - int cellSz; //!< Cell size (same for X, Y). Note: mosaic size must be a multiple of cell size + int cellSz; //!< Cell size (same for X, Y) int decim; //!< Decimation (0 stands for no decimation) /*@{*/ }; diff --git a/modules/gapi/test/gapi_sample_pipelines.cpp b/modules/gapi/test/gapi_sample_pipelines.cpp index e41cd067a0..9c329f97fb 100644 --- a/modules/gapi/test/gapi_sample_pipelines.cpp +++ b/modules/gapi/test/gapi_sample_pipelines.cpp @@ -11,9 +11,6 @@ #include #include "logger.hpp" -#include - - namespace opencv_test { @@ -44,6 +41,27 @@ namespace out = in.clone(); } }; + + // These definitons test the correct macro work if the kernel has multiple output values + G_TYPED_KERNEL(GRetGArrayTupleOfGMat2Kernel, >(GMat, Scalar)>, "org.opencv.test.retarrayoftupleofgmat2kernel") {}; + G_TYPED_KERNEL(GRetGArraTupleyOfGMat3Kernel, >(GMat)>, "org.opencv.test.retarrayoftupleofgmat3kernel") {}; + G_TYPED_KERNEL(GRetGArraTupleyOfGMat4Kernel, >(GMat)>, "org.opencv.test.retarrayoftupleofgmat4kernel") {}; + G_TYPED_KERNEL(GRetGArraTupleyOfGMat5Kernel, >(GMat)>, "org.opencv.test.retarrayoftupleofgmat5kernel") {}; + G_TYPED_KERNEL(GRetGArraTupleyOfGMat6Kernel, >(GMat)>, "org.opencv.test.retarrayoftupleofgmat6kernel") {}; + G_TYPED_KERNEL(GRetGArraTupleyOfGMat7Kernel, >(GMat)>, "org.opencv.test.retarrayoftupleofgmat7kernel") {}; + G_TYPED_KERNEL(GRetGArraTupleyOfGMat8Kernel, >(GMat)>, "org.opencv.test.retarrayoftupleofgmat8kernel") {}; + G_TYPED_KERNEL(GRetGArraTupleyOfGMat9Kernel, >(GMat)>, "org.opencv.test.retarrayoftupleofgmat9kernel") {}; + G_TYPED_KERNEL(GRetGArraTupleyOfGMat10Kernel, >(GMat)>, "org.opencv.test.retarrayoftupleofgmat10kernel") {}; + + G_TYPED_KERNEL_M(GRetGMat2Kernel, (GMat, GMat, GMat)>, "org.opencv.test.retgmat2kernel") {}; + G_TYPED_KERNEL_M(GRetGMat3Kernel, (GMat, GScalar)>, "org.opencv.test.retgmat3kernel") {}; + G_TYPED_KERNEL_M(GRetGMat4Kernel, (GMat, GArray, GScalar)>, "org.opencv.test.retgmat4kernel") {}; + G_TYPED_KERNEL_M(GRetGMat5Kernel, (GMat)>, "org.opencv.test.retgmat5kernel") {}; + G_TYPED_KERNEL_M(GRetGMat6Kernel, (GMat)>, "org.opencv.test.retgmat6kernel") {}; + G_TYPED_KERNEL_M(GRetGMat7Kernel, (GMat)>, "org.opencv.test.retgmat7kernel") {}; + G_TYPED_KERNEL_M(GRetGMat8Kernel, (GMat)>, "org.opencv.test.retgmat8kernel") {}; + G_TYPED_KERNEL_M(GRetGMat9Kernel, (GMat)>, "org.opencv.test.retgmat9kernel") {}; + G_TYPED_KERNEL_M(GRetGMat10Kernel, (GMat)>, "org.opencv.test.retgmat10kernel") {}; } TEST(GAPI_Pipeline, OverloadUnary_MatMat)