提交 e368f17c 编写于 作者: V Vadim Pisarevsky

fixed python bindings generation

上级 ba3783d2
......@@ -10,6 +10,7 @@
#include <numpy/ndarrayobject.h>
#include "pyopencv_generated_include.h"
#include "opencv2/core/types_c.h"
#include "opencv2/opencv_modules.hpp"
......@@ -1089,14 +1090,6 @@ bool pyopencv_to(PyObject* obj, CvSlice& r, const char* name)
return PyArg_ParseTuple(obj, "ii", &r.start_index, &r.end_index) > 0;
}
template<>
PyObject* pyopencv_from(CvDTreeNode* const & node)
{
double value = node->value;
int ivalue = cvRound(value);
return value == ivalue ? PyInt_FromLong(ivalue) : PyFloat_FromDouble(value);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
static void OnMouse(int event, int x, int y, int flags, void* param)
......
......@@ -267,7 +267,7 @@ class ClassInfo(object):
#return sys.exit(-1)
if self.bases and self.bases[0].startswith("cv::"):
self.bases[0] = self.bases[0][4:]
if self.bases and self.bases[0] == "Algorithm":
if self.bases and self.bases[0] == "cv::Algorithm":
self.isalgorithm = True
for m in decl[2]:
if m.startswith("="):
......@@ -286,7 +286,7 @@ class ClassInfo(object):
code = "static bool pyopencv_to(PyObject* src, %s& dst, const char* name)\n{\n PyObject* tmp;\n bool ok;\n" % (self.cname)
code += "".join([gen_template_set_prop_from_map.substitute(propname=p.name,proptype=p.tp) for p in self.props])
if self.bases:
code += "\n return pyopencv_to(src, (%s&)dst, name);\n}\n" % all_classes[self.bases[0]].cname
code += "\n return pyopencv_to(src, (%s&)dst, name);\n}\n" % all_classes[self.bases[0].replace("::", "_")].cname
else:
code += "\n return true;\n}\n"
return code
......@@ -761,7 +761,7 @@ class PythonWrapperGenerator(object):
sys.exit(-1)
self.classes[classinfo.name] = classinfo
if classinfo.bases and not classinfo.isalgorithm:
classinfo.isalgorithm = self.classes[classinfo.bases[0]].isalgorithm
classinfo.isalgorithm = self.classes[classinfo.bases[0].replace("::", "_")].isalgorithm
def add_const(self, name, decl):
constinfo = ConstInfo(name, decl[1])
......
......@@ -582,6 +582,7 @@ class CppHeaderParser(object):
return name
if name.startswith("cv."):
return name
qualified_name = (("." in name) or ("::" in name))
n = ""
for b in self.block_stack:
block_type, block_name = b[self.BLOCK_TYPE], b[self.BLOCK_NAME]
......@@ -590,9 +591,12 @@ class CppHeaderParser(object):
if block_type not in ["struct", "class", "namespace"]:
print("Error at %d: there are non-valid entries in the current block stack " % (self.lineno, self.block_stack))
sys.exit(-1)
if block_name:
if block_name and (block_type == "namespace" or not qualified_name):
n += block_name + "."
return n + name.replace("::", ".")
n += name.replace("::", ".")
if n.endswith(".Algorithm"):
n = "cv.Algorithm"
return n
def parse_stmt(self, stmt, end_token):
"""
......@@ -643,7 +647,7 @@ class CppHeaderParser(object):
classname = classname[1:]
decl = [stmt_type + " " + self.get_dotted_name(classname), "", modlist, []]
if bases:
decl[1] = ": " + ", ".join([b if "::" in b else self.get_dotted_name(b).replace(".","::") for b in bases])
decl[1] = ": " + ", ".join([self.get_dotted_name(b).replace(".","::") for b in bases])
return stmt_type, classname, True, decl
if stmt.startswith("class") or stmt.startswith("struct"):
......@@ -658,7 +662,7 @@ class CppHeaderParser(object):
if ("CV_EXPORTS_W" in stmt) or ("CV_EXPORTS_AS" in stmt) or (not self.wrap_mode):# and ("CV_EXPORTS" in stmt)):
decl = [stmt_type + " " + self.get_dotted_name(classname), "", modlist, []]
if bases:
decl[1] = ": " + ", ".join([b if "::" in b else self.get_dotted_name(b).replace(".","::") for b in bases])
decl[1] = ": " + ", ".join([self.get_dotted_name(b).replace(".","::") for b in bases])
return stmt_type, classname, True, decl
if stmt.startswith("enum"):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册