python: support Python list for cv::Range

pull/13945/head
Alexander Alekhin 6 years ago
parent f5b58e5fc9
commit 030e955db7
  1. 34
      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();

Loading…
Cancel
Save