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
|
opencv_nonfree
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: Undo this when building all modules to find python properly
|
# set the path to the C++ header parser
|
||||||
#set(HDR_PARSER_PATH ${OPENCV_MODULE_opencv_python_LOCATION}/src2)
|
|
||||||
set(HDR_PARSER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../python/src2)
|
set(HDR_PARSER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../python/src2)
|
||||||
|
|
||||||
# set mex compiler options
|
# set mex compiler options
|
||||||
|
@ -51,6 +51,25 @@ def convertibleToInt(string):
|
|||||||
except:
|
except:
|
||||||
return False
|
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):
|
def capitalizeFirst(text):
|
||||||
return text[0].upper() + text[1:]
|
return text[0].upper() + text[1:]
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ class MatlabWrapperGenerator(object):
|
|||||||
jtemplate = Environment(loader=PackageLoader('templates', ''), trim_blocks=True, lstrip_blocks=True)
|
jtemplate = Environment(loader=PackageLoader('templates', ''), trim_blocks=True, lstrip_blocks=True)
|
||||||
|
|
||||||
# add the custom filters
|
# add the custom filters
|
||||||
|
jtemplate.filters['formatMatlabConstant'] = formatMatlabConstant
|
||||||
jtemplate.filters['convertibleToInt'] = convertibleToInt
|
jtemplate.filters['convertibleToInt'] = convertibleToInt
|
||||||
jtemplate.filters['toUpperCamelCase'] = toUpperCamelCase
|
jtemplate.filters['toUpperCamelCase'] = toUpperCamelCase
|
||||||
jtemplate.filters['toLowerCamelCase'] = toLowerCamelCase
|
jtemplate.filters['toLowerCamelCase'] = toLowerCamelCase
|
||||||
@ -38,8 +39,7 @@ class MatlabWrapperGenerator(object):
|
|||||||
tclassm = jtemplate.get_template('template_class_base.m')
|
tclassm = jtemplate.get_template('template_class_base.m')
|
||||||
tclassc = jtemplate.get_template('template_class_base.cpp')
|
tclassc = jtemplate.get_template('template_class_base.cpp')
|
||||||
tdoc = jtemplate.get_template('template_doc_base.m')
|
tdoc = jtemplate.get_template('template_doc_base.m')
|
||||||
tconstc = jtemplate.get_template('template_map_base.cpp')
|
tconst = jtemplate.get_template('template_map_base.m')
|
||||||
tconstm = jtemplate.get_template('template_map_base.m')
|
|
||||||
|
|
||||||
# create the build directory
|
# create the build directory
|
||||||
output_source_dir = output_dir+'/src'
|
output_source_dir = output_dir+'/src'
|
||||||
@ -75,12 +75,9 @@ class MatlabWrapperGenerator(object):
|
|||||||
|
|
||||||
# create a global constants lookup table
|
# create a global constants lookup table
|
||||||
const = dict(constants(todict(parse_tree.namespaces)))
|
const = dict(constants(todict(parse_tree.namespaces)))
|
||||||
populatedc = tconstc.render(constants=const)
|
populated = tconst.render(constants=const)
|
||||||
populatedm = tconstm.render(constants=const)
|
|
||||||
with open(output_map_dir+'/map.cpp', 'wb') as f:
|
|
||||||
f.write(populatedc)
|
|
||||||
with open(output_dir+'/cv.m', 'wb') as f:
|
with open(output_dir+'/cv.m', 'wb') as f:
|
||||||
f.write(populatedm)
|
f.write(populated)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,11 +23,7 @@
|
|||||||
classdef cv
|
classdef cv
|
||||||
properties (Constant = true)
|
properties (Constant = true)
|
||||||
{% for key, val in constants.items() %}
|
{% for key, val in constants.items() %}
|
||||||
{% if val|convertibleToInt %}
|
{{key}} = {{val|formatMatlabConstant(constants)}};
|
||||||
{{key}} = {{val}};
|
|
||||||
{% else %}
|
|
||||||
{{key}} = {{constants[val]}};
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user