From 030e955db7fc89de691dd8bcfa82d0c4881f28ab Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 1 Mar 2019 20:52:35 +0000 Subject: [PATCH] python: support Python list for cv::Range --- modules/python/src2/cv2.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index c9adbbda23..fbe2bbca51 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -819,6 +819,40 @@ bool pyopencv_to(PyObject* obj, Range& r, const char* name) CV_UNUSED(name); if(!obj || obj == Py_None) return true; + while (PySequence_Check(obj)) + { + PyObject *fi = PySequence_Fast(obj, name); + if (fi == NULL) + break; + if (2 != PySequence_Fast_GET_SIZE(fi)) + { + failmsg("Range value for argument '%s' is longer than 2", name); + Py_DECREF(fi); + return false; + } + { + PyObject *item = PySequence_Fast_GET_ITEM(fi, 0); + if (PyInt_Check(item)) { + r.start = (int)PyInt_AsLong(item); + } else { + failmsg("Range.start value for argument '%s' is not integer", name); + Py_DECREF(fi); + break; + } + } + { + PyObject *item = PySequence_Fast_GET_ITEM(fi, 1); + if (PyInt_Check(item)) { + r.end = (int)PyInt_AsLong(item); + } else { + failmsg("Range.end value for argument '%s' is not integer", name); + Py_DECREF(fi); + break; + } + } + Py_DECREF(fi); + return true; + } if(PyObject_Size(obj) == 0) { r = Range::all();