1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-28 23:03:03 +04:00

upgraded to FLANN 1.6. Added miniflann interface, which is now used in the rest of OpenCV. Added Python bindings for FLANN.

This commit is contained in:
Vadim Pisarevsky
2011-07-13 23:04:39 +00:00
parent 4e42bf6308
commit 562914e33b
48 changed files with 8503 additions and 3606 deletions
+3 -1
View File
@@ -7,6 +7,7 @@ include_directories(${PYTHON_INCLUDE_PATH})
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/src2"
"${OpenCV_SOURCE_DIR}/modules/core/include"
"${OpenCV_SOURCE_DIR}/modules/flann/include"
"${OpenCV_SOURCE_DIR}/modules/imgproc/include"
"${OpenCV_SOURCE_DIR}/modules/video/include"
"${OpenCV_SOURCE_DIR}/modules/highgui/include"
@@ -22,6 +23,7 @@ include_directories(
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(opencv_hdrs "${OpenCV_SOURCE_DIR}/modules/core/include/opencv2/core/core.hpp"
"${OpenCV_SOURCE_DIR}/modules/flann/include/opencv2/flann/miniflann.hpp"
"${OpenCV_SOURCE_DIR}/modules/imgproc/include/opencv2/imgproc/imgproc.hpp"
"${OpenCV_SOURCE_DIR}/modules/video/include/opencv2/video/background_segm.hpp"
"${OpenCV_SOURCE_DIR}/modules/video/include/opencv2/video/tracking.hpp"
@@ -61,7 +63,7 @@ add_custom_command(
set(cv2_target "opencv_python")
add_library(${cv2_target} SHARED src2/cv2.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated0.i src2/opencv_extra_api.hpp ${cv2_generated_hdrs} src2/cv2.cv.hpp)
target_link_libraries(${cv2_target} ${PYTHON_LIBRARIES} opencv_core opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_objdetect opencv_legacy opencv_contrib)
target_link_libraries(${cv2_target} ${PYTHON_LIBRARIES} opencv_core opencv_flann opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_objdetect opencv_legacy opencv_contrib)
set_target_properties(${cv2_target} PROPERTIES PREFIX "")
set_target_properties(${cv2_target} PROPERTIES OUTPUT_NAME "cv2")
+44
View File
@@ -9,6 +9,7 @@
#include "numpy/ndarrayobject.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
@@ -19,6 +20,9 @@
#include "opencv2/highgui/highgui.hpp"
#include "opencv_extra_api.hpp"
using cv::flann::IndexParams;
using cv::flann::SearchParams;
static PyObject* opencv_error = 0;
static int failmsg(const char *fmt, ...)
@@ -735,6 +739,46 @@ static inline PyObject* pyopencv_from(const CvDTreeNode* node)
return value == ivalue ? PyInt_FromLong(ivalue) : PyFloat_FromDouble(value);
}
static bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name="<unknown>")
{
bool ok = false;
PyObject* keys = PyMapping_Keys(o);
PyObject* values = PyMapping_Values(o);
if( keys && values )
{
int i, n = (int)PyList_GET_SIZE(keys);
for( i = 0; i < n; i++ )
{
PyObject* key = PyList_GET_ITEM(keys, i);
PyObject* item = PyList_GET_ITEM(values, i);
if( !PyString_Check(key) )
break;
std::string k = PyString_AsString(key);
if( PyString_Check(item) )
p.setString(k, PyString_AsString(item));
else if( PyInt_Check(item) )
p.setInt(k, PyInt_AsLong(item));
else if( PyFloat_Check(item) )
p.setDouble(k, PyFloat_AsDouble(item));
else
break;
}
ok = i == n && !PyErr_Occurred();
}
Py_XDECREF(keys);
Py_XDECREF(values);
return ok;
}
static bool pyopencv_to(PyObject *o, flann_distance_t& dist, const char *name="<unknown>")
{
int d = 0;
bool ok = pyopencv_to(o, d, name);
dist = (flann_distance_t)d;
return ok;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
+18 -7
View File
@@ -164,6 +164,9 @@ simple_argtype_mapping = {
"c_string": ("char*", "s", '(char*)""')
}
def normalize_class_name(name):
return re.sub(r"^cv\.", "", name).replace(".", "_")
class ClassProp(object):
def __init__(self, decl):
self.tp = decl[0].replace("*", "_ptr")
@@ -175,7 +178,7 @@ class ClassProp(object):
class ClassInfo(object):
def __init__(self, name, decl=None):
self.cname = name.replace(".", "::")
self.name = self.wname = re.sub(r"^cv\.", "", name)
self.name = self.wname = normalize_class_name(name)
self.ismap = False
self.issimple = False
self.methods = {}
@@ -300,8 +303,12 @@ class FuncVariant(object):
self.classname = classname
self.name = self.wname = name
self.isconstructor = isconstructor
if self.isconstructor and self.wname.startswith("Cv"):
self.wname = self.wname[2:]
if self.isconstructor:
if self.wname.startswith("Cv"):
self.wname = self.wname[2:]
else:
self.wname = self.classname
self.rettype = decl[1]
if self.rettype == "void":
self.rettype = ""
@@ -446,7 +453,7 @@ class FuncInfo(object):
s = self.variants[idx].py_docstring
p1 = s.find("(")
p2 = s.rfind(")")
docstring_list = [s[:p1+1] + "[" + s[p1+2:p2] + "]" + s[p2:]]
docstring_list = [s[:p1+1] + "[" + s[p1+1:p2] + "]" + s[p2:]]
return Template(' {"$py_funcname", (PyCFunction)$wrap_funcname, METH_KEYWORDS, "$py_docstring"},\n'
).substitute(py_funcname = self.variants[0].wname, wrap_funcname=self.get_wrapper_name(),
@@ -643,15 +650,19 @@ class PythonWrapperGenerator(object):
self.consts[constinfo.name] = constinfo
def add_func(self, decl):
classname = ""
classname = bareclassname = ""
name = decl[0]
dpos = name.rfind(".")
if dpos >= 0 and name[:dpos] != "cv":
classname = re.sub(r"^cv\.", "", name[:dpos])
classname = bareclassname = re.sub(r"^cv\.", "", name[:dpos])
name = name[dpos+1:]
dpos = classname.rfind(".")
if dpos >= 0:
bareclassname = classname[dpos+1:]
classname = classname.replace(".", "_")
cname = name
name = re.sub(r"^cv\.", "", name)
isconstructor = cname == classname
isconstructor = cname == bareclassname
cname = cname.replace(".", "::")
isclassmethod = False
customname = False
+1
View File
@@ -3,6 +3,7 @@ import os, sys, re, string
# the list only for debugging. The real list, used in the real OpenCV build, is specified in CMakeLists.txt
opencv_hdr_list = [
"../../core/include/opencv2/core/core.hpp",
"../../flann/include/opencv2/flann/miniflann.hpp",
"../../ml/include/opencv2/ml/ml.hpp",
"../../imgproc/include/opencv2/imgproc/imgproc.hpp",
"../../calib3d/include/opencv2/calib3d/calib3d.hpp",