From: Anatoliy Talamanov Date: Sat, 12 Sep 2020 22:02:21 +0000 (+0300) Subject: Merge pull request #18309 from TolyaTalamanov:at/wrap-apply-overloads X-Git-Tag: submit/tizen/20210224.033012~2^2~53 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a258404a58ea6b9b393abfdf65a890c5c2a1049b;p=platform%2Fupstream%2Fopencv.git Merge pull request #18309 from TolyaTalamanov:at/wrap-apply-overloads [G-API] Wrap cv::gapi::mean kernel into python * Wrap cv::gapi::mean kernel into python * Fix test --- diff --git a/modules/gapi/include/opencv2/gapi/core.hpp b/modules/gapi/include/opencv2/gapi/core.hpp index ff59c62..5b9fb5a 100644 --- a/modules/gapi/include/opencv2/gapi/core.hpp +++ b/modules/gapi/include/opencv2/gapi/core.hpp @@ -744,7 +744,7 @@ Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref @note Function textual ID is "org.opencv.core.math.mean" @param src input matrix. */ -GAPI_EXPORTS GScalar mean(const GMat& src); +GAPI_EXPORTS_W GScalar mean(const GMat& src); /** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle. diff --git a/modules/gapi/include/opencv2/gapi/gcomputation.hpp b/modules/gapi/include/opencv2/gapi/gcomputation.hpp index c600de9..d6b8561 100644 --- a/modules/gapi/include/opencv2/gapi/gcomputation.hpp +++ b/modules/gapi/include/opencv2/gapi/gcomputation.hpp @@ -181,7 +181,7 @@ public: * @param in input GMat of the defined unary computation * @param out output GScalar of the defined unary computation */ - GComputation(GMat in, GScalar out); // Unary overload (scalar) + GAPI_WRAP GComputation(GMat in, GScalar out); // Unary overload (scalar) /** * @brief Defines a binary (two inputs -- one output) computation @@ -286,7 +286,7 @@ public: * @param args compilation arguments for underlying compilation * process. */ - void apply(cv::Mat in, cv::Scalar &out, GCompileArgs &&args = {}); // Unary overload (scalar) + GAPI_WRAP void apply(cv::Mat in, CV_OUT cv::Scalar &out, GCompileArgs &&args = {}); // Unary overload (scalar) /** * @brief Execute a binary computation (with compilation on the fly) diff --git a/modules/gapi/include/opencv2/gapi/gscalar.hpp b/modules/gapi/include/opencv2/gapi/gscalar.hpp index be20048..00abdd1 100644 --- a/modules/gapi/include/opencv2/gapi/gscalar.hpp +++ b/modules/gapi/include/opencv2/gapi/gscalar.hpp @@ -26,10 +26,10 @@ struct GOrigin; * @{ */ -class GAPI_EXPORTS GScalar +class GAPI_EXPORTS_W_SIMPLE GScalar { public: - GScalar(); // Empty constructor + GAPI_WRAP GScalar(); // Empty constructor explicit GScalar(const cv::Scalar& s); // Constant value constructor from cv::Scalar explicit GScalar(cv::Scalar&& s); // Constant value move-constructor from cv::Scalar diff --git a/modules/gapi/misc/python/test/test_gapi_core.py b/modules/gapi/misc/python/test/test_gapi_core.py index 9e22725..773e542 100644 --- a/modules/gapi/misc/python/test/test_gapi_core.py +++ b/modules/gapi/misc/python/test/test_gapi_core.py @@ -38,5 +38,23 @@ class gapi_core_test(NewOpenCVTests): self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF)) + def test_mean(self): + sz = (1280, 720, 3) + in_mat = np.random.randint(0, 100, sz).astype(np.uint8) + + # OpenCV + expected = cv.mean(in_mat) + + # G-API + g_in = cv.GMat() + g_out = cv.gapi.mean(g_in) + comp = cv.GComputation(g_in, g_out) + + for pkg in pkgs: + actual = comp.apply(in_mat, args=cv.compile_args(pkg)) + # Comparison + self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF)) + + if __name__ == '__main__': NewOpenCVTests.bootstrap()