From cdfa8a668bc13d8f0905d0e16ca2029f8e98e5b2 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 24 Dec 2021 14:51:01 +0000 Subject: [PATCH] python: use '((x,y), (w,h), angle)' in std::vector --- .../core/include/opencv2/core/bindings_utils.hpp | 15 +++++++++++++++ modules/python/src2/cv2.cpp | 4 ++++ modules/python/test/test_misc.py | 12 ++++++++++++ 3 files changed, 31 insertions(+) diff --git a/modules/core/include/opencv2/core/bindings_utils.hpp b/modules/core/include/opencv2/core/bindings_utils.hpp index c53511f88f..67efdcdac2 100644 --- a/modules/core/include/opencv2/core/bindings_utils.hpp +++ b/modules/core/include/opencv2/core/bindings_utils.hpp @@ -103,6 +103,21 @@ String dumpRotatedRect(const RotatedRect& argument) argument.size.height, argument.angle); } +CV_WRAP static inline +RotatedRect testRotatedRect(float x, float y, float w, float h, float angle) +{ + return RotatedRect(Point2f(x, y), Size2f(w, h), angle); +} + +CV_WRAP static inline +std::vector testRotatedRectVector(float x, float y, float w, float h, float angle) +{ + std::vector result; + for (int i = 0; i < 10; i++) + result.push_back(RotatedRect(Point2f(x + i, y + 2 * i), Size2f(w, h), angle + 10 * i)); + return result; +} + CV_WRAP static inline String dumpRange(const Range& argument) { diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 67c4166799..3241b4f5e8 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -518,6 +518,10 @@ template struct IsRepresentableAsMatDataType::channel_type>::type> : TrueType { }; + +// https://github.com/opencv/opencv/issues/20930 +template <> struct IsRepresentableAsMatDataType : FalseType {}; + } // namespace traits typedef std::vector vector_uchar; diff --git a/modules/python/test/test_misc.py b/modules/python/test/test_misc.py index c992c9450d..de7af1d350 100644 --- a/modules/python/test/test_misc.py +++ b/modules/python/test/test_misc.py @@ -583,6 +583,18 @@ class Arguments(NewOpenCVTests): self.assertEqual(ints.dtype, np.int32, "Vector of integers has wrong elements type") self.assertEqual(ints.shape, expected_shape, "Vector of integers has wrong shape.") + def test_result_rotated_rect_issue_20930(self): + rr = cv.utils.testRotatedRect(10, 20, 100, 200, 45) + self.assertTrue(isinstance(rr, tuple), msg=type(rr)) + self.assertEqual(len(rr), 3) + + rrv = cv.utils.testRotatedRectVector(10, 20, 100, 200, 45) + self.assertTrue(isinstance(rrv, tuple), msg=type(rrv)) + self.assertEqual(len(rrv), 10) + + rr = rrv[0] + self.assertTrue(isinstance(rr, tuple), msg=type(rrv)) + self.assertEqual(len(rr), 3) class SamplesFindFile(NewOpenCVTests):