Matlab constants now being parsed correctly. Over 700 constants correctly formatted :)
This commit is contained in:
parent
ef6327bb89
commit
fc519aa3b3
@ -51,8 +51,7 @@ ocv_add_module(matlab BINDINGS
|
||||
opencv_nonfree
|
||||
)
|
||||
|
||||
# TODO: Undo this when building all modules to find python properly
|
||||
#set(HDR_PARSER_PATH ${OPENCV_MODULE_opencv_python_LOCATION}/src2)
|
||||
# set the path to the C++ header parser
|
||||
set(HDR_PARSER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../python/src2)
|
||||
|
||||
# set mex compiler options
|
||||
|
@ -51,6 +51,25 @@ def convertibleToInt(string):
|
||||
except:
|
||||
return False
|
||||
|
||||
def binaryToDecimal(string):
|
||||
try:
|
||||
return str(eval(string))
|
||||
except:
|
||||
return string
|
||||
|
||||
def formatMatlabConstant(string, table):
|
||||
import re
|
||||
# split the string into expressions
|
||||
words = re.split('(\W+)', string)
|
||||
# add a 'cv' prefix if an expression is also a key in the lookup table
|
||||
words = ''.join([('cv.'+word if word in table else word) for word in words])
|
||||
# attempt to convert arithmetic expressions and binary/hex to decimal
|
||||
words = binaryToDecimal(words)
|
||||
# convert any remaining bitshifts to Matlab 'bitshift' methods
|
||||
shift = re.sub('[\(\) ]', '', words).split('<<')
|
||||
words = 'bitshift('+shift[0]+', '+shift[1]+')' if len(shift) == 2 else words
|
||||
return words
|
||||
|
||||
def capitalizeFirst(text):
|
||||
return text[0].upper() + text[1:]
|
||||
|
||||
|
@ -20,6 +20,7 @@ class MatlabWrapperGenerator(object):
|
||||
jtemplate = Environment(loader=PackageLoader('templates', ''), trim_blocks=True, lstrip_blocks=True)
|
||||
|
||||
# add the custom filters
|
||||
jtemplate.filters['formatMatlabConstant'] = formatMatlabConstant
|
||||
jtemplate.filters['convertibleToInt'] = convertibleToInt
|
||||
jtemplate.filters['toUpperCamelCase'] = toUpperCamelCase
|
||||
jtemplate.filters['toLowerCamelCase'] = toLowerCamelCase
|
||||
@ -38,8 +39,7 @@ class MatlabWrapperGenerator(object):
|
||||
tclassm = jtemplate.get_template('template_class_base.m')
|
||||
tclassc = jtemplate.get_template('template_class_base.cpp')
|
||||
tdoc = jtemplate.get_template('template_doc_base.m')
|
||||
tconstc = jtemplate.get_template('template_map_base.cpp')
|
||||
tconstm = jtemplate.get_template('template_map_base.m')
|
||||
tconst = jtemplate.get_template('template_map_base.m')
|
||||
|
||||
# create the build directory
|
||||
output_source_dir = output_dir+'/src'
|
||||
@ -75,12 +75,9 @@ class MatlabWrapperGenerator(object):
|
||||
|
||||
# create a global constants lookup table
|
||||
const = dict(constants(todict(parse_tree.namespaces)))
|
||||
populatedc = tconstc.render(constants=const)
|
||||
populatedm = tconstm.render(constants=const)
|
||||
with open(output_map_dir+'/map.cpp', 'wb') as f:
|
||||
f.write(populatedc)
|
||||
populated = tconst.render(constants=const)
|
||||
with open(output_dir+'/cv.m', 'wb') as f:
|
||||
f.write(populatedm)
|
||||
f.write(populated)
|
||||
|
||||
|
||||
|
||||
|
@ -23,11 +23,7 @@
|
||||
classdef cv
|
||||
properties (Constant = true)
|
||||
{% for key, val in constants.items() %}
|
||||
{% if val|convertibleToInt %}
|
||||
{{key}} = {{val}};
|
||||
{% else %}
|
||||
{{key}} = {{constants[val]}};
|
||||
{% endif %}
|
||||
{{key}} = {{val|formatMatlabConstant(constants)}};
|
||||
{% endfor %}
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user