Commit c19b6ed2 authored by Gabe Schwartz's avatar Gabe Schwartz

Fixed pyopencv_to w/FLANN IndexParams in python3.

The keys() and values() functions on dictionaries in Python 3 no longer
return lists.  pyopencv_to() for flann::IndexParams now iterates over
the dictionary in a way that is version-agnostic.
parent cf5dd88c
...@@ -999,19 +999,18 @@ template<> ...@@ -999,19 +999,18 @@ template<>
bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name) bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name)
{ {
(void)name; (void)name;
bool ok = false; bool ok = true;
PyObject* keys = PyObject_CallMethod(o,(char*)"keys",0); PyObject* key = NULL;
PyObject* values = PyObject_CallMethod(o,(char*)"values",0); PyObject* item = NULL;
Py_ssize_t pos = 0;
if( keys && values )
{ if(PyDict_Check(o)) {
int i, n = (int)PyList_GET_SIZE(keys); while(PyDict_Next(o, &pos, &key, &item)) {
for( i = 0; i < n; i++ ) if( !PyString_Check(key) ) {
{ ok = false;
PyObject* key = PyList_GET_ITEM(keys, i);
PyObject* item = PyList_GET_ITEM(values, i);
if( !PyString_Check(key) )
break; break;
}
String k = PyString_AsString(key); String k = PyString_AsString(key);
if( PyString_Check(item) ) if( PyString_Check(item) )
{ {
...@@ -1034,14 +1033,14 @@ bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name) ...@@ -1034,14 +1033,14 @@ bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name)
p.setDouble(k, value); p.setDouble(k, value);
} }
else else
{
ok = false;
break; break;
}
} }
ok = i == n && !PyErr_Occurred();
} }
Py_XDECREF(keys); return ok && !PyErr_Occurred();
Py_XDECREF(values);
return ok;
} }
template<> template<>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment