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
pull/18330/head
Anatoliy Talamanov 5 years ago committed by GitHub
parent 1604ea3b27
commit a258404a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/gapi/include/opencv2/gapi/core.hpp
  2. 4
      modules/gapi/include/opencv2/gapi/gcomputation.hpp
  3. 4
      modules/gapi/include/opencv2/gapi/gscalar.hpp
  4. 18
      modules/gapi/misc/python/test/test_gapi_core.py

@ -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.

@ -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)

@ -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

@ -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()

Loading…
Cancel
Save