Skip to content

Commit cdfa8a6

Browse files
committed
python: use '((x,y), (w,h), angle)' in std::vector<RotatedRect>
1 parent 92651d2 commit cdfa8a6

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

modules/core/include/opencv2/core/bindings_utils.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ String dumpRotatedRect(const RotatedRect& argument)
103103
argument.size.height, argument.angle);
104104
}
105105

106+
CV_WRAP static inline
107+
RotatedRect testRotatedRect(float x, float y, float w, float h, float angle)
108+
{
109+
return RotatedRect(Point2f(x, y), Size2f(w, h), angle);
110+
}
111+
112+
CV_WRAP static inline
113+
std::vector<RotatedRect> testRotatedRectVector(float x, float y, float w, float h, float angle)
114+
{
115+
std::vector<RotatedRect> result;
116+
for (int i = 0; i < 10; i++)
117+
result.push_back(RotatedRect(Point2f(x + i, y + 2 * i), Size2f(w, h), angle + 10 * i));
118+
return result;
119+
}
120+
106121
CV_WRAP static inline
107122
String dumpRange(const Range& argument)
108123
{

modules/python/src2/cv2.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ template <class T>
518518
struct IsRepresentableAsMatDataType<T, typename VoidType<typename DataType<T>::channel_type>::type> : TrueType
519519
{
520520
};
521+
522+
// https://github.com/opencv/opencv/issues/20930
523+
template <> struct IsRepresentableAsMatDataType<RotatedRect, void> : FalseType {};
524+
521525
} // namespace traits
522526

523527
typedef std::vector<uchar> vector_uchar;

modules/python/test/test_misc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,18 @@ def test_vector_fast_return(self):
583583
self.assertEqual(ints.dtype, np.int32, "Vector of integers has wrong elements type")
584584
self.assertEqual(ints.shape, expected_shape, "Vector of integers has wrong shape.")
585585

586+
def test_result_rotated_rect_issue_20930(self):
587+
rr = cv.utils.testRotatedRect(10, 20, 100, 200, 45)
588+
self.assertTrue(isinstance(rr, tuple), msg=type(rr))
589+
self.assertEqual(len(rr), 3)
590+
591+
rrv = cv.utils.testRotatedRectVector(10, 20, 100, 200, 45)
592+
self.assertTrue(isinstance(rrv, tuple), msg=type(rrv))
593+
self.assertEqual(len(rrv), 10)
594+
595+
rr = rrv[0]
596+
self.assertTrue(isinstance(rr, tuple), msg=type(rrv))
597+
self.assertEqual(len(rr), 3)
586598

587599
class SamplesFindFile(NewOpenCVTests):
588600

0 commit comments

Comments
 (0)