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
opencv_nonfree opencv_calib
)
# Add all of the headers we wish to parse
set
(
opencv_hdrs
"
${
OPENCV_MODULE_opencv_core_LOCATION
}
/include/opencv2/core/core.hpp"
"
${
OPENCV_MODULE_opencv_flann_LOCATION
}
/include/opencv2/flann/miniflann.hpp"
"
${
OPENCV_MODULE_opencv_imgproc_LOCATION
}
/include/opencv2/imgproc/imgproc.hpp"
"
${
OPENCV_MODULE_opencv_video_LOCATION
}
/include/opencv2/video/background_segm.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"
)
string
(
REPLACE
"opencv_"
""
OPENCV_MATLAB_MODULES
"
${
OPENCV_MODULE_
${
the_module
}
_REQ_DEPS
}
;
${
OPENCV_MODULE_
${
the_module
}
_OPT_DEPS
}
"
)
foreach
(
module
${
OPENCV_MATLAB_MODULES
}
)
if
(
HAVE_opencv_
${
module
}
)
list
(
APPEND opencv_hdrs
"
${
OPENCV_MODULE_opencv_
${
module
}
_LOCATION
}
/include/opencv2/
${
module
}
/
${
module
}
.hpp"
)
endif
()
endforeach
()
# add the python generator to the python path
set
(
PYPATH_CACHE $ENV{PYTHONPATH}
)
...
...
@@ -41,7 +29,7 @@ set(ENV{PYTHONPATH} ${OPENCV_MODULE_opencv_python_LOCATION}/src2:$ENV{PYTHONPATH
# synthesise the matlab sources
execute_process
(
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
file
(
GLOB SOURCE_FILES
${
CMAKE_CURRENT_BINARY_DIR
}
/src
)
...
...
@@ -49,7 +37,5 @@ foreach(SOURCE_FILE ${SOURCE_FILES})
# compile the source file using mex
endforeach
()
# restore the pythonpath
set
(
ENV{PYTHONPATH}
${
PYPATH_CACHE
}
)
modules/matlab/generator/gen_matlab.py
View file @
eda32520
...
...
@@ -39,17 +39,34 @@ class MatlabWrapperGenerator(object):
tdoc
=
jtemplate
.
get_template
(
'template_doc_base.m'
)
# create the build directory
if
not
os
.
path
.
isdir
(
output_dir
):
os
.
mkdir
(
output_dir
)
# populate!
function
=
parse_tree
.
namespaces
[
0
]
.
functions
[
0
]
print
function
populated
=
tfunction
.
render
(
fun
=
function
,
time
=
time
)
with
open
(
output_dir
+
'/'
+
function
.
name
+
'.cpp'
,
'wb'
)
as
f
:
f
.
write
(
populated
)
#for name, namespace in ns:
# for function in namespace.functions:
# print 'populating function tempaltes from '+name
# populated = tfunction.render(function)
output_source_dir
=
output_dir
+
'/src'
output_private_dir
=
output_source_dir
+
'/private'
output_class_dir
=
output_dir
+
'/+cv'
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
)
# populate templates
for
namespace
in
parse_tree
.
namespaces
:
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'
# default filters, tests and namespace
from
jinja2.filters
import
FILTERS
as
DEFAULT_FILTERS
from
jinja2.tests
import
TESTS
as
DEFAULT_TESTS
DEFAULT_NAMESPACE
=
{
'range'
:
xrange
,
'dict'
:
lambda
**
kw
:
kw
,
...
...
modules/matlab/generator/jinja2/environment.py
View file @
eda32520
...
...
@@ -265,7 +265,6 @@ class Environment(object):
# defaults
self
.
filters
=
DEFAULT_FILTERS
.
copy
()
self
.
tests
=
DEFAULT_TESTS
.
copy
()
self
.
globals
=
DEFAULT_NAMESPACE
.
copy
()
# set the loader provided
...
...
modules/matlab/generator/parse_tree.py
View file @
eda32520
...
...
@@ -133,9 +133,9 @@ class Function(object):
self
.
opt
=
opt
if
opt
else
[]
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
),
', '
)
+
\
')'
+
(
' const'
if
self
.
const
else
''
)
+
';'
,
80
,
subsequent_indent
=
(
'
\t\t
'
if
self
.
clss
else
'
\t
'
))
')'
+
(
' const'
if
self
.
const
else
''
)
+
';'
class
Argument
(
object
):
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
* date: {{time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())}}
*
...
...
@@ -18,34 +18,35 @@
namespace
{
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
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
// invoke
// setdown
}
{
%
endfor
%
}
map
<
std
::
string
,
MethodSignature
>
createMethodMap
()
{
Map
<
std
::
string
,
MethodSignature
>
m
;
{
%
for
function
in
cl
ass
.
functions
%
}
{
%
for
function
in
cl
ss
.
functions
-
%
}
m
[
"{{function.name}}"
]
=
&
{{
function
.
name
}};
{
%
endfor
%
}
return
m
;
}
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...
static
Map
<
void
*
,
{{
cl
a
ss
.
name
}}
>
instances
;
// map of created {{clss.name}} instances. Don't trust the user to keep them safe...
static
Map
<
void
*
,
{{
clss
.
name
}}
>
instances
;
/*
* {{ cl
a
ss.name }}
* {{ clss.name }}
* Gateway routine
* nlhs - number of return arguments
* plhs - pointers to return arguments
...
...
@@ -63,7 +64,7 @@ void mexFunction(int nlhs, mxArray* plhs[],
// retrieve the instance of interest
try
{
{{
cl
a
ss
.
name
}}
&
inst
=
instances
.
at
(
handle
.
address
());
{{
clss
.
name
}}
&
inst
=
instances
.
at
(
handle
.
address
());
}
catch
(
const
std
::
out_of_range
&
e
)
{
mexErrMsgTxt
(
"Invalid object instance provided"
);
}
...
...
@@ -80,6 +81,7 @@ void mexFunction(int nlhs, mxArray* plhs[],
{
%
block
cleanup
%
}
{
%
endblock
%
}
}
};
// end namespace
modules/matlab/generator/templates/template_class_base.m
View file @
eda32520
% {{cl
a
ss.name | upper}}
% Matlab handle cl
ass for OpenCV object cla
sses
% {{clss.name | upper}}
% Matlab handle cl
ss for OpenCV object cl
sses
%
% This file was autogenerated, do not modify.
% See LICENCE for full modification and redistribution details.
% Copyright {{time.strftime("%Y", time.localtime())}} The OpenCV Foundation
classdef
{{
cl
a
ss
.
name
}}
<
handle
classdef
{{
clss
.
name
}}
<
handle
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
methods
% constructor
function
this
=
{{
cl
a
ss
.
name
}}(
varargin
)
this
.
ptr_
=
{{
cl
a
ss
.
name
}}
Bridge
(
'new'
,
varargin
{:});
function
this
=
{{
clss
.
name
}}(
varargin
)
this
.
ptr_
=
{{
clss
.
name
}}
Bridge
(
'new'
,
varargin
{:});
end
% destructor
function
delete
(
this
)
{{
cl
assN
ame
}}
Bridge
(
this
.
ptr_
,
'delete'
);
{{
cl
ss
.
n
ame
}}
Bridge
(
this
.
ptr_
,
'delete'
);
end
{% for function in cl
ass.functions
%}
{% for function in cl
ss.functions -
%}
% {{function.__str__()}}
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
{% 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