From e368f17cafc0f8f6af7209edcc51495abea9d2de Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 30 Jul 2014 16:11:08 +0400 Subject: [PATCH] fixed python bindings generation --- modules/python/src2/cv2.cpp | 9 +-------- modules/python/src2/gen2.py | 6 +++--- modules/python/src2/hdr_parser.py | 12 ++++++++---- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 622d24e64b..225ea5afc5 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -10,6 +10,7 @@ #include #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) diff --git a/modules/python/src2/gen2.py b/modules/python/src2/gen2.py index 684b80f4e8..3dc2329c5a 100755 --- a/modules/python/src2/gen2.py +++ b/modules/python/src2/gen2.py @@ -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]) diff --git a/modules/python/src2/hdr_parser.py b/modules/python/src2/hdr_parser.py index eb9100928f..de33aeb911 100755 --- a/modules/python/src2/hdr_parser.py +++ b/modules/python/src2/hdr_parser.py @@ -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"): -- GitLab