mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 19:50:38 +08:00
Merge pull request #3249 from mshabunin:java_wrap
This commit is contained in:
commit
120594163f
@ -8,7 +8,7 @@ if(IOS OR NOT PYTHON_DEFAULT_AVAILABLE OR NOT ANT_EXECUTABLE OR NOT (JNI_FOUND O
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(the_description "The java bindings")
|
set(the_description "The java bindings")
|
||||||
ocv_add_module(java BINDINGS opencv_core opencv_imgproc OPTIONAL opencv_objdetect opencv_features2d opencv_video opencv_imgcodecs opencv_videoio opencv_calib3d opencv_photo)
|
ocv_add_module(java BINDINGS opencv_core opencv_imgproc OPTIONAL opencv_objdetect opencv_features2d opencv_video opencv_imgcodecs opencv_videoio opencv_calib3d opencv_photo opencv_bioinspired)
|
||||||
ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp")
|
ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp")
|
||||||
|
|
||||||
if(NOT ANDROID)
|
if(NOT ANDROID)
|
||||||
|
1
modules/java/generator/config/bioinspired.filelist
Normal file
1
modules/java/generator/config/bioinspired.filelist
Normal file
@ -0,0 +1 @@
|
|||||||
|
include/opencv2/bioinspired/retina.hpp
|
@ -1,12 +1,13 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import sys, re, os.path
|
import sys, re, os.path
|
||||||
|
import logging
|
||||||
from string import Template
|
from string import Template
|
||||||
|
|
||||||
try:
|
if sys.version_info[0] >= 3:
|
||||||
|
from io import StringIO
|
||||||
|
else:
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
except:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
class_ignore_list = (
|
class_ignore_list = (
|
||||||
#core
|
#core
|
||||||
@ -150,32 +151,18 @@ missing_consts = \
|
|||||||
|
|
||||||
"Calib3d":
|
"Calib3d":
|
||||||
{
|
{
|
||||||
'private' :
|
'public' :
|
||||||
(
|
(
|
||||||
('CV_LMEDS', 4),
|
('CALIB_USE_INTRINSIC_GUESS', '1'),
|
||||||
('CV_RANSAC', 8),
|
('CALIB_RECOMPUTE_EXTRINSIC', '2'),
|
||||||
('CV_FM_LMEDS', 'CV_LMEDS'),
|
('CALIB_CHECK_COND', '4'),
|
||||||
('CV_FM_RANSAC','CV_RANSAC'),
|
('CALIB_FIX_SKEW', '8'),
|
||||||
('CV_FM_7POINT', 1),
|
('CALIB_FIX_K1', '16'),
|
||||||
('CV_FM_8POINT', 2),
|
('CALIB_FIX_K2', '32'),
|
||||||
('CV_CALIB_USE_INTRINSIC_GUESS', 1),
|
('CALIB_FIX_K3', '64'),
|
||||||
('CV_CALIB_FIX_ASPECT_RATIO', 2),
|
('CALIB_FIX_K4', '128'),
|
||||||
('CV_CALIB_FIX_PRINCIPAL_POINT', 4),
|
('CALIB_FIX_INTRINSIC', '256')
|
||||||
('CV_CALIB_ZERO_TANGENT_DIST', 8),
|
)
|
||||||
('CV_CALIB_FIX_FOCAL_LENGTH', 16),
|
|
||||||
('CV_CALIB_FIX_K1', 32),
|
|
||||||
('CV_CALIB_FIX_K2', 64),
|
|
||||||
('CV_CALIB_FIX_K3', 128),
|
|
||||||
('CV_CALIB_FIX_K4', 2048),
|
|
||||||
('CV_CALIB_FIX_K5', 4096),
|
|
||||||
('CV_CALIB_FIX_K6', 8192),
|
|
||||||
('CV_CALIB_RATIONAL_MODEL', 16384),
|
|
||||||
('CV_CALIB_THIN_PRISM_MODEL',32768),
|
|
||||||
('CV_CALIB_FIX_S1_S2_S3_S4', 65536),
|
|
||||||
('CV_CALIB_FIX_INTRINSIC', 256),
|
|
||||||
('CV_CALIB_SAME_FOCAL_LENGTH', 512),
|
|
||||||
('CV_CALIB_ZERO_DISPARITY', 1024),
|
|
||||||
) # public
|
|
||||||
}, # Calib3d
|
}, # Calib3d
|
||||||
|
|
||||||
"Video":
|
"Video":
|
||||||
@ -635,6 +622,51 @@ func_arg_fix = {
|
|||||||
}, # '', i.e. no class
|
}, # '', i.e. no class
|
||||||
} # func_arg_fix
|
} # func_arg_fix
|
||||||
|
|
||||||
|
def objdump(obj):
|
||||||
|
attrs = ["%s='%s'" % (attr, getattr(obj, attr)) for attr in dir(obj) if not attr.startswith("__") and not hasattr(getattr(obj, attr), "__call__")]
|
||||||
|
return "%s [%s]" % (obj.__class__.__name__, " ; ".join(attrs))
|
||||||
|
|
||||||
|
class DebuggedObject(object):
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
def __str__(self):
|
||||||
|
return objdump(self)
|
||||||
|
|
||||||
|
class GeneralInfo(DebuggedObject):
|
||||||
|
def __init__(self, name, namespaces):
|
||||||
|
DebuggedObject.__init__(self)
|
||||||
|
self.namespace, self.classpath, self.classname, self.name = self.parseName(name, namespaces)
|
||||||
|
|
||||||
|
def parseName(self, name, namespaces):
|
||||||
|
'''
|
||||||
|
input: full name and available namespaces
|
||||||
|
returns: (namespace, classpath, classname, name)
|
||||||
|
'''
|
||||||
|
name = name[name.find(" ")+1:].strip() # remove struct/class/const prefix
|
||||||
|
spaceName = ""
|
||||||
|
localName = name # <classes>.<name>
|
||||||
|
for namespace in sorted(namespaces, key=len, reverse=True):
|
||||||
|
if name.startswith(namespace + "."):
|
||||||
|
spaceName = namespace
|
||||||
|
localName = name.replace(namespace + ".", "")
|
||||||
|
break
|
||||||
|
pieces = localName.split(".")
|
||||||
|
if len(pieces) > 2: # <class>.<class>.<class>.<name>
|
||||||
|
return spaceName, ".".join(pieces[:-1]), pieces[-2], pieces[-1]
|
||||||
|
elif len(pieces) == 2: # <class>.<name>
|
||||||
|
return spaceName, pieces[0], pieces[0], pieces[1]
|
||||||
|
elif len(pieces) == 1: # <name>
|
||||||
|
return spaceName, "", "", pieces[0]
|
||||||
|
else:
|
||||||
|
return spaceName, "", "" # error?!
|
||||||
|
|
||||||
|
def fullName(self, isCPP=False):
|
||||||
|
result = ".".join([self.fullClass(), self.name])
|
||||||
|
return result if not isCPP else result.replace(".", "::")
|
||||||
|
|
||||||
|
def fullClass(self, isCPP=False):
|
||||||
|
result = ".".join([f for f in [self.namespace] + self.classpath.split(".") if len(f)>0])
|
||||||
|
return result if not isCPP else result.replace(".", "::")
|
||||||
|
|
||||||
def getLibVersion(version_hpp_path):
|
def getLibVersion(version_hpp_path):
|
||||||
version_file = open(version_hpp_path, "rt").read()
|
version_file = open(version_hpp_path, "rt").read()
|
||||||
@ -644,26 +676,24 @@ def getLibVersion(version_hpp_path):
|
|||||||
status = re.search("^W*#\W*define\W+CV_VERSION_STATUS\W+\"(.*?)\"\W*$", version_file, re.MULTILINE).group(1)
|
status = re.search("^W*#\W*define\W+CV_VERSION_STATUS\W+\"(.*?)\"\W*$", version_file, re.MULTILINE).group(1)
|
||||||
return (major, minor, revision, status)
|
return (major, minor, revision, status)
|
||||||
|
|
||||||
class ConstInfo(object):
|
class ConstInfo(GeneralInfo):
|
||||||
def __init__(self, cname, name, val, addedManually=False):
|
def __init__(self, decl, addedManually=False, namespaces=[]):
|
||||||
self.cname = cname
|
GeneralInfo.__init__(self, decl[0], namespaces)
|
||||||
self.name = re.sub(r"^Cv", "", name)
|
self.cname = self.name.replace(".", "::")
|
||||||
self.value = val
|
self.value = decl[1]
|
||||||
self.addedManually = addedManually
|
self.addedManually = addedManually
|
||||||
|
|
||||||
|
class ClassPropInfo(DebuggedObject):
|
||||||
class ClassPropInfo(object):
|
|
||||||
def __init__(self, decl): # [f_ctype, f_name, '', '/RW']
|
def __init__(self, decl): # [f_ctype, f_name, '', '/RW']
|
||||||
|
DebuggedObject.__init__(self)
|
||||||
self.ctype = decl[0]
|
self.ctype = decl[0]
|
||||||
self.name = decl[1]
|
self.name = decl[1]
|
||||||
self.rw = "/RW" in decl[3]
|
self.rw = "/RW" in decl[3]
|
||||||
|
|
||||||
class ClassInfo(object):
|
class ClassInfo(GeneralInfo):
|
||||||
def __init__(self, decl): # [ 'class/struct cname', ': base', [modlist] ]
|
def __init__(self, decl, namespaces=[]): # [ 'class/struct cname', ': base', [modlist] ]
|
||||||
name = decl[0]
|
GeneralInfo.__init__(self, decl[0], namespaces)
|
||||||
name = name[name.find(" ")+1:].strip()
|
self.cname = self.name.replace(".", "::")
|
||||||
self.cname = self.name = self.jname = re.sub(r"^cv\.", "", name)
|
|
||||||
self.cname = self.cname.replace(".", "::")
|
|
||||||
self.methods = {}
|
self.methods = {}
|
||||||
self.methods_suffixes = {}
|
self.methods_suffixes = {}
|
||||||
self.consts = [] # using a list to save the occurence order
|
self.consts = [] # using a list to save the occurence order
|
||||||
@ -679,8 +709,9 @@ class ClassInfo(object):
|
|||||||
#self.base = re.sub(r"\b"+self.jname+r"\b", "", decl[1].replace(":", "")).strip()
|
#self.base = re.sub(r"\b"+self.jname+r"\b", "", decl[1].replace(":", "")).strip()
|
||||||
self.base = re.sub(r"^.*:", "", decl[1].split(",")[0]).strip().replace(self.jname, "")
|
self.base = re.sub(r"^.*:", "", decl[1].split(",")[0]).strip().replace(self.jname, "")
|
||||||
|
|
||||||
class ArgInfo(object):
|
class ArgInfo(DebuggedObject):
|
||||||
def __init__(self, arg_tuple): # [ ctype, name, def val, [mod], argno ]
|
def __init__(self, arg_tuple): # [ ctype, name, def val, [mod], argno ]
|
||||||
|
DebuggedObject.__init__(self)
|
||||||
self.pointer = False
|
self.pointer = False
|
||||||
ctype = arg_tuple[0]
|
ctype = arg_tuple[0]
|
||||||
if ctype.endswith("*"):
|
if ctype.endswith("*"):
|
||||||
@ -700,18 +731,12 @@ class ArgInfo(object):
|
|||||||
self.out = "IO"
|
self.out = "IO"
|
||||||
|
|
||||||
|
|
||||||
class FuncInfo(object):
|
class FuncInfo(GeneralInfo):
|
||||||
def __init__(self, decl): # [ funcname, return_ctype, [modifiers], [args] ]
|
def __init__(self, decl, namespaces=[]): # [ funcname, return_ctype, [modifiers], [args] ]
|
||||||
name = re.sub(r"^cv\.", "", decl[0])
|
GeneralInfo.__init__(self, decl[0], namespaces)
|
||||||
self.cname = name.replace(".", "::")
|
self.cname = self.name.replace(".", "::")
|
||||||
classname = ""
|
self.jname = self.name
|
||||||
dpos = name.rfind(".")
|
if "[" in self.name:
|
||||||
if dpos >= 0:
|
|
||||||
classname = name[:dpos]
|
|
||||||
name = name[dpos+1:]
|
|
||||||
self.classname = classname
|
|
||||||
self.jname = self.name = name
|
|
||||||
if "[" in name:
|
|
||||||
self.jname = "getelem"
|
self.jname = "getelem"
|
||||||
for m in decl[2]:
|
for m in decl[2]:
|
||||||
if m.startswith("="):
|
if m.startswith("="):
|
||||||
@ -719,26 +744,22 @@ class FuncInfo(object):
|
|||||||
self.static = ["","static"][ "/S" in decl[2] ]
|
self.static = ["","static"][ "/S" in decl[2] ]
|
||||||
self.ctype = re.sub(r"^CvTermCriteria", "TermCriteria", decl[1] or "")
|
self.ctype = re.sub(r"^CvTermCriteria", "TermCriteria", decl[1] or "")
|
||||||
self.args = []
|
self.args = []
|
||||||
func_fix_map = func_arg_fix.get(classname, {}).get(self.jname, {})
|
func_fix_map = func_arg_fix.get(self.classname, {}).get(self.jname, {})
|
||||||
for a in decl[3]:
|
for a in decl[3]:
|
||||||
arg = a[:]
|
arg = a[:]
|
||||||
arg_fix_map = func_fix_map.get(arg[1], {})
|
arg_fix_map = func_fix_map.get(arg[1], {})
|
||||||
arg[0] = arg_fix_map.get('ctype', arg[0]) #fixing arg type
|
arg[0] = arg_fix_map.get('ctype', arg[0]) #fixing arg type
|
||||||
arg[3] = arg_fix_map.get('attrib', arg[3]) #fixing arg attrib
|
arg[3] = arg_fix_map.get('attrib', arg[3]) #fixing arg attrib
|
||||||
ai = ArgInfo(arg)
|
self.args.append(ArgInfo(arg))
|
||||||
self.args.append(ai)
|
|
||||||
|
|
||||||
|
class FuncFamilyInfo(DebuggedObject):
|
||||||
|
def __init__(self, decl, namespaces=set()): # [ funcname, return_ctype, [modifiers], [args] ]
|
||||||
class FuncFamilyInfo(object):
|
DebuggedObject.__init__(self)
|
||||||
def __init__(self, decl): # [ funcname, return_ctype, [modifiers], [args] ]
|
|
||||||
self.funcs = []
|
self.funcs = []
|
||||||
self.funcs.append( FuncInfo(decl) )
|
self.funcs.append( FuncInfo(decl, namespaces) )
|
||||||
self.jname = self.funcs[0].jname
|
self.jname = self.funcs[0].jname
|
||||||
self.isconstructor = self.funcs[0].name == self.funcs[0].classname
|
self.isconstructor = self.funcs[0].name == self.funcs[0].classname
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def add_func(self, fi):
|
def add_func(self, fi):
|
||||||
self.funcs.append( fi )
|
self.funcs.append( fi )
|
||||||
|
|
||||||
@ -758,6 +779,7 @@ class JavaWrapperGenerator(object):
|
|||||||
self.def_args_hist = {} # { def_args_cnt : funcs_cnt }
|
self.def_args_hist = {} # { def_args_cnt : funcs_cnt }
|
||||||
self.classes_map = []
|
self.classes_map = []
|
||||||
self.classes_simple = []
|
self.classes_simple = []
|
||||||
|
self.namespaces = set(["cv"])
|
||||||
|
|
||||||
def add_class_code_stream(self, class_name, cls_base = ''):
|
def add_class_code_stream(self, class_name, cls_base = ''):
|
||||||
jname = self.classes[class_name].jname
|
jname = self.classes[class_name].jname
|
||||||
@ -833,51 +855,55 @@ public class %(jc)s {
|
|||||||
|
|
||||||
|
|
||||||
def add_class(self, decl):
|
def add_class(self, decl):
|
||||||
classinfo = ClassInfo(decl)
|
logging.info("class: %s", decl)
|
||||||
|
classinfo = ClassInfo(decl, namespaces=self.namespaces)
|
||||||
if classinfo.name in class_ignore_list:
|
if classinfo.name in class_ignore_list:
|
||||||
|
logging.info('ignored: %s', classinfo)
|
||||||
return
|
return
|
||||||
name = classinfo.name
|
name = classinfo.name
|
||||||
if name in self.classes:
|
if name in self.classes:
|
||||||
print "Generator error: class %s (%s) is duplicated" % \
|
print("Generator error: class %s (%s) is duplicated" % \
|
||||||
(name, classinfo.cname)
|
(name, classinfo.cname))
|
||||||
|
logging.info('duplicated: %s', classinfo)
|
||||||
return
|
return
|
||||||
self.classes[name] = classinfo
|
self.classes[name] = classinfo
|
||||||
if name in type_dict:
|
if name in type_dict:
|
||||||
print "Duplicated class: " + name
|
print("Duplicated class: " + name)
|
||||||
|
logging.info('duplicated: %s', classinfo)
|
||||||
return
|
return
|
||||||
if '/Simple' in decl[2]:
|
if '/Simple' in decl[2]:
|
||||||
self.classes_simple.append(name)
|
self.classes_simple.append(name)
|
||||||
if ('/Map' in decl[2]):
|
if ('/Map' in decl[2]):
|
||||||
self.classes_map.append(name)
|
self.classes_map.append(name)
|
||||||
#adding default c-tor
|
#adding default c-tor
|
||||||
ffi = FuncFamilyInfo(['cv.'+name+'.'+name, '', [], []])
|
ffi = FuncFamilyInfo(['cv.'+name+'.'+name, '', [], []], namespaces=self.namespaces)
|
||||||
classinfo.methods[ffi.jname] = ffi
|
classinfo.methods[ffi.jname] = ffi
|
||||||
type_dict[name] = \
|
type_dict[name] = \
|
||||||
{ "j_type" : classinfo.jname,
|
{ "j_type" : classinfo.jname,
|
||||||
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
|
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
|
||||||
"jni_name" : "(*("+name+"*)%(n)s_nativeObj)", "jni_type" : "jlong",
|
"jni_name" : "(*("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj)", "jni_type" : "jlong",
|
||||||
"suffix" : "J" }
|
"suffix" : "J" }
|
||||||
type_dict[name+'*'] = \
|
type_dict[name+'*'] = \
|
||||||
{ "j_type" : classinfo.jname,
|
{ "j_type" : classinfo.jname,
|
||||||
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
|
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
|
||||||
"jni_name" : "("+name+"*)%(n)s_nativeObj", "jni_type" : "jlong",
|
"jni_name" : "("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj", "jni_type" : "jlong",
|
||||||
"suffix" : "J" }
|
"suffix" : "J" }
|
||||||
|
|
||||||
# missing_consts { Module : { public : [[name, val],...], private : [[]...] } }
|
# missing_consts { Module : { public : [[name, val],...], private : [[]...] } }
|
||||||
if name in missing_consts:
|
if name in missing_consts:
|
||||||
if 'private' in missing_consts[name]:
|
if 'private' in missing_consts[name]:
|
||||||
for (n, val) in missing_consts[name]['private']:
|
for (n, val) in missing_consts[name]['private']:
|
||||||
classinfo.private_consts.append( ConstInfo(n, n, val, True) )
|
classinfo.private_consts.append( ConstInfo([n, val], addedManually=True) )
|
||||||
if 'public' in missing_consts[name]:
|
if 'public' in missing_consts[name]:
|
||||||
for (n, val) in missing_consts[name]['public']:
|
for (n, val) in missing_consts[name]['public']:
|
||||||
classinfo.consts.append( ConstInfo(n, n, val, True) )
|
classinfo.consts.append( ConstInfo([n, val], addedManually=True) )
|
||||||
|
|
||||||
# class props
|
# class props
|
||||||
for p in decl[3]:
|
for p in decl[3]:
|
||||||
if True: #"vector" not in p[0]:
|
if True: #"vector" not in p[0]:
|
||||||
classinfo.props.append( ClassPropInfo(p) )
|
classinfo.props.append( ClassPropInfo(p) )
|
||||||
else:
|
else:
|
||||||
print "Skipped property: [%s]" % name, p
|
print("Skipped property: [%s]" % name, p)
|
||||||
|
|
||||||
self.add_class_code_stream(name, classinfo.base)
|
self.add_class_code_stream(name, classinfo.base)
|
||||||
if classinfo.base:
|
if classinfo.base:
|
||||||
@ -887,57 +913,60 @@ public class %(jc)s {
|
|||||||
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
|
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
|
||||||
"jni_name" : "Ptr<"+name+">(("+name+"*)%(n)s_nativeObj)", "jni_type" : "jlong",
|
"jni_name" : "Ptr<"+name+">(("+name+"*)%(n)s_nativeObj)", "jni_type" : "jlong",
|
||||||
"suffix" : "J" }
|
"suffix" : "J" }
|
||||||
|
logging.info('ok: %s', classinfo)
|
||||||
|
|
||||||
def add_const(self, decl): # [ "const cname", val, [], [] ]
|
def add_const(self, decl): # [ "const cname", val, [], [] ]
|
||||||
name = decl[0].replace("const ", "").strip()
|
logging.info("constant: %s", decl)
|
||||||
name = re.sub(r"^cv\.", "", name)
|
constinfo = ConstInfo(decl, namespaces=self.namespaces)
|
||||||
cname = name.replace(".", "::")
|
|
||||||
for c in const_ignore_list:
|
for c in const_ignore_list:
|
||||||
if re.match(c, name):
|
if re.match(c, constinfo.name):
|
||||||
|
logging.info('ignored: %s', constinfo)
|
||||||
return
|
return
|
||||||
# class member?
|
# class member?
|
||||||
dpos = name.rfind(".")
|
if len(constinfo.classname) == 0:
|
||||||
if dpos >= 0:
|
constinfo.classname = self.Module
|
||||||
classname = name[:dpos]
|
if constinfo.classname not in self.classes:
|
||||||
name = name[dpos+1:]
|
|
||||||
else:
|
|
||||||
classname = self.Module
|
|
||||||
if classname not in self.classes:
|
|
||||||
# this class isn't wrapped
|
# this class isn't wrapped
|
||||||
# skipping this const
|
# skipping this const
|
||||||
|
logging.info('class not found: %s', constinfo)
|
||||||
return
|
return
|
||||||
|
|
||||||
consts = self.classes[classname].consts
|
consts = self.classes[constinfo.classname].consts
|
||||||
for c in const_private_list:
|
for c in const_private_list:
|
||||||
if re.match(c, name):
|
if re.match(c, constinfo.name):
|
||||||
consts = self.classes[classname].private_consts
|
consts = self.classes[constinfo.classname].private_consts
|
||||||
break
|
break
|
||||||
|
|
||||||
constinfo = ConstInfo(cname, name, decl[1])
|
|
||||||
# checking duplication
|
# checking duplication
|
||||||
for list in self.classes[classname].consts, self.classes[classname].private_consts:
|
for list in self.classes[constinfo.classname].consts, self.classes[constinfo.classname].private_consts:
|
||||||
for c in list:
|
for c in list:
|
||||||
if c.name == constinfo.name:
|
if c.name == constinfo.name:
|
||||||
if c.addedManually:
|
if c.addedManually:
|
||||||
|
logging.info('manual: %s', constinfo)
|
||||||
return
|
return
|
||||||
print "Generator error: constant %s (%s) is duplicated" \
|
print("Generator error: constant %s (%s) is duplicated" \
|
||||||
% (constinfo.name, constinfo.cname)
|
% (constinfo.name, constinfo.cname))
|
||||||
sys.exit(-1)
|
logging.info('duplicated: %s', constinfo)
|
||||||
|
return
|
||||||
|
|
||||||
consts.append(constinfo)
|
consts.append(constinfo)
|
||||||
|
logging.info('ok: %s', constinfo)
|
||||||
|
|
||||||
def add_func(self, decl):
|
def add_func(self, decl):
|
||||||
ffi = FuncFamilyInfo(decl)
|
logging.info("function: %s", decl)
|
||||||
|
ffi = FuncFamilyInfo(decl, namespaces=self.namespaces)
|
||||||
classname = ffi.funcs[0].classname or self.Module
|
classname = ffi.funcs[0].classname or self.Module
|
||||||
if classname in class_ignore_list:
|
if classname in class_ignore_list:
|
||||||
|
logging.info('ignored: %s', ffi)
|
||||||
return
|
return
|
||||||
if classname in ManualFuncs and ffi.jname in ManualFuncs[classname]:
|
if classname in ManualFuncs and ffi.jname in ManualFuncs[classname]:
|
||||||
|
logging.info('manual: %s', ffi)
|
||||||
return
|
return
|
||||||
if classname not in self.classes:
|
if classname not in self.classes:
|
||||||
print "Generator error: the class %s for method %s is missing" % \
|
print("Generator error: the class %s for method %s is missing" % \
|
||||||
(classname, ffi.jname)
|
(classname, ffi.jname))
|
||||||
sys.exit(-1)
|
logging.info('not found: %s', ffi)
|
||||||
|
return
|
||||||
func_map = self.classes[classname].methods
|
func_map = self.classes[classname].methods
|
||||||
if ffi.jname in func_map:
|
if ffi.jname in func_map:
|
||||||
func_map[ffi.jname].add_func(ffi.funcs[0])
|
func_map[ffi.jname].add_func(ffi.funcs[0])
|
||||||
@ -946,6 +975,7 @@ public class %(jc)s {
|
|||||||
# calc args with def val
|
# calc args with def val
|
||||||
cnt = len([a for a in ffi.funcs[0].args if a.defval])
|
cnt = len([a for a in ffi.funcs[0].args if a.defval])
|
||||||
self.def_args_hist[cnt] = self.def_args_hist.get(cnt, 0) + 1
|
self.def_args_hist[cnt] = self.def_args_hist.get(cnt, 0) + 1
|
||||||
|
logging.info('ok: %s', ffi)
|
||||||
|
|
||||||
def save(self, path, buf):
|
def save(self, path, buf):
|
||||||
f = open(path, "wt")
|
f = open(path, "wt")
|
||||||
@ -963,6 +993,9 @@ public class %(jc)s {
|
|||||||
# scan the headers and build more descriptive maps of classes, consts, functions
|
# scan the headers and build more descriptive maps of classes, consts, functions
|
||||||
for hdr in srcfiles:
|
for hdr in srcfiles:
|
||||||
decls = parser.parse(hdr)
|
decls = parser.parse(hdr)
|
||||||
|
self.namespaces = parser.namespaces
|
||||||
|
logging.info("=== Header: %s", hdr)
|
||||||
|
logging.info("=== Namespaces: %s", parser.namespaces)
|
||||||
for decl in decls:
|
for decl in decls:
|
||||||
name = decl[0]
|
name = decl[0]
|
||||||
if name.startswith("struct") or name.startswith("class"):
|
if name.startswith("struct") or name.startswith("class"):
|
||||||
@ -1054,7 +1087,7 @@ extern "C" {
|
|||||||
|
|
||||||
self.save(output_path+"/"+module+".txt", report.getvalue())
|
self.save(output_path+"/"+module+".txt", report.getvalue())
|
||||||
|
|
||||||
#print "Done %i of %i funcs." % (len(self.ported_func_list), len(self.ported_func_list)+ len(self.skipped_func_list))
|
#print("Done %i of %i funcs." % (len(self.ported_func_list), len(self.ported_func_list)+ len(self.skipped_func_list)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1087,7 +1120,11 @@ extern "C" {
|
|||||||
imports.add("java.lang.String")
|
imports.add("java.lang.String")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def fullTypeName(self, t):
|
||||||
|
if t in self.classes:
|
||||||
|
return self.classes[t].fullName(isCPP=True)
|
||||||
|
else:
|
||||||
|
return t
|
||||||
|
|
||||||
def gen_func(self, fi, prop_name=''):
|
def gen_func(self, fi, prop_name=''):
|
||||||
j_code = self.java_code[fi.classname or self.Module]["j_code"]
|
j_code = self.java_code[fi.classname or self.Module]["j_code"]
|
||||||
@ -1119,7 +1156,7 @@ extern "C" {
|
|||||||
msg = "// Return type '%s' is not supported, skipping the function\n\n" % fi.ctype
|
msg = "// Return type '%s' is not supported, skipping the function\n\n" % fi.ctype
|
||||||
self.skipped_func_list.append(c_decl + "\n" + msg)
|
self.skipped_func_list.append(c_decl + "\n" + msg)
|
||||||
j_code.write( " "*4 + msg )
|
j_code.write( " "*4 + msg )
|
||||||
print "SKIP:", c_decl.strip(), "\t due to RET type", fi.ctype
|
print("SKIP:", c_decl.strip(), "\t due to RET type", fi.ctype)
|
||||||
return
|
return
|
||||||
for a in fi.args:
|
for a in fi.args:
|
||||||
if a.ctype not in type_dict:
|
if a.ctype not in type_dict:
|
||||||
@ -1131,7 +1168,7 @@ extern "C" {
|
|||||||
msg = "// Unknown type '%s' (%s), skipping the function\n\n" % (a.ctype, a.out or "I")
|
msg = "// Unknown type '%s' (%s), skipping the function\n\n" % (a.ctype, a.out or "I")
|
||||||
self.skipped_func_list.append(c_decl + "\n" + msg)
|
self.skipped_func_list.append(c_decl + "\n" + msg)
|
||||||
j_code.write( " "*4 + msg )
|
j_code.write( " "*4 + msg )
|
||||||
print "SKIP:", c_decl.strip(), "\t due to ARG type", a.ctype, "/" + (a.out or "I")
|
print("SKIP:", c_decl.strip(), "\t due to ARG type", a.ctype, "/" + (a.out or "I"))
|
||||||
return
|
return
|
||||||
|
|
||||||
self.ported_func_list.append(c_decl)
|
self.ported_func_list.append(c_decl)
|
||||||
@ -1335,9 +1372,9 @@ extern "C" {
|
|||||||
ret = "return env->NewStringUTF(_retval_.c_str());"
|
ret = "return env->NewStringUTF(_retval_.c_str());"
|
||||||
default = 'return env->NewStringUTF("");'
|
default = 'return env->NewStringUTF("");'
|
||||||
elif fi.ctype in self.classes: # wrapped class:
|
elif fi.ctype in self.classes: # wrapped class:
|
||||||
ret = "return (jlong) new %s(_retval_);" % fi.ctype
|
ret = "return (jlong) new %s(_retval_);" % self.fullTypeName(fi.ctype)
|
||||||
elif fi.ctype.startswith('Ptr_'):
|
elif fi.ctype.startswith('Ptr_'):
|
||||||
c_prologue.append("typedef Ptr<%s> %s;" % (fi.ctype[4:], fi.ctype))
|
c_prologue.append("typedef Ptr<%s> %s;" % (self.fullTypeName(fi.ctype[4:]), fi.ctype))
|
||||||
ret = "return (jlong)(new %(ctype)s(_retval_));" % { 'ctype':fi.ctype }
|
ret = "return (jlong)(new %(ctype)s(_retval_));" % { 'ctype':fi.ctype }
|
||||||
elif ret_type in self.classes: # pointer to wrapped class:
|
elif ret_type in self.classes: # pointer to wrapped class:
|
||||||
ret = "return (jlong) _retval_;"
|
ret = "return (jlong) _retval_;"
|
||||||
@ -1352,8 +1389,8 @@ extern "C" {
|
|||||||
else:
|
else:
|
||||||
name = prop_name + ";//"
|
name = prop_name + ";//"
|
||||||
|
|
||||||
cvname = "cv::" + name
|
cvname = fi.fullName(isCPP=True)
|
||||||
retval = fi.ctype + " _retval_ = "
|
retval = self.fullTypeName(fi.ctype) + " _retval_ = "
|
||||||
if fi.ctype == "void":
|
if fi.ctype == "void":
|
||||||
retval = ""
|
retval = ""
|
||||||
elif fi.ctype == "String":
|
elif fi.ctype == "String":
|
||||||
@ -1362,17 +1399,17 @@ extern "C" {
|
|||||||
retval = type_dict[fi.ctype]['jni_var'] % {"n" : '_ret_val_vector_'} + " = "
|
retval = type_dict[fi.ctype]['jni_var'] % {"n" : '_ret_val_vector_'} + " = "
|
||||||
c_epilogue.append("Mat* _retval_ = new Mat();")
|
c_epilogue.append("Mat* _retval_ = new Mat();")
|
||||||
c_epilogue.append(fi.ctype+"_to_Mat(_ret_val_vector_, *_retval_);")
|
c_epilogue.append(fi.ctype+"_to_Mat(_ret_val_vector_, *_retval_);")
|
||||||
if fi.classname:
|
if len(fi.classname)>0:
|
||||||
if not fi.ctype: # c-tor
|
if not fi.ctype: # c-tor
|
||||||
retval = fi.classname + "* _retval_ = "
|
retval = fi.fullClass(isCPP=True) + "* _retval_ = "
|
||||||
cvname = "new " + fi.classname
|
cvname = "new " + fi.fullClass(isCPP=True)
|
||||||
elif fi.static:
|
elif fi.static:
|
||||||
cvname = "%s::%s" % (fi.classname, name)
|
cvname = fi.fullName(isCPP=True)
|
||||||
else:
|
else:
|
||||||
cvname = ("me->" if not self.isSmartClass(fi.classname) else "(*me)->") + name
|
cvname = ("me->" if not self.isSmartClass(fi.classname) else "(*me)->") + name
|
||||||
c_prologue.append(\
|
c_prologue.append(\
|
||||||
"%(cls)s* me = (%(cls)s*) self; //TODO: check for NULL" \
|
"%(cls)s* me = (%(cls)s*) self; //TODO: check for NULL" \
|
||||||
% { "cls" : self.smartWrap(fi.classname)} \
|
% { "cls" : self.smartWrap(fi.classname, fi.fullClass(isCPP=True))} \
|
||||||
)
|
)
|
||||||
cvargs = []
|
cvargs = []
|
||||||
for a in args:
|
for a in args:
|
||||||
@ -1461,8 +1498,7 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname
|
|||||||
%s;\n\n""" % (",\n"+" "*12).join(["%s = %s" % (c.name, c.value) for c in ci.consts])
|
%s;\n\n""" % (",\n"+" "*12).join(["%s = %s" % (c.name, c.value) for c in ci.consts])
|
||||||
)
|
)
|
||||||
# c-tors
|
# c-tors
|
||||||
fflist = ci.methods.items()
|
fflist = sorted(ci.methods.items())
|
||||||
fflist.sort()
|
|
||||||
for n, ffi in fflist:
|
for n, ffi in fflist:
|
||||||
if ffi.isconstructor:
|
if ffi.isconstructor:
|
||||||
for fi in ffi.funcs:
|
for fi in ffi.funcs:
|
||||||
@ -1476,15 +1512,13 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname
|
|||||||
# props
|
# props
|
||||||
for pi in ci.props:
|
for pi in ci.props:
|
||||||
# getter
|
# getter
|
||||||
getter_name = name + ".get_" + pi.name
|
getter_name = ci.fullName() + ".get_" + pi.name
|
||||||
#print getter_name
|
fi = FuncInfo( [getter_name, pi.ctype, [], []], self.namespaces ) # [ funcname, return_ctype, [modifiers], [args] ]
|
||||||
fi = FuncInfo( [getter_name, pi.ctype, [], []] ) # [ funcname, return_ctype, [modifiers], [args] ]
|
|
||||||
self.gen_func(fi, pi.name)
|
self.gen_func(fi, pi.name)
|
||||||
if pi.rw:
|
if pi.rw:
|
||||||
#setter
|
#setter
|
||||||
setter_name = name + ".set_" + pi.name
|
setter_name = ci.fullName() + ".set_" + pi.name
|
||||||
#print setter_name
|
fi = FuncInfo( [ setter_name, "void", [], [ [pi.ctype, pi.name, "", [], ""] ] ], self.namespaces)
|
||||||
fi = FuncInfo( [ setter_name, "void", [], [ [pi.ctype, pi.name, "", [], ""] ] ] )
|
|
||||||
self.gen_func(fi, pi.name)
|
self.gen_func(fi, pi.name)
|
||||||
|
|
||||||
# manual ports
|
# manual ports
|
||||||
@ -1525,7 +1559,7 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete
|
|||||||
delete (%(cls)s*) self;
|
delete (%(cls)s*) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
""" % {"module" : module, "cls" : self.smartWrap(name), "j_cls" : ci.jname.replace('_', '_1')}
|
""" % {"module" : module, "cls" : self.smartWrap(ci.name, ci.fullName(isCPP=True)), "j_cls" : ci.jname.replace('_', '_1')}
|
||||||
)
|
)
|
||||||
|
|
||||||
def isSmartClass(self, classname):
|
def isSmartClass(self, classname):
|
||||||
@ -1534,21 +1568,21 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete
|
|||||||
'''
|
'''
|
||||||
return classname in self.classes and self.classes[classname].base
|
return classname in self.classes and self.classes[classname].base
|
||||||
|
|
||||||
def smartWrap(self, classname):
|
def smartWrap(self, name, fullname):
|
||||||
'''
|
'''
|
||||||
Wraps class name with Ptr<> if needed
|
Wraps fullname with Ptr<> if needed
|
||||||
'''
|
'''
|
||||||
if self.isSmartClass(classname):
|
if self.isSmartClass(name):
|
||||||
return "Ptr<" + classname + ">"
|
return "Ptr<" + fullname + ">"
|
||||||
return classname
|
return fullname
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 4:
|
if len(sys.argv) < 4:
|
||||||
print "Usage:\n", \
|
print("Usage:\n", \
|
||||||
os.path.basename(sys.argv[0]), \
|
os.path.basename(sys.argv[0]), \
|
||||||
"<full path to hdr_parser.py> <module name> <C++ header> [<C++ header>...]"
|
"<full path to hdr_parser.py> <module name> <C++ header> [<C++ header>...]")
|
||||||
print "Current args are: ", ", ".join(["'"+a+"'" for a in sys.argv])
|
print("Current args are: ", ", ".join(["'"+a+"'" for a in sys.argv]))
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
dstdir = "."
|
dstdir = "."
|
||||||
@ -1559,6 +1593,7 @@ if __name__ == "__main__":
|
|||||||
import hdr_parser
|
import hdr_parser
|
||||||
module = sys.argv[2]
|
module = sys.argv[2]
|
||||||
srcfiles = sys.argv[3:]
|
srcfiles = sys.argv[3:]
|
||||||
#print "Generating module '" + module + "' from headers:\n\t" + "\n\t".join(srcfiles)
|
logging.basicConfig(filename='%s/%s.log' % (dstdir, module), filemode='w', level=logging.INFO)
|
||||||
|
#print("Generating module '" + module + "' from headers:\n\t" + "\n\t".join(srcfiles))
|
||||||
generator = JavaWrapperGenerator()
|
generator = JavaWrapperGenerator()
|
||||||
generator.gen(srcfiles, module, dstdir)
|
generator.gen(srcfiles, module, dstdir)
|
||||||
|
@ -18,6 +18,8 @@ ocv_list_filterout(candidate_deps "^opencv_matlab$")
|
|||||||
ocv_list_filterout(candidate_deps "^opencv_ts$")
|
ocv_list_filterout(candidate_deps "^opencv_ts$")
|
||||||
ocv_list_filterout(candidate_deps "^opencv_adas$")
|
ocv_list_filterout(candidate_deps "^opencv_adas$")
|
||||||
ocv_list_filterout(candidate_deps "^opencv_tracking$")
|
ocv_list_filterout(candidate_deps "^opencv_tracking$")
|
||||||
|
ocv_list_filterout(candidate_deps "^opencv_bioinspired$")
|
||||||
|
ocv_list_filterout(candidate_deps "^opencv_java$")
|
||||||
|
|
||||||
ocv_add_module(${MODULE_NAME} BINDINGS OPTIONAL ${candidate_deps})
|
ocv_add_module(${MODULE_NAME} BINDINGS OPTIONAL ${candidate_deps})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user