2016-08-07 00:46:17 +08:00
|
|
|
#ifdef HAVE_OPENCV_FLANN
|
|
|
|
typedef cvflann::flann_distance_t cvflann_flann_distance_t;
|
|
|
|
typedef cvflann::flann_algorithm_t cvflann_flann_algorithm_t;
|
|
|
|
|
|
|
|
template<>
|
|
|
|
PyObject* pyopencv_from(const cvflann_flann_algorithm_t& value)
|
|
|
|
{
|
|
|
|
return PyInt_FromLong(int(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
PyObject* pyopencv_from(const cvflann_flann_distance_t& value)
|
|
|
|
{
|
|
|
|
return PyInt_FromLong(int(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name)
|
|
|
|
{
|
2018-09-07 19:33:52 +08:00
|
|
|
CV_UNUSED(name);
|
2016-08-07 00:46:17 +08:00
|
|
|
bool ok = true;
|
|
|
|
PyObject* key = NULL;
|
|
|
|
PyObject* item = NULL;
|
|
|
|
Py_ssize_t pos = 0;
|
|
|
|
|
2017-03-10 21:09:31 +08:00
|
|
|
if (!o || o == Py_None)
|
|
|
|
return true;
|
|
|
|
|
2016-08-07 00:46:17 +08:00
|
|
|
if(PyDict_Check(o)) {
|
2019-03-21 15:45:02 +08:00
|
|
|
while(PyDict_Next(o, &pos, &key, &item))
|
|
|
|
{
|
|
|
|
// get key
|
|
|
|
std::string k;
|
|
|
|
if (!getUnicodeString(key, k))
|
|
|
|
{
|
2016-08-07 00:46:17 +08:00
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
2019-03-21 15:45:02 +08:00
|
|
|
// get value
|
|
|
|
if( !!PyBool_Check(item) )
|
2016-08-07 00:46:17 +08:00
|
|
|
{
|
|
|
|
p.setBool(k, item == Py_True);
|
2019-03-21 15:45:02 +08:00
|
|
|
}
|
2016-08-07 00:46:17 +08:00
|
|
|
else if( PyInt_Check(item) )
|
|
|
|
{
|
|
|
|
int value = (int)PyInt_AsLong(item);
|
|
|
|
if( strcmp(k.c_str(), "algorithm") == 0 )
|
|
|
|
p.setAlgorithm(value);
|
|
|
|
else
|
|
|
|
p.setInt(k, value);
|
|
|
|
}
|
|
|
|
else if( PyFloat_Check(item) )
|
|
|
|
{
|
|
|
|
double value = PyFloat_AsDouble(item);
|
|
|
|
p.setDouble(k, value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-21 15:45:02 +08:00
|
|
|
std::string val_str;
|
|
|
|
if (!getUnicodeString(item, val_str))
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p.setString(k, val_str);
|
2016-08-07 00:46:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok && !PyErr_Occurred();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool pyopencv_to(PyObject* obj, cv::flann::SearchParams & value, const char * name)
|
|
|
|
{
|
|
|
|
return pyopencv_to<cv::flann::IndexParams>(obj, value, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool pyopencv_to(PyObject *o, cvflann::flann_distance_t& dist, const char *name)
|
|
|
|
{
|
|
|
|
int d = (int)dist;
|
|
|
|
bool ok = pyopencv_to(o, d, name);
|
|
|
|
dist = (cvflann::flann_distance_t)d;
|
|
|
|
return ok;
|
|
|
|
}
|
2019-03-21 15:45:02 +08:00
|
|
|
#endif
|