Started writing the Bridge interface. Mex wrappers now starting to compile for core
This commit is contained in:
parent
0263727b53
commit
3b4814a52e
@ -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
|
# 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 ${OPENCV_MODULE_opencv_python_LOCATION}/src2)
|
||||||
set(HDR_PARSER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../python/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)
|
if (BUILD_TESTS)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
@ -79,7 +83,7 @@ endif()
|
|||||||
# attempt to compile the file using mex
|
# attempt to compile the file using mex
|
||||||
message("-- Trying to compile mex file")
|
message("-- Trying to compile mex file")
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_INCLUDES}
|
COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} ${MEX_INCLUDE_DIRS}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test/test_compiler.cpp
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
|
||||||
ERROR_VARIABLE MEX_ERROR
|
ERROR_VARIABLE MEX_ERROR
|
||||||
@ -105,6 +109,8 @@ string(REPLACE "opencv_" "" OPENCV_MATLAB_MODULES "${OPENCV_MODULE_${the_module}
|
|||||||
foreach(module ${OPENCV_MATLAB_MODULES})
|
foreach(module ${OPENCV_MATLAB_MODULES})
|
||||||
if (HAVE_opencv_${module})
|
if (HAVE_opencv_${module})
|
||||||
list(APPEND opencv_hdrs "${OPENCV_MODULE_opencv_${module}_LOCATION}/include/opencv2/${module}.hpp")
|
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()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
@ -122,8 +128,8 @@ foreach(SOURCE_FILE ${SOURCE_FILES})
|
|||||||
get_filename_component(FILENAME ${SOURCE_FILE} NAME_WE)
|
get_filename_component(FILENAME ${SOURCE_FILE} NAME_WE)
|
||||||
# compile the source file using mex
|
# compile the source file using mex
|
||||||
add_custom_command(TARGET opencv_matlab PRE_BUILD
|
add_custom_command(TARGET opencv_matlab PRE_BUILD
|
||||||
COMMAND echo ${MATLAB_MEX_SCRIPT} ${MEX_INCLUDES}
|
COMMAND ${MATLAB_MEX_SCRIPT} ${MEX_OPTS} ${MEX_INCLUDE_DIRS}
|
||||||
${SOURCE_FILE}
|
${MEX_LIB_DIR} ${MEX_LIBS} ${SOURCE_FILE}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
|
||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
@ -7,8 +7,9 @@
|
|||||||
/
|
/
|
||||||
{% macro compose(fun) %}
|
{% macro compose(fun) %}
|
||||||
{# ----------- Return type ------------- #}
|
{# ----------- Return type ------------- #}
|
||||||
{%- if not fun.rtp|void -%} {{fun.rtp}} retval = {% endif -%}
|
{%- if not fun.rtp|void -%} retval = {% endif -%}
|
||||||
cv::{{fun.name}}(
|
{%- if fun.clss -%}inst.{%- else -%} cv:: {% endif -%}
|
||||||
|
{{fun.name}}(
|
||||||
{#- ----------- Required ------------- -#}
|
{#- ----------- Required ------------- -#}
|
||||||
{%- for arg in fun.req -%}
|
{%- for arg in fun.req -%}
|
||||||
{%- if arg.ref == '*' -%}&{%- endif -%}
|
{%- if arg.ref == '*' -%}&{%- endif -%}
|
||||||
@ -34,7 +35,7 @@
|
|||||||
{{arg.tp}} {{arg.name}} = inputs[{{ loop.index0 }}];
|
{{arg.tp}} {{arg.name}} = inputs[{{ loop.index0 }}];
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for opt in fun.opt|inputs %}
|
{% 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 %}
|
{% endfor %}
|
||||||
{# ----------- Outputs ------------ #}
|
{# ----------- Outputs ------------ #}
|
||||||
{% for arg in fun.req|only|outputs %}
|
{% for arg in fun.req|only|outputs %}
|
||||||
@ -43,6 +44,9 @@
|
|||||||
{% for opt in fun.opt|only|outputs %}
|
{% for opt in fun.opt|only|outputs %}
|
||||||
{{opt.tp}} {{opt.name}};
|
{{opt.tp}} {{opt.name}};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if not fun.rtp|void %}
|
||||||
|
{{fun.rtp}} retval;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
// call the opencv function
|
// call the opencv function
|
||||||
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
|
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
#include "mex.h"
|
#include "mex.h"
|
||||||
#include "bridge.hpp"
|
#include "bridge.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
//TODO: Standard C++ does not have an unordered_map (only C++11 and Boost)
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <opencv2/core.hpp>
|
#include <opencv2/core.hpp>
|
||||||
{% block includes %}
|
using namespace cv;
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -25,12 +25,7 @@ typedef std::vector<Bridge> (*)({{clss.name}}&, const std::vector<Bridge>&) Meth
|
|||||||
{% for function in clss.functions %}
|
{% for function in clss.functions %}
|
||||||
// wrapper for {{function.name}}() method
|
// wrapper for {{function.name}}() method
|
||||||
std::vector<Bridge> {{function.name}}({{clss.name}}& inst, const std::vector<Bridge>& args) {
|
std::vector<Bridge> {{function.name}}({{clss.name}}& inst, const std::vector<Bridge>& args) {
|
||||||
// setup
|
|
||||||
|
|
||||||
// invoke
|
|
||||||
{{ functional.generate(function) }}
|
{{ functional.generate(function) }}
|
||||||
|
|
||||||
// setdown
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
% {{clss.name | upper}}
|
% {{clss.name | upper}}
|
||||||
% Matlab handle clss for OpenCV object clsses
|
% Matlab handle class for OpenCV object classes
|
||||||
%
|
%
|
||||||
% 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.
|
||||||
@ -20,7 +20,7 @@ classdef {{clss.name}} < handle
|
|||||||
{{clss.name}}Bridge(this.ptr_, 'delete');
|
{{clss.name}}Bridge(this.ptr_, 'delete');
|
||||||
end
|
end
|
||||||
|
|
||||||
{% for function in clss.functions -%}
|
{% for function in clss.functions %}
|
||||||
% {{function.__str__()}}
|
% {{function.__str__()}}
|
||||||
function varargout = {{function.name}}(this, varargin)
|
function varargout = {{function.name}}(this, varargin)
|
||||||
[varargout{1:nargout}] = {{clss.name}}Bridge('{{function.name}}', this.ptr_, varargin{:});
|
[varargout{1:nargout}] = {{clss.name}}Bridge('{{function.name}}', this.ptr_, varargin{:});
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <opencv2/{{includes}}.hpp>
|
#include <opencv2/{{includes}}.hpp>
|
||||||
{% block includes %}
|
using namespace cv;
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* {{ fun.name }}
|
* {{ fun.name }}
|
||||||
|
@ -2,5 +2,56 @@
|
|||||||
#define OPENCV_BRIDGE_HPP_
|
#define OPENCV_BRIDGE_HPP_
|
||||||
|
|
||||||
#include "mex.h"
|
#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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user