diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index 8a0886f2c8..8e56d5dd93 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -558,7 +558,7 @@ public: //! returns the minimal up-right integer rectangle containing the rotated rectangle CV_WRAP Rect boundingRect() const; //! returns the minimal (exact) floating point rectangle containing the rotated rectangle, not intended for use with images - Rect_ boundingRect2f() const; + CV_WRAP Rect2f boundingRect2f() const; //! returns the rectangle mass center CV_PROP_RW Point2f center; //! returns width and height of the rectangle diff --git a/modules/python/src2/cv2_convert.cpp b/modules/python/src2/cv2_convert.cpp index c4a867892a..113bff09a8 100644 --- a/modules/python/src2/cv2_convert.cpp +++ b/modules/python/src2/cv2_convert.cpp @@ -797,6 +797,21 @@ PyObject* pyopencv_from(const Rect& r) return Py_BuildValue("(iiii)", r.x, r.y, r.width, r.height); } +template<> +bool pyopencv_to(PyObject* obj, Rect2f& r, const ArgInfo& info) +{ + RefWrapper values[] = { + RefWrapper(r.x), RefWrapper(r.y), + RefWrapper(r.width), RefWrapper(r.height)}; + return parseSequence(obj, values, info); +} + +template<> +PyObject* pyopencv_from(const Rect2f& r) +{ + return Py_BuildValue("(ffff)", r.x, r.y, r.width, r.height); +} + template<> bool pyopencv_to(PyObject* obj, Rect2d& r, const ArgInfo& info) { @@ -964,6 +979,21 @@ PyObject* pyopencv_from(const Point2d& p) return Py_BuildValue("(dd)", p.x, p.y); } +template<> +bool pyopencv_to(PyObject* obj, Point3i& p, const ArgInfo& info) +{ + RefWrapper values[] = {RefWrapper(p.x), + RefWrapper(p.y), + RefWrapper(p.z)}; + return parseSequence(obj, values, info); +} + +template<> +PyObject* pyopencv_from(const Point3i& p) +{ + return Py_BuildValue("(iii)", p.x, p.y, p.z); +} + template<> bool pyopencv_to(PyObject* obj, Point3f& p, const ArgInfo& info) { diff --git a/modules/python/src2/cv2_convert.hpp b/modules/python/src2/cv2_convert.hpp index 8d2c876ada..0c0fbd7b96 100644 --- a/modules/python/src2/cv2_convert.hpp +++ b/modules/python/src2/cv2_convert.hpp @@ -214,6 +214,8 @@ template<> PyObject* pyopencv_from(const cv::Size_& sz); // --- Rect template<> bool pyopencv_to(PyObject* obj, cv::Rect& r, const ArgInfo& info); template<> PyObject* pyopencv_from(const cv::Rect& r); +template<> bool pyopencv_to(PyObject* obj, cv::Rect2f& r, const ArgInfo& info); +template<> PyObject* pyopencv_from(const cv::Rect2f& r); template<> bool pyopencv_to(PyObject* obj, cv::Rect2d& r, const ArgInfo& info); template<> PyObject* pyopencv_from(const cv::Rect2d& r); @@ -232,6 +234,8 @@ template<> bool pyopencv_to(PyObject* obj, cv::Point2f& p, const ArgInfo& info); template<> PyObject* pyopencv_from(const cv::Point2f& p); template<> bool pyopencv_to(PyObject* obj, cv::Point2d& p, const ArgInfo& info); template<> PyObject* pyopencv_from(const cv::Point2d& p); +template<> bool pyopencv_to(PyObject* obj, cv::Point3i& p, const ArgInfo& info); +template<> PyObject* pyopencv_from(const cv::Point3i& p); template<> bool pyopencv_to(PyObject* obj, cv::Point3f& p, const ArgInfo& info); template<> PyObject* pyopencv_from(const cv::Point3f& p); template<> bool pyopencv_to(PyObject* obj, cv::Point3d& p, const ArgInfo& info); diff --git a/modules/python/src2/typing_stubs_generation/predefined_types.py b/modules/python/src2/typing_stubs_generation/predefined_types.py index ce4f901e79..6e08a85c9a 100644 --- a/modules/python/src2/typing_stubs_generation/predefined_types.py +++ b/modules/python/src2/typing_stubs_generation/predefined_types.py @@ -71,6 +71,8 @@ _PREDEFINED_TYPES = ( doc="Required length is 4"), AliasTypeNode.sequence_("Rect2i", PrimitiveTypeNode.int_(), doc="Required length is 4"), + AliasTypeNode.sequence_("Rect2f", PrimitiveTypeNode.float_(), + doc="Required length is 4"), AliasTypeNode.sequence_("Rect2d", PrimitiveTypeNode.float_(), doc="Required length is 4"), AliasTypeNode.dict_("Moments", PrimitiveTypeNode.str_("Moments::key"), diff --git a/modules/python/test/test_misc.py b/modules/python/test/test_misc.py index 51ece30dc6..bcd3152699 100644 --- a/modules/python/test/test_misc.py +++ b/modules/python/test/test_misc.py @@ -608,6 +608,14 @@ class Arguments(NewOpenCVTests): _, inter_pts = cv.rotatedRectangleIntersection(rect1, rect2) self.assertLess(np.max(np.abs(inter_pts.reshape(-1, 2) - pts)), 1e-4) + def test_result_rotated_rect_boundingRect2f(self): + center = (0, 0) + size = (10, 10) + angle = 0 + gold_box = (-5.0, -5.0, 10.0, 10.0) + rect1 = cv.RotatedRect(center, size, angle) + bbox = rect1.boundingRect2f() + self.assertEqual(gold_box, bbox) def test_parse_to_rotated_rect_not_convertible(self): for not_convertible in ([], (), np.array([]), (123, (45, 34), 1), {1: 2, 3: 4}, 123,