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
e51bdbeb
Commit
e51bdbeb
authored
Jun 26, 2013
by
hbristow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All OpenCV constants being exported into matlab class and C++ map templates
parent
0b9ff115
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
2 deletions
+45
-2
gen_matlab.py
modules/matlab/generator/gen_matlab.py
+15
-1
parse_tree.py
modules/matlab/generator/parse_tree.py
+12
-1
template_map_base.cpp
modules/matlab/generator/templates/template_map_base.cpp
+11
-0
template_map_base.m
modules/matlab/generator/templates/template_map_base.m
+7
-0
No files found.
modules/matlab/generator/gen_matlab.py
View file @
e51bdbeb
...
...
@@ -38,17 +38,22 @@ 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'
)
# create the build directory
output_source_dir
=
output_dir
+
'/src'
output_private_dir
=
output_source_dir
+
'/private'
output_class_dir
=
output_dir
+
'/+cv'
output_map_dir
=
output_dir
+
'/map'
if
not
os
.
path
.
isdir
(
output_source_dir
):
os
.
mkdir
(
output_source_dir
)
if
not
os
.
path
.
isdir
(
output_private_dir
):
os
.
mkdir
(
output_private_dir
)
if
not
os
.
path
.
isdir
(
output_class_dir
):
os
.
mkdir
(
output_class_dir
)
if
not
os
.
path
.
isdir
(
output_map_dir
):
os
.
mkdir
(
output_map_dir
)
# populate templates
for
namespace
in
parse_tree
.
namespaces
:
...
...
@@ -68,6 +73,15 @@ class MatlabWrapperGenerator(object):
with
open
(
output_class_dir
+
'/'
+
clss
.
name
+
'.m'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
# 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
)
with
open
(
output_map_dir
+
'/map.m'
,
'wb'
)
as
f
:
f
.
write
(
populatedm
)
if
__name__
==
"__main__"
:
...
...
@@ -77,7 +91,7 @@ if __name__ == "__main__":
sys
.
path
.
append
(
sys
.
argv
[
1
])
from
string
import
Template
from
hdr_parser
import
CppHeaderParser
from
parse_tree
import
ParseTree
,
todict
from
parse_tree
import
ParseTree
,
todict
,
constants
from
filters
import
*
from
jinja2
import
Environment
,
PackageLoader
...
...
modules/matlab/generator/parse_tree.py
View file @
e51bdbeb
...
...
@@ -172,7 +172,18 @@ class Constant(object):
return
(
'const '
if
self
.
const
else
''
)
+
self
.
tp
+
self
.
ref
+
\
' '
+
self
.
name
+
(
'='
+
self
.
default
if
self
.
default
else
''
)
+
';'
def
constants
(
tree
):
if
isinstance
(
tree
,
dict
)
and
'constants'
in
tree
and
isinstance
(
tree
[
'constants'
],
list
):
for
node
in
tree
[
'constants'
]:
yield
(
node
[
'name'
],
node
[
'default'
])
if
isinstance
(
tree
,
dict
):
for
key
,
val
in
tree
.
items
():
for
gen
in
constants
(
val
):
yield
gen
if
isinstance
(
tree
,
list
):
for
val
in
tree
:
for
gen
in
constants
(
val
):
yield
gen
def
todict
(
obj
,
classkey
=
None
):
if
isinstance
(
obj
,
dict
):
...
...
modules/matlab/generator/templates/template_map_base.cpp
0 → 100644
View file @
e51bdbeb
#include <unordered_map>
#include <string>
#include <bridge>
typedef
std
::
unordered_map
Map
;
Map
<
std
::
string
,
int
>
constants
=
{
{
%
for
key
,
val
in
constants
.
items
()
%
}
{
"{{key}}"
,
{{
val
}}
},
{
%
endfor
%
}
};
modules/matlab/generator/templates/template_map_base.m
0 → 100644
View file @
e51bdbeb
classdef
cv
properties
(
Constant
=
true
)
{% for key, val in constants.items() %}
{{
key
}}
=
{{
val
}};
{% 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