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
eda32520
Commit
eda32520
authored
Mar 18, 2013
by
Hilton Bristow
Committed by
hbristow
Jun 17, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved tempalte formatting
parent
66c40bee
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
57 deletions
+60
-57
CMakeLists.txt
modules/matlab/CMakeLists.txt
+7
-21
gen_matlab.py
modules/matlab/generator/gen_matlab.py
+30
-13
defaults.py
modules/matlab/generator/jinja2/defaults.py
+0
-1
environment.py
modules/matlab/generator/jinja2/environment.py
+0
-1
parse_tree.py
modules/matlab/generator/parse_tree.py
+2
-2
template_class_base.cpp
modules/matlab/generator/templates/template_class_base.cpp
+12
-10
template_class_base.m
modules/matlab/generator/templates/template_class_base.m
+9
-9
No files found.
modules/matlab/CMakeLists.txt
View file @
eda32520
...
@@ -14,25 +14,13 @@ ocv_add_module(matlab BINDINGS opencv_core opencv_imgproc
...
@@ -14,25 +14,13 @@ ocv_add_module(matlab BINDINGS opencv_core opencv_imgproc
opencv_nonfree opencv_calib
)
opencv_nonfree opencv_calib
)
# Add all of the headers we wish to parse
# Add all of the headers we wish to parse
set
(
opencv_hdrs
string
(
REPLACE
"opencv_"
""
OPENCV_MATLAB_MODULES
"
${
OPENCV_MODULE_
${
the_module
}
_REQ_DEPS
}
;
"
${
OPENCV_MODULE_opencv_core_LOCATION
}
/include/opencv2/core/core.hpp"
${
OPENCV_MODULE_
${
the_module
}
_OPT_DEPS
}
"
)
"
${
OPENCV_MODULE_opencv_flann_LOCATION
}
/include/opencv2/flann/miniflann.hpp"
foreach
(
module
${
OPENCV_MATLAB_MODULES
}
)
"
${
OPENCV_MODULE_opencv_imgproc_LOCATION
}
/include/opencv2/imgproc/imgproc.hpp"
if
(
HAVE_opencv_
${
module
}
)
"
${
OPENCV_MODULE_opencv_video_LOCATION
}
/include/opencv2/video/background_segm.hpp"
list
(
APPEND opencv_hdrs
"
${
OPENCV_MODULE_opencv_
${
module
}
_LOCATION
}
/include/opencv2/
${
module
}
/
${
module
}
.hpp"
)
"
${
OPENCV_MODULE_opencv_video_LOCATION
}
/include/opencv2/video/tracking.hpp"
"
${
OPENCV_MODULE_opencv_photo_LOCATION
}
/include/opencv2/photo/photo.hpp"
"
${
OPENCV_MODULE_opencv_highgui_LOCATION
}
/include/opencv2/highgui/highgui.hpp"
"
${
OPENCV_MODULE_opencv_ml_LOCATION
}
/include/opencv2/ml/ml.hpp"
"
${
OPENCV_MODULE_opencv_features2d_LOCATION
}
/include/opencv2/features2d/features2d.hpp"
"
${
OPENCV_MODULE_opencv_calib3d_LOCATION
}
/include/opencv2/calib3d/calib3d.hpp"
"
${
OPENCV_MODULE_opencv_objdetect_LOCATION
}
/include/opencv2/objdetect/objdetect.hpp"
"
${
OPENCV_MODULE_opencv_softcascade_LOCATION
}
/include/opencv2/softcascade/softcascade.hpp"
"
${
OPENCV_MODULE_opencv_contrib_LOCATION
}
/include/opencv2/contrib/contrib.hpp"
)
if
(
HAVE_opencv_nonfree
)
list
(
APPEND opencv_hdrs
"
${
OPENCV_MODULE_opencv_nonfree_LOCATION
}
/include/opencv2/nonfree/features2d.hpp"
"
${
OPENCV_MODULE_opencv_nonfree_LOCATION
}
/include/opencv2/nonfree/nonfree.hpp"
)
endif
()
endif
()
endforeach
()
# add the python generator to the python path
# add the python generator to the python path
set
(
PYPATH_CACHE $ENV{PYTHONPATH}
)
set
(
PYPATH_CACHE $ENV{PYTHONPATH}
)
...
@@ -41,7 +29,7 @@ set(ENV{PYTHONPATH} ${OPENCV_MODULE_opencv_python_LOCATION}/src2:$ENV{PYTHONPATH
...
@@ -41,7 +29,7 @@ set(ENV{PYTHONPATH} ${OPENCV_MODULE_opencv_python_LOCATION}/src2:$ENV{PYTHONPATH
# synthesise the matlab sources
# synthesise the matlab sources
execute_process
(
execute_process
(
COMMAND
${
PYTHON_EXECUTABLE
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/generator/gen_matlab_caller.py
COMMAND
${
PYTHON_EXECUTABLE
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/generator/gen_matlab_caller.py
${
opencv_hdrs
}
${
CMAKE_CURRENT_BINARY_DIR
}
/src
)
${
opencv_hdrs
}
${
CMAKE_CURRENT_BINARY_DIR
}
)
# compile the matlab sources
# compile the matlab sources
file
(
GLOB SOURCE_FILES
${
CMAKE_CURRENT_BINARY_DIR
}
/src
)
file
(
GLOB SOURCE_FILES
${
CMAKE_CURRENT_BINARY_DIR
}
/src
)
...
@@ -49,7 +37,5 @@ foreach(SOURCE_FILE ${SOURCE_FILES})
...
@@ -49,7 +37,5 @@ foreach(SOURCE_FILE ${SOURCE_FILES})
# compile the source file using mex
# compile the source file using mex
endforeach
()
endforeach
()
# restore the pythonpath
# restore the pythonpath
set
(
ENV{PYTHONPATH}
${
PYPATH_CACHE
}
)
set
(
ENV{PYTHONPATH}
${
PYPATH_CACHE
}
)
modules/matlab/generator/gen_matlab.py
View file @
eda32520
...
@@ -39,17 +39,34 @@ class MatlabWrapperGenerator(object):
...
@@ -39,17 +39,34 @@ class MatlabWrapperGenerator(object):
tdoc
=
jtemplate
.
get_template
(
'template_doc_base.m'
)
tdoc
=
jtemplate
.
get_template
(
'template_doc_base.m'
)
# create the build directory
# create the build directory
if
not
os
.
path
.
isdir
(
output_dir
):
output_source_dir
=
output_dir
+
'/src'
os
.
mkdir
(
output_dir
)
output_private_dir
=
output_source_dir
+
'/private'
output_class_dir
=
output_dir
+
'/+cv'
# populate!
if
not
os
.
path
.
isdir
(
output_source_dir
):
function
=
parse_tree
.
namespaces
[
0
]
.
functions
[
0
]
os
.
mkdir
(
output_source_dir
)
print
function
if
not
os
.
path
.
isdir
(
output_private_dir
):
populated
=
tfunction
.
render
(
fun
=
function
,
time
=
time
)
os
.
mkdir
(
output_private_dir
)
with
open
(
output_dir
+
'/'
+
function
.
name
+
'.cpp'
,
'wb'
)
as
f
:
if
not
os
.
path
.
isdir
(
output_class_dir
):
f
.
write
(
populated
)
os
.
mkdir
(
output_class_dir
)
#for name, namespace in ns:
# for function in namespace.functions:
# populate templates
# print 'populating function tempaltes from '+name
for
namespace
in
parse_tree
.
namespaces
:
# populated = tfunction.render(function)
print
'populating function templates from '
+
namespace
.
name
# functions
for
function
in
namespace
.
functions
:
populated
=
tfunction
.
render
(
fun
=
function
,
time
=
time
)
with
open
(
output_source_dir
+
'/'
+
function
.
name
+
'.cpp'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
# classes
for
clss
in
namespace
.
classes
:
# cpp converter
if
len
(
clss
.
functions
)
>
2
:
print
clss
.
functions
[
1
]
.
__str__
()
populated
=
tclassc
.
render
(
clss
=
clss
,
time
=
time
)
with
open
(
output_private_dir
+
'/'
+
clss
.
name
+
'Bridge.cpp'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
# matlab classdef
populated
=
tclassm
.
render
(
clss
=
clss
,
time
=
time
)
with
open
(
output_class_dir
+
'/'
+
clss
.
name
+
'.m'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
modules/matlab/generator/jinja2/defaults.py
View file @
eda32520
...
@@ -26,7 +26,6 @@ NEWLINE_SEQUENCE = '\n'
...
@@ -26,7 +26,6 @@ NEWLINE_SEQUENCE = '\n'
# default filters, tests and namespace
# default filters, tests and namespace
from
jinja2.filters
import
FILTERS
as
DEFAULT_FILTERS
from
jinja2.filters
import
FILTERS
as
DEFAULT_FILTERS
from
jinja2.tests
import
TESTS
as
DEFAULT_TESTS
DEFAULT_NAMESPACE
=
{
DEFAULT_NAMESPACE
=
{
'range'
:
xrange
,
'range'
:
xrange
,
'dict'
:
lambda
**
kw
:
kw
,
'dict'
:
lambda
**
kw
:
kw
,
...
...
modules/matlab/generator/jinja2/environment.py
View file @
eda32520
...
@@ -265,7 +265,6 @@ class Environment(object):
...
@@ -265,7 +265,6 @@ class Environment(object):
# defaults
# defaults
self
.
filters
=
DEFAULT_FILTERS
.
copy
()
self
.
filters
=
DEFAULT_FILTERS
.
copy
()
self
.
tests
=
DEFAULT_TESTS
.
copy
()
self
.
globals
=
DEFAULT_NAMESPACE
.
copy
()
self
.
globals
=
DEFAULT_NAMESPACE
.
copy
()
# set the loader provided
# set the loader provided
...
...
modules/matlab/generator/parse_tree.py
View file @
eda32520
...
@@ -133,9 +133,9 @@ class Function(object):
...
@@ -133,9 +133,9 @@ class Function(object):
self
.
opt
=
opt
if
opt
else
[]
self
.
opt
=
opt
if
opt
else
[]
def
__str__
(
self
):
def
__str__
(
self
):
return
fill
(
(
self
.
rtp
+
' '
if
self
.
rtp
else
''
)
+
self
.
name
+
'('
+
\
return
(
self
.
rtp
+
' '
if
self
.
rtp
else
''
)
+
self
.
name
+
'('
+
\
join
((
arg
.
__str__
()
for
arg
in
self
.
req
+
self
.
opt
),
', '
)
+
\
join
((
arg
.
__str__
()
for
arg
in
self
.
req
+
self
.
opt
),
', '
)
+
\
')'
+
(
' const'
if
self
.
const
else
''
)
+
';'
,
80
,
subsequent_indent
=
(
'
\t\t
'
if
self
.
clss
else
'
\t
'
))
')'
+
(
' const'
if
self
.
const
else
''
)
+
';'
class
Argument
(
object
):
class
Argument
(
object
):
def
__init__
(
self
,
name
=
''
,
tp
=
''
,
const
=
False
,
ref
=
''
,
default
=
''
):
def
__init__
(
self
,
name
=
''
,
tp
=
''
,
const
=
False
,
ref
=
''
,
default
=
''
):
...
...
modules/matlab/generator/templates/template_class_base.cpp
View file @
eda32520
/*
/*
* file: {{cl
a
ss.name}}Bridge.cpp
* file: {{clss.name}}Bridge.cpp
* author: A trusty code generator
* author: A trusty code generator
* date: {{time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())}}
* date: {{time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())}}
*
*
...
@@ -18,34 +18,35 @@
...
@@ -18,34 +18,35 @@
namespace
{
namespace
{
typedef
std
::
unordered_map
Map
;
typedef
std
::
unordered_map
Map
;
typedef
std
::
vector
<
Bridge
>
(
*
)({{
cl
a
ss
.
name
}}
&
,
const
std
::
vector
<
Bridge
>&
)
MethodSignature
;
typedef
std
::
vector
<
Bridge
>
(
*
)({{
clss
.
name
}}
&
,
const
std
::
vector
<
Bridge
>&
)
MethodSignature
;
{
%
for
function
in
cl
a
ss
.
functions
%
}
{
%
for
function
in
clss
.
functions
%
}
// wrapper for {{function.name}}() method
// wrapper for {{function.name}}() method
std
::
vector
<
Bridge
>
{{
function
.
name
}}({{
cl
a
ss
.
name
}}
&
inst
,
const
std
::
vector
<
Bridge
>&
args
)
{
std
::
vector
<
Bridge
>
{{
function
.
name
}}({{
clss
.
name
}}
&
inst
,
const
std
::
vector
<
Bridge
>&
args
)
{
// setup
// setup
// invoke
// invoke
// setdown
// setdown
}
}
{
%
endfor
%
}
{
%
endfor
%
}
map
<
std
::
string
,
MethodSignature
>
createMethodMap
()
{
map
<
std
::
string
,
MethodSignature
>
createMethodMap
()
{
Map
<
std
::
string
,
MethodSignature
>
m
;
Map
<
std
::
string
,
MethodSignature
>
m
;
{
%
for
function
in
cl
ass
.
functions
%
}
{
%
for
function
in
cl
ss
.
functions
-
%
}
m
[
"{{function.name}}"
]
=
&
{{
function
.
name
}};
m
[
"{{function.name}}"
]
=
&
{{
function
.
name
}};
{
%
endfor
%
}
{
%
endfor
%
}
return
m
;
return
m
;
}
}
static
const
Map
<
std
::
string
,
MethodSignature
>
methods
=
createMethodMap
();
static
const
Map
<
std
::
string
,
MethodSignature
>
methods
=
createMethodMap
();
// map of created {{cl
a
ss.name}} instances. Don't trust the user to keep them safe...
// map of created {{clss.name}} instances. Don't trust the user to keep them safe...
static
Map
<
void
*
,
{{
cl
a
ss
.
name
}}
>
instances
;
static
Map
<
void
*
,
{{
clss
.
name
}}
>
instances
;
/*
/*
* {{ cl
a
ss.name }}
* {{ clss.name }}
* Gateway routine
* Gateway routine
* nlhs - number of return arguments
* nlhs - number of return arguments
* plhs - pointers to return arguments
* plhs - pointers to return arguments
...
@@ -63,7 +64,7 @@ void mexFunction(int nlhs, mxArray* plhs[],
...
@@ -63,7 +64,7 @@ void mexFunction(int nlhs, mxArray* plhs[],
// retrieve the instance of interest
// retrieve the instance of interest
try
{
try
{
{{
cl
a
ss
.
name
}}
&
inst
=
instances
.
at
(
handle
.
address
());
{{
clss
.
name
}}
&
inst
=
instances
.
at
(
handle
.
address
());
}
catch
(
const
std
::
out_of_range
&
e
)
{
}
catch
(
const
std
::
out_of_range
&
e
)
{
mexErrMsgTxt
(
"Invalid object instance provided"
);
mexErrMsgTxt
(
"Invalid object instance provided"
);
}
}
...
@@ -80,6 +81,7 @@ void mexFunction(int nlhs, mxArray* plhs[],
...
@@ -80,6 +81,7 @@ void mexFunction(int nlhs, mxArray* plhs[],
{
%
block
cleanup
%
}
{
%
block
cleanup
%
}
{
%
endblock
%
}
{
%
endblock
%
}
}
}
};
// end namespace
};
// end namespace
modules/matlab/generator/templates/template_class_base.m
View file @
eda32520
% {{cl
a
ss.name | upper}}
% {{clss.name | upper}}
% Matlab handle cl
ass for OpenCV object cla
sses
% Matlab handle cl
ss for OpenCV object cl
sses
%
%
% This file was autogenerated, do not modify.
% This file was autogenerated, do not modify.
% See LICENCE for full modification and redistribution details.
% See LICENCE for full modification and redistribution details.
% Copyright {{time.strftime("%Y", time.localtime())}} The OpenCV Foundation
% Copyright {{time.strftime("%Y", time.localtime())}} The OpenCV Foundation
classdef
{{
cl
a
ss
.
name
}}
<
handle
classdef
{{
clss
.
name
}}
<
handle
properties
(
SetAccess
=
private
,
Hidden
=
true
)
properties
(
SetAccess
=
private
,
Hidden
=
true
)
ptr_
=
0
;
% handle to the underlying c++ cl
a
ss instance
ptr_
=
0
;
% handle to the underlying c++ clss instance
end
end
methods
methods
% constructor
% constructor
function
this
=
{{
cl
a
ss
.
name
}}(
varargin
)
function
this
=
{{
clss
.
name
}}(
varargin
)
this
.
ptr_
=
{{
cl
a
ss
.
name
}}
Bridge
(
'new'
,
varargin
{:});
this
.
ptr_
=
{{
clss
.
name
}}
Bridge
(
'new'
,
varargin
{:});
end
end
% destructor
% destructor
function
delete
(
this
)
function
delete
(
this
)
{{
cl
assN
ame
}}
Bridge
(
this
.
ptr_
,
'delete'
);
{{
cl
ss
.
n
ame
}}
Bridge
(
this
.
ptr_
,
'delete'
);
end
end
{% for function in cl
ass.functions
%}
{% for function in cl
ss.functions -
%}
% {{function.__str__()}}
% {{function.__str__()}}
function
varargout
=
{{
function
.
name
}}(
this
,
varargin
)
function
varargout
=
{{
function
.
name
}}(
this
,
varargin
)
[
varargout
{
1
:
nargout
}]
=
{{
cl
a
ss
.
name
}}
Bridge
(
'{{function.name}}'
,
this
.
ptr_
,
varargin
{:});
[
varargout
{
1
:
nargout
}]
=
{{
clss
.
name
}}
Bridge
(
'{{function.name}}'
,
this
.
ptr_
,
varargin
{:});
end
end
{% endfor %}
{% endfor %}
...
...
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