diff --git a/modules/core/include/opencv2/core/bindings_utils.hpp b/modules/core/include/opencv2/core/bindings_utils.hpp index 4f7eb532b9..76c9437a30 100644 --- a/modules/core/include/opencv2/core/bindings_utils.hpp +++ b/modules/core/include/opencv2/core/bindings_utils.hpp @@ -219,6 +219,11 @@ AsyncArray testAsyncException() return p.getArrayResult(); } +CV_WRAP static inline +String dumpVec2i(const cv::Vec2i value = cv::Vec2i(42, 24)) { + return format("Vec2i(%d, %d)", value[0], value[1]); +} + namespace nested { CV_WRAP static inline bool testEchoBooleanFunction(bool flag) { return flag; diff --git a/modules/python/src2/cv2_convert.hpp b/modules/python/src2/cv2_convert.hpp index 563f5386b7..700f29e3c5 100644 --- a/modules/python/src2/cv2_convert.hpp +++ b/modules/python/src2/cv2_convert.hpp @@ -62,6 +62,10 @@ PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter::from(src); template bool pyopencv_to(PyObject* o, cv::Matx<_Tp, m, n>& mx, const ArgInfo& info) { + if (!o || o == Py_None) { + return true; + } + cv::Mat tmp; if (!pyopencv_to(o, tmp, info)) { return false; diff --git a/modules/python/test/test_misc.py b/modules/python/test/test_misc.py index fd21656d83..deabbd25aa 100644 --- a/modules/python/test/test_misc.py +++ b/modules/python/test/test_misc.py @@ -736,6 +736,13 @@ class CanUsePurePythonModuleFunction(NewOpenCVTests): res = cv.utils._native.testOverwriteNativeMethod(123) self.assertEqual(res, 123, msg="Failed to call native method implementation") + def test_default_matx_argument(self): + res = cv.utils.dumpVec2i() + self.assertEqual(res, "Vec2i(42, 24)", + msg="Default argument is not properly handled") + res = cv.utils.dumpVec2i((12, 21)) + self.assertEqual(res, "Vec2i(12, 21)") + class SamplesFindFile(NewOpenCVTests):