mirror of
https://github.com/opencv/opencv.git
synced 2024-12-18 03:18:01 +08:00
Merge pull request #24919 from asmorkalov:as/python_Rect2f_Point3i
Add python bindings for Rect2f and Point3i
This commit is contained in:
commit
73acf08844
@ -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_<float> boundingRect2f() const;
|
||||
CV_WRAP Rect2f boundingRect2f() const;
|
||||
//! returns the rectangle mass center
|
||||
CV_PROP_RW Point2f center;
|
||||
//! returns width and height of the rectangle
|
||||
|
@ -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<float> values[] = {
|
||||
RefWrapper<float>(r.x), RefWrapper<float>(r.y),
|
||||
RefWrapper<float>(r.width), RefWrapper<float>(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<int> values[] = {RefWrapper<int>(p.x),
|
||||
RefWrapper<int>(p.y),
|
||||
RefWrapper<int>(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)
|
||||
{
|
||||
|
@ -214,6 +214,8 @@ template<> PyObject* pyopencv_from(const cv::Size_<float>& 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);
|
||||
|
@ -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"),
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user