Enabled syntax highlighting
This commit is contained in:
parent
2ac31a87c9
commit
eb83a9ed9f
@ -42,7 +42,7 @@ to get help on the purpose and call signature of a particular method, or
|
|||||||
|
|
||||||
to get general help regarding the OpenCV bindings. If you ever run into issues with the bindings
|
to get general help regarding the OpenCV bindings. If you ever run into issues with the bindings
|
||||||
|
|
||||||
cv.buildInformation();
|
cv.buildInformation();
|
||||||
|
|
||||||
will produce a printout of diagnostic information pertaining to your particular build of OS, OpenCV and Matlab. It is useful to submit this information alongside a bug report to the OpenCV team.
|
will produce a printout of diagnostic information pertaining to your particular build of OS, OpenCV and Matlab. It is useful to submit this information alongside a bug report to the OpenCV team.
|
||||||
|
|
||||||
@ -52,41 +52,43 @@ The Matlab bindings come with a set of utilities to help you quickly write your
|
|||||||
|
|
||||||
The first thing you need to learn how to do is write a mex-file with Matlab constructs. Following is a brief example:
|
The first thing you need to learn how to do is write a mex-file with Matlab constructs. Following is a brief example:
|
||||||
|
|
||||||
// include useful constructs
|
```cpp
|
||||||
// this automatically includes opencv core.hpp and mex.h)
|
// include useful constructs
|
||||||
#include <opencv2/matlab/bridge.hpp>
|
// this automatically includes opencv core.hpp and mex.h)
|
||||||
using namespace cv;
|
#include <opencv2/matlab/bridge.hpp>
|
||||||
using namespace std;
|
using namespace cv;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
// define the mex gateway
|
// define the mex gateway
|
||||||
void mexFunction(int nlhs, mxArray* plhs[],
|
void mexFunction(int nlhs, mxArray* plhs[],
|
||||||
int nrhs, const mxArray* prhs[]) {
|
int nrhs, const mxArray* prhs[]) {
|
||||||
|
|
||||||
// claim the inputs into scoped management
|
// claim the inputs into scoped management
|
||||||
MxArrayVector raw_inputs(prhs, prhs+nrhs);
|
MxArrayVector raw_inputs(prhs, prhs+nrhs);
|
||||||
|
|
||||||
// add an argument parser to automatically handle basic options
|
// add an argument parser to automatically handle basic options
|
||||||
ArgumentParser parser("my function");
|
ArgumentParser parser("my function");
|
||||||
parser.addVariant(1, 1, "opt");
|
parser.addVariant(1, 1, "opt");
|
||||||
MxArrayVector parsed_inputs = parser.parse(inputs);
|
MxArrayVector parsed_inputs = parser.parse(inputs);
|
||||||
|
|
||||||
// if we get here, we know the inputs are valid. Unpack...
|
// if we get here, we know the inputs are valid. Unpack...
|
||||||
BridgeVector inputs(parsed_inputs);
|
BridgeVector inputs(parsed_inputs);
|
||||||
Mat required = inputs[0].toMat();
|
Mat required = inputs[0].toMat();
|
||||||
string optional = inputs[1].empty() ? "Default string" : inputs[1].toString();
|
string optional = inputs[1].empty() ? "Default string" : inputs[1].toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Do stuff...
|
// Do stuff...
|
||||||
} catch(Exception& e) {
|
} catch(Exception& e) {
|
||||||
error(e.what());
|
error(e.what());
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
error("Uncaught exception occurred");
|
error("Uncaught exception occurred");
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate an output
|
// allocate an output
|
||||||
Bridge out = required;
|
Bridge out = required;
|
||||||
plhs[0] = out.toMxArray().releaseOwnership();
|
plhs[0] = out.toMxArray().releaseOwnership();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
There are a couple of important things going on in this example. Firstly, you need to include `<opencv2/matlab/bridge.hpp>` to enable the bridging capabilities. Once you've done this, you get some nice utilities for free. `MxArray` is a class that wraps Matlab's `mxArray*` class in an OOP-style interface. `ArgumentParser` is a class that handles default, optional and named arguments for you, along with multiple possible calling syntaxes. Finally, `Bridge` is a class that allows bidirectional conversions between OpenCV/std and Matlab types.
|
There are a couple of important things going on in this example. Firstly, you need to include `<opencv2/matlab/bridge.hpp>` to enable the bridging capabilities. Once you've done this, you get some nice utilities for free. `MxArray` is a class that wraps Matlab's `mxArray*` class in an OOP-style interface. `ArgumentParser` is a class that handles default, optional and named arguments for you, along with multiple possible calling syntaxes. Finally, `Bridge` is a class that allows bidirectional conversions between OpenCV/std and Matlab types.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user