From fbfddbd3eaf3196f9defaec6e5aa1ea0f4bbdd6c Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Tue, 12 Jul 2011 21:13:56 +0000 Subject: [PATCH] - 'c_string' support added to Java API - improved CV_IN_OUT/CV_OUT handling for generated Python/Java wrappers --- modules/core/include/opencv2/core/core.hpp | 2 +- modules/java/gen_java.py | 17 +++++++----- .../include/opencv2/objdetect/objdetect.hpp | 4 +-- modules/python/src2/hdr_parser.py | 30 +++++++++++++--------- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index dc75f4d..4fa02aa 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -2031,7 +2031,7 @@ CV_EXPORTS_W void merge(const vector& mv, OutputArray dst); //! copies each plane of a multi-channel array to a dedicated array CV_EXPORTS void split(const Mat& src, Mat* mvbegin); //! copies each plane of a multi-channel array to a dedicated array -CV_EXPORTS_W void split(const Mat& m, vector& mv); +CV_EXPORTS_W void split(const Mat& m, CV_OUT vector& mv); //! copies selected channels from the input arrays to the selected channels of the output arrays CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, diff --git a/modules/java/gen_java.py b/modules/java/gen_java.py index d63b8bc..95fa410 100644 --- a/modules/java/gen_java.py +++ b/modules/java/gen_java.py @@ -66,6 +66,10 @@ type_dict = { "jni_type" : "jstring", "jni_name" : "n_%(n)s", "jni_var" : 'const char* utf_%(n)s = env->GetStringUTFChars(%(n)s, 0); String n_%(n)s( utf_%(n)s ? utf_%(n)s : "" ); env->ReleaseStringUTFChars(%(n)s, utf_%(n)s)', "suffix" : "Ljava_lang_String_2"}, + "c_string": { "j_type" : "java.lang.String", "jn_type" : "java.lang.String", + "jni_type" : "jstring", "jni_name" : "n_%(n)s.c_str()", + "jni_var" : 'const char* utf_%(n)s = env->GetStringUTFChars(%(n)s, 0); std::string n_%(n)s( utf_%(n)s ? utf_%(n)s : "" ); env->ReleaseStringUTFChars(%(n)s, utf_%(n)s)', + "suffix" : "Ljava_lang_String_2"}, } @@ -98,10 +102,11 @@ class ArgInfo(object): self.ctype = arg_tuple[0] self.name = arg_tuple[1] self.defval = arg_tuple[2] - self.out = "/O" in arg_tuple[3] or "/IO" in arg_tuple[3] - -## def isbig(self): -## return self.ctype == "Mat" or self.ctype == "vector_Mat" + self.out = "" + if "/O" in arg_tuple[3]: + self.out = "O" + if "/IO" in arg_tuple[3]: + self.out = "IO" class FuncInfo(object): @@ -407,14 +412,14 @@ class JavaWrapperGenerator(object): self.skipped_func_list.append(c_decl + "\n" + msg) self.java_code.write( indent + msg ) #self.cpp_code.write( msg ) - print "SKIP:", c_decl, "\n\tdue to ARG type", a.ctype + print "SKIP:", c_decl, "\n\tdue to ARG type", a.ctype, a.out return if a.ctype != "Mat" and "jn_args" in type_dict[a.ctype] and a.out: # complex out args not yet supported msg = "// Unsupported type '%s&', skipping the function\n\n" % a.ctype self.skipped_func_list.append(c_decl + "\n" + msg) self.java_code.write( indent + msg ) #self.cpp_code.write( msg ) - print "SKIP:", c_decl, "\n\tdue to OUT ARG of type", a.ctype + print "SKIP:", c_decl, "\n\tdue to OUT ARG of type", a.ctype, a.out return self.ported_func_counter += 1 diff --git a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp index 33d1b34..fd11506 100644 --- a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp @@ -286,8 +286,8 @@ namespace cv ///////////////////////////// Object Detection //////////////////////////// -CV_EXPORTS_W void groupRectangles(vector& rectList, int groupThreshold, double eps=0.2); -CV_EXPORTS_W void groupRectangles(vector& rectList, CV_OUT vector& weights, int groupThreshold, double eps=0.2); +CV_EXPORTS_W void groupRectangles(CV_IN_OUT vector& rectList, int groupThreshold, double eps=0.2); +CV_EXPORTS_W void groupRectangles(CV_IN_OUT vector& rectList, CV_OUT vector& weights, int groupThreshold, double eps=0.2); CV_EXPORTS void groupRectangles(vector& rectList, vector& rejectLevels, vector& levelWeights, int groupThreshold, double eps=0.2); CV_EXPORTS void groupRectangles_meanshift(vector& rectList, vector& foundWeights, vector& foundScales, diff --git a/modules/python/src2/hdr_parser.py b/modules/python/src2/hdr_parser.py index df10fd1..4f2f14e 100755 --- a/modules/python/src2/hdr_parser.py +++ b/modules/python/src2/hdr_parser.py @@ -253,7 +253,7 @@ class CppHeaderParser(object): fnpos = 0 fname = fname[fnpos:].strip() rettype = fdecl[:fnpos].strip() - + if rettype.endswith("operator"): fname = ("operator " + fname).strip() rettype = rettype[:rettype.rfind("operator")].strip() @@ -265,16 +265,16 @@ class CppHeaderParser(object): else: fname = rettype + fname rettype = "" - + apos = fdecl.find("(") if fname.endswith("operator"): fname += "()" apos = fdecl.find("(", apos+1) - + fname = "cv." + fname.replace("::", ".") decl = [fname, rettype, [], []] args0str = fdecl[apos+1:fdecl.rfind(")")].strip() - + if args0str != "": args0 = args0str.split(",") @@ -287,7 +287,7 @@ class CppHeaderParser(object): if balance_paren == 0 and balance_angle == 0: args.append(narg.strip()) narg = "" - + for arg in args: dfpos = arg.find("=") defval = "" @@ -307,7 +307,7 @@ class CppHeaderParser(object): atype = arg aname = "param" decl[3].append([atype, aname, defval, []]) - + return decl def parse_func_decl(self, decl_str): @@ -326,11 +326,11 @@ class CppHeaderParser(object): if not (("CV_EXPORTS_AS" in decl_str) or ("CV_EXPORTS_W" in decl_str) or \ ("CV_WRAP" in decl_str) or ("CV_WRAP_AS" in decl_str)): return [] - - # ignore old API in the documentation check (for now) + + # ignore old API in the documentation check (for now) if "CVAPI(" in decl_str: - return [] - + return [] + top = self.block_stack[-1] func_modlist = [] @@ -454,13 +454,19 @@ class CppHeaderParser(object): a = a[:eqpos].strip() arg_type, arg_name, modlist, argno = self.parse_arg(a, argno) if self.wrap_mode: - if arg_type == "InputArray" or arg_type == "InputOutputArray": + if arg_type == "InputArray": arg_type = "Mat" + elif arg_type == "InputOutputArray": + arg_type = "Mat" + modlist.append("/IO") elif arg_type == "OutputArray": arg_type = "Mat" modlist.append("/O") - elif arg_type == "InputArrayOfArrays" or arg_type == "InputOutputArrayOfArrays": + elif arg_type == "InputArrayOfArrays": + arg_type = "vector_Mat" + elif arg_type == "InputOutputArrayOfArrays": arg_type = "vector_Mat" + modlist.append("/IO") elif arg_type == "OutputArrayOfArrays": arg_type = "vector_Mat" modlist.append("/O") -- 2.7.4