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
3b4814a5
Commit
3b4814a5
authored
Jun 22, 2013
by
hbristow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started writing the Bridge interface. Mex wrappers now starting to compile for core
parent
0263727b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
18 deletions
+73
-18
CMakeLists.txt
modules/matlab/CMakeLists.txt
+10
-4
functional.cpp
modules/matlab/generator/templates/functional.cpp
+7
-3
template_class_base.cpp
modules/matlab/generator/templates/template_class_base.cpp
+2
-7
template_class_base.m
modules/matlab/generator/templates/template_class_base.m
+2
-2
template_function_base.cpp
...les/matlab/generator/templates/template_function_base.cpp
+1
-2
bridge.hpp
modules/matlab/include/bridge.hpp
+51
-0
No files found.
modules/matlab/CMakeLists.txt
View file @
3b4814a5
...
...
@@ -50,7 +50,11 @@ ocv_add_module(matlab BINDINGS opencv_core #TODO: does it actually NEED to dep
# TODO: Undo this when building all modules to find python properly
#set(HDR_PARSER_PATH ${OPENCV_MODULE_opencv_python_LOCATION}/src2)
set
(
HDR_PARSER_PATH
${
CMAKE_CURRENT_SOURCE_DIR
}
/../python/src2
)
prepend
(
"-I"
MEX_INCLUDES
${
CMAKE_CURRENT_SOURCE_DIR
}
/include
)
# set mex compiler options
prepend
(
"-I"
MEX_INCLUDE_DIRS
${
CMAKE_CURRENT_SOURCE_DIR
}
/include
)
prepend
(
"-L"
MEX_LIB_DIR
${
CMAKE_BINARY_DIR
}
/lib
)
set
(
MEX_OPTS
"-largeArrayDims"
)
if
(
BUILD_TESTS
)
add_subdirectory
(
test
)
...
...
@@ -79,7 +83,7 @@ endif()
# attempt to compile the file using mex
message
(
"-- Trying to compile mex file"
)
execute_process
(
COMMAND
${
MATLAB_MEX_SCRIPT
}
${
MEX_
INCLUDE
S
}
COMMAND
${
MATLAB_MEX_SCRIPT
}
${
MEX_
OPTS
}
${
MEX_INCLUDE_DIR
S
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/test/test_compiler.cpp
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
/src
ERROR_VARIABLE MEX_ERROR
...
...
@@ -105,6 +109,8 @@ string(REPLACE "opencv_" "" OPENCV_MATLAB_MODULES "${OPENCV_MODULE_${the_module}
foreach
(
module
${
OPENCV_MATLAB_MODULES
}
)
if
(
HAVE_opencv_
${
module
}
)
list
(
APPEND opencv_hdrs
"
${
OPENCV_MODULE_opencv_
${
module
}
_LOCATION
}
/include/opencv2/
${
module
}
.hpp"
)
prepend
(
"-I"
MEX_INCLUDE_DIRS
"
${
OPENCV_MODULE_opencv_
${
module
}
_LOCATION
}
/include"
)
prepend
(
"-l"
MEX_LIBS
"opencv_
${
module
}
"
)
endif
()
endforeach
()
...
...
@@ -122,8 +128,8 @@ foreach(SOURCE_FILE ${SOURCE_FILES})
get_filename_component
(
FILENAME
${
SOURCE_FILE
}
NAME_WE
)
# compile the source file using mex
add_custom_command
(
TARGET opencv_matlab PRE_BUILD
COMMAND
echo
${
MATLAB_MEX_SCRIPT
}
${
MEX_INCLUDES
}
${
SOURCE_FILE
}
COMMAND
${
MATLAB_MEX_SCRIPT
}
${
MEX_OPTS
}
${
MEX_INCLUDE_DIRS
}
${
MEX_LIB_DIR
}
${
MEX_LIBS
}
${
SOURCE_FILE
}
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
/src
)
endforeach
()
...
...
modules/matlab/generator/templates/functional.cpp
View file @
3b4814a5
...
...
@@ -7,8 +7,9 @@
/
{
%
macro
compose
(
fun
)
%
}
{
#
-----------
Return
type
-------------
#
}
{
%-
if
not
fun
.
rtp
|
void
-%
}
{{
fun
.
rtp
}}
retval
=
{
%
endif
-%
}
cv
::
{{
fun
.
name
}}(
{
%-
if
not
fun
.
rtp
|
void
-%
}
retval
=
{
%
endif
-%
}
{
%-
if
fun
.
clss
-%
}
inst
.{
%-
else
-%
}
cv
::
{
%
endif
-%
}
{{
fun
.
name
}}(
{
#
-
-----------
Required
-------------
-
#
}
{
%-
for
arg
in
fun
.
req
-%
}
{
%-
if
arg
.
ref
==
'*'
-%
}
&
{
%-
endif
-%
}
...
...
@@ -34,7 +35,7 @@
{{
arg
.
tp
}}
{{
arg
.
name
}}
=
inputs
[{{
loop
.
index0
}}];
{
%
endfor
%
}
{
%
for
opt
in
fun
.
opt
|
inputs
%
}
{{
opt
.
tp
}}
{{
opt
.
name
}}
=
(
nrhs
>
{{
loop
.
index0
+
fun
.
req
|
inputs
|
length
}})
?
inputs
[{{
loop
.
index0
+
fun
.
req
|
inputs
|
length
}}]
:
{{
opt
.
default
}};
{{
opt
.
tp
}}
{{
opt
.
name
}}
=
(
nrhs
>
{{
loop
.
index0
+
fun
.
req
|
inputs
|
length
}})
?
({{
opt
.
tp
}})
inputs
[{{
loop
.
index0
+
fun
.
req
|
inputs
|
length
}}]
:
{{
opt
.
default
}};
{
%
endfor
%
}
{
#
-----------
Outputs
------------
#
}
{
%
for
arg
in
fun
.
req
|
only
|
outputs
%
}
...
...
@@ -43,6 +44,9 @@
{
%
for
opt
in
fun
.
opt
|
only
|
outputs
%
}
{{
opt
.
tp
}}
{{
opt
.
name
}};
{
%
endfor
%
}
{
%
if
not
fun
.
rtp
|
void
%
}
{{
fun
.
rtp
}}
retval
;
{
%
endif
%
}
// call the opencv function
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
...
...
modules/matlab/generator/templates/template_class_base.cpp
View file @
3b4814a5
...
...
@@ -11,11 +11,11 @@
#include "mex.h"
#include "bridge.hpp"
#include <vector>
//TODO: Standard C++ does not have an unordered_map (only C++11 and Boost)
#include <unordered_map>
#include <string>
#include <opencv2/core.hpp>
{
%
block
includes
%
}
{
%
endblock
%
}
using
namespace
cv
;
namespace
{
...
...
@@ -25,12 +25,7 @@ typedef std::vector<Bridge> (*)({{clss.name}}&, const std::vector<Bridge>&) Meth
{
%
for
function
in
clss
.
functions
%
}
// wrapper for {{function.name}}() method
std
::
vector
<
Bridge
>
{{
function
.
name
}}({{
clss
.
name
}}
&
inst
,
const
std
::
vector
<
Bridge
>&
args
)
{
// setup
// invoke
{{
functional
.
generate
(
function
)
}}
// setdown
}
{
%
endfor
%
}
...
...
modules/matlab/generator/templates/template_class_base.m
View file @
3b4814a5
% {{clss.name | upper}}
% Matlab handle cl
ss for OpenCV object cl
sses
% Matlab handle cl
ass for OpenCV object cla
sses
%
% This file was autogenerated, do not modify.
% See LICENCE for full modification and redistribution details.
...
...
@@ -20,7 +20,7 @@ classdef {{clss.name}} < handle
{{
clss
.
name
}}
Bridge
(
this
.
ptr_
,
'delete'
);
end
{% for function in clss.functions
-
%}
{% for function in clss.functions %}
% {{function.__str__()}}
function
varargout
=
{{
function
.
name
}}(
this
,
varargin
)
[
varargout
{
1
:
nargout
}]
=
{{
clss
.
name
}}
Bridge
(
'{{function.name}}'
,
this
.
ptr_
,
varargin
{:});
...
...
modules/matlab/generator/templates/template_function_base.cpp
View file @
3b4814a5
...
...
@@ -14,8 +14,7 @@
#include <vector>
#include <exception>
#include <opencv2/{{includes}}.hpp>
{
%
block
includes
%
}
{
%
endblock
%
}
using
namespace
cv
;
/*
* {{ fun.name }}
...
...
modules/matlab/include/bridge.hpp
View file @
3b4814a5
...
...
@@ -2,5 +2,56 @@
#define OPENCV_BRIDGE_HPP_
#include "mex.h"
#include <opencv2/core.hpp>
/*!
* @class Bridge
* @brief Type conversion class for converting OpenCV and native C++ types
*
* Bridge provides an interface for converting between OpenCV/C++ types
* to Matlab's mxArray format.
*
* Each type conversion requires three operators:
* // conversion from ObjectType --> Bridge
* Bridge& operator=(const ObjectType&);
* // implicit conversion from Bridge --> ObjectType
* operator ObjectType();
* // explicit conversion from Bridge --> ObjectType
* ObjectType toObjectType
*
* The bridging class provides common conversions between OpenCV types,
* std and stl types to Matlab's mxArray format. By inheriting Bridge,
* you can add your own custom type conversions.
*
* Bridge attempts to make as few assumptions as possible, however in
* some cases where 1-to-1 mappings don't exist, some assumptions are necessary.
* In particular:
* - conversion from of a 2-channel Mat to an mxArray will result in a complex
* output
* - conversion from multi-channel interleaved Mats will result in
* multichannel planar mxArrays
*
*/
class
Bridge
{
public
:
// bridges are default constructible
Bridge
()
{}
virtual
~
Bridge
()
{}
// --------------------------- mxArray --------------------------------------
Bridge
&
operator
=
(
const
mxArray
*
obj
)
{}
Bridge
(
const
mxArray
*
obj
)
{}
mxArray
*
mxArray
()
{
return
NULL
;
}
// --------------------------- cv::Mat --------------------------------------
Bridge
&
operator
=
(
const
cv
::
Mat
&
obj
)
{}
operator
cv
::
Mat
()
{
return
cv
::
Mat
();
}
cv
::
Mat
toMat
()
{
return
cv
::
Mat
();
}
// --------------------------- int --------------------------------------
Bridge
&
operator
=
(
const
int
&
obj
)
{}
operator
int
()
{
return
0
;
}
int
toInt
()
{
return
0
;
}
};
#endif
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