Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
fc519aa3
Commit
fc519aa3
authored
Jun 28, 2013
by
hbristow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Matlab constants now being parsed correctly. Over 700 constants correctly formatted :)
parent
ef6327bb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
14 deletions
+25
-14
CMakeLists.txt
modules/matlab/CMakeLists.txt
+1
-2
filters.py
modules/matlab/generator/filters.py
+19
-0
gen_matlab.py
modules/matlab/generator/gen_matlab.py
+4
-7
template_map_base.m
modules/matlab/generator/templates/template_map_base.m
+1
-5
No files found.
modules/matlab/CMakeLists.txt
View file @
fc519aa3
...
...
@@ -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
...
...
modules/matlab/generator/filters.py
View file @
fc519aa3
...
...
@@ -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
:]
...
...
modules/matlab/generator/gen_matlab.py
View file @
fc519aa3
...
...
@@ -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
(
populated
m
)
f
.
write
(
populated
)
...
...
modules/matlab/generator/templates/template_map_base.m
View file @
fc519aa3
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment