19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
31 vector<MxArray> rhs(prhs, prhs+nrhs);
32 string method(rhs[0].toString());
35 if (method ==
"from_scalar_int") {
40 CV_Assert(arr.
numel() == 1 && arr.
rows() == 1 && arr.
cols() == 1);
43 else if (method ==
"from_scalar_double") {
48 CV_Assert(arr.
numel() == 1 && arr.
rows() == 1 && arr.
cols() == 1);
51 else if (method ==
"from_scalar_bool") {
56 CV_Assert(arr.
numel() == 1 && arr.
rows() == 1 && arr.
cols() == 1);
59 else if (method ==
"from_string") {
64 CV_Assert(arr.
numel() == str.size() && arr.
rows() == 1 && arr.
cols() == str.size());
67 else if (method ==
"toMat_row_vector") {
69 Mat m(rhs[1].toMat());
70 CV_Assert(m.depth() == CV_64F && m.channels() == 1);
71 CV_Assert(m.total() == 10 && m.dims == 2 && m.rows == 1 && m.cols == 10);
72 const double *data = m.ptr<
double>();
73 const size_t len = m.total() * m.channels();
74 for (
size_t i=0; i<len; i++)
75 CV_Assert(data[i] == (i+1));
78 else if (method ==
"toMat_col_vector") {
80 Mat m(rhs[1].toMat());
81 CV_Assert(m.depth() == CV_64F && m.channels() == 1);
82 CV_Assert(m.total() == 10 && m.dims == 2 && m.rows == 10 && m.cols == 1);
83 const double *data = m.ptr<
double>();
84 const size_t len = m.total() * m.channels();
85 for (
size_t i=0; i<len; i++)
86 CV_Assert(data[i] == (i+1));
89 else if (method ==
"fromMat_row_vector") {
91 Mat m = (Mat_<double>(1,10) << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
94 CV_Assert(arr.
numel() == 10 && arr.
rows() == 1 && arr.
cols() == 10);
97 else if (method ==
"fromMat_col_vector") {
99 Mat m = (Mat_<double>(10,1) << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
102 CV_Assert(arr.
numel() == 10 && arr.
rows() == 10 && arr.
cols() == 1);
106 mexErrMsgIdAndTxt(
"mexopencv:error",
107 "Unrecognized method %s", method.c_str());
bool isChar() const
Determine whether input is string array.
int MexErrorHandler(int status, const char *func_name, const char *err_msg, const char *file_name, int line, void *userdata)
Cutom error callback to be invoked by cv::error(), CV_Assert, etc...
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mwSize numel() const
Number of elements in an array.
mwSize ndims() const
Number of dimensions.
bool isDouble() const
Determine whether mxArray represents data as double-precision, floating-point numbers.
bool isLogicalScalar() const
Determine whether scalar array is of type mxLogical.
mwSize rows() const
Number of rows in an array.
mwSize cols() const
Number of columns in an array.