mirror of
https://github.com/opencv/opencv.git
synced 2026-07-25 21:33:04 +04:00
Merge pull request #23702 from dkurt:py_rotated_rect
Python binding for RotatedRect #23702 ### Pull Request Readiness Checklist related: https://github.com/opencv/opencv/issues/23546#issuecomment-1562894602 See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -728,6 +728,26 @@ PyObject* pyopencv_from(const Rect2d& r)
|
||||
|
||||
// --- RotatedRect
|
||||
|
||||
static inline bool convertToRotatedRect(PyObject* obj, RotatedRect& dst)
|
||||
{
|
||||
PyObject* type = PyObject_Type(obj);
|
||||
if (getPyObjectAttr(type, "__module__") == MODULESTR &&
|
||||
getPyObjectNameAttr(type) == "RotatedRect")
|
||||
{
|
||||
struct pyopencv_RotatedRect_t
|
||||
{
|
||||
PyObject_HEAD
|
||||
cv::RotatedRect v;
|
||||
};
|
||||
dst = reinterpret_cast<pyopencv_RotatedRect_t*>(obj)->v;
|
||||
|
||||
Py_DECREF(type);
|
||||
return true;
|
||||
}
|
||||
Py_DECREF(type);
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, RotatedRect& dst, const ArgInfo& info)
|
||||
{
|
||||
@@ -735,6 +755,12 @@ bool pyopencv_to(PyObject* obj, RotatedRect& dst, const ArgInfo& info)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// This is a workaround for compatibility with an initialization from tuple.
|
||||
// Allows import RotatedRect as an object.
|
||||
if (convertToRotatedRect(obj, dst))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!PySequence_Check(obj))
|
||||
{
|
||||
failmsg("Can't parse '%s' as RotatedRect."
|
||||
|
||||
Reference in New Issue
Block a user