14 #include "opencv2/opencv.hpp" 118 int MexErrorHandler(
int status,
const char *func_name,
const char *err_msg,
119 const char *file_name,
int line,
void *userdata);
148 explicit MxArray(
const double d);
153 explicit MxArray(
const bool b);
333 operator const mxArray*()
const {
return p_; };
506 template <
typename T>
606 inline bool isNull()
const {
return (p_ == NULL); }
829 template <
typename T>
void set(
mwIndex index,
const T& value);
871 template <
typename T>
void set(
const std::string& fieldName,
926 template <
typename T,
typename U>
956 template <
typename T>
963 for (
mwIndex i = 0; i <
v.size(); ++i)
973 template <
typename T>
980 x[0] =
static_cast<double>(p.
x);
981 x[1] =
static_cast<double>(p.
y);
984 template <
typename T>
991 x[0] =
static_cast<double>(p.
x);
992 x[1] =
static_cast<double>(p.
y);
993 x[2] =
static_cast<double>(p.
z);
996 template <
typename T>
1003 x[0] =
static_cast<double>(s.
width);
1004 x[1] =
static_cast<double>(s.
height);
1007 template <
typename T>
1014 x[0] =
static_cast<double>(r.
x);
1015 x[1] =
static_cast<double>(r.
y);
1016 x[2] =
static_cast<double>(r.
width);
1017 x[3] =
static_cast<double>(r.
height);
1020 template <
typename T>
1027 x[0] =
static_cast<double>(s[0]);
1028 x[1] =
static_cast<double>(s[1]);
1029 x[2] =
static_cast<double>(s[2]);
1030 x[3] =
static_cast<double>(s[3]);
1033 template <
typename T,
int cn>
1048 template <
typename T,
int m,
int n>
1066 template <
typename T>
1074 template <
typename T>
1082 template <
typename T>
1090 template <
typename T>
1095 return cv::Rect_<T>(at<T>(0), at<T>(1), at<T>(2), at<T>(3));
1098 template <
typename T>
1108 case 4:
return cv::Scalar_<T>(at<T>(0), at<T>(1), at<T>(2), at<T>(3));
1113 template <
typename T,
int cn>
1118 "MxArray is not a cv::Vec%d", cn);
1125 for (
mwIndex i = 0; i < cn; i++)
1130 template <
typename T,
int m,
int n>
1135 "MxArray is not a cv::Matx%d%d", m, n);
1146 mat(i,j) = at<T>(i,j);
1150 template <
typename T>
1164 const double *data =
mxGetPr(p_);
1166 vt.
assign(data, data + n);
1170 const float *data =
reinterpret_cast<float*
>(
mxGetData(p_));
1171 vt.
assign(data, data + n);
1176 vt.
assign(data, data + n);
1181 vt.
assign(data, data + n);
1186 vt.
assign(data, data + n);
1191 vt.
assign(data, data + n);
1196 vt.
assign(data, data + n);
1201 vt.
assign(data, data + n);
1206 vt.
assign(data, data + n);
1211 vt.
assign(data, data + n);
1216 vt.
assign(data, data + n);
1221 vt.
assign(data, data + n);
1229 for (
mwIndex i = 0; i < n; ++i)
1238 template <
typename T>
1249 template <
typename T>
1264 return static_cast<T>(
1267 return static_cast<T>(
1270 return static_cast<T>(
1273 return static_cast<T>(
1276 return static_cast<T>(
1279 return static_cast<T>(
1282 return static_cast<T>(
1285 return static_cast<T>(
1288 return static_cast<T>(
1293 return static_cast<T>(0);
1297 template <
typename T>
1300 return at<T>(
subs(i,j));
1303 template <
typename T>
1306 return at<T>(
subs(si));
1309 template <
typename T>
1327 static_cast<int8_t>(value);
1359 static_cast<float>(value);
1369 template <
typename T>
1372 set<T>(
subs(i,j), value);
1375 template <
typename T>
1378 set<T>(
subs(si), value);
1381 template <
typename T>
1391 "Failed to create a field '%s'", fieldName.
c_str());
1852 #endif // MXARRAY_HPP MxArray(const std::vector< T > &v)
MxArray constructor from vector<T>.
bool isInt32() const
Determine whether array represents data as signed 32-bit integers.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsSingle(const mxArray *pa)
Determine whether the specified array represents its data as single-precision floating-point numbers...
mwSize ndims() const
Number of dimensions.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsFromGlobalWS(const mxArray *pa)
Inform Watcom compilers that scalar double return values will be in the FPU register.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxChar * mxGetChars(const mxArray *pa)
Get string array data.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C double mxGetNaN(void)
Function for obtaining MATLAB's concept of NaN (Used in MEX-File callback).
static double Inf()
Value of infinity.
void destroy()
Deallocate memory occupied by mxArray.
int toInt() const
Convert MxArray to int.
std::string fieldname(int fieldnumber) const
Get specified field name from a struct array.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C int mxGetFieldNumber(const mxArray *pa, const char *name)
Get the index to the named field.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsInt8(const mxArray *pa)
Determine whether the specified array represents its data as signed 8-bit integers.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsSparse(const mxArray *pa)
Determine whether the given array is a sparse (as opposed to full).
bool isEmpty() const
Determine whether array is empty.
size_t mwSize
unsigned pointer-width integer
bool isLogicalScalarTrue() const
Determine whether scalar array of type mxLogical is true.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsEmpty(const mxArray *pa)
Is array empty.
MxArray(const MxArray &arr)
Copy constructor.
mwSize numel() const
Number of elements in an array.
T at(mwIndex index) const
Template for numeric array element accessor.
cv::TermCriteria toTermCriteria(mwIndex index=0) const
Convert MxArray to cv::TermCriteria.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsStruct(const mxArray *pa)
Determine whether the given array is a structure array.
bool isUint32() const
Determine whether array represents data as unsigned 32-bit integers.
bool isSingle() const
Determine whether array represents data as single-precision, floating-point numbers.
static const mxClassID type
maps general template parameter to unkown MATLAB type.
cv::Point3_< T > toPoint3_() const
Convert MxArray to Point3_<T>.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsUint32(const mxArray *pa)
Determine whether the specified array represents its data as unsigned 32-bit integers.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsClass(const mxArray *pa, const char *name)
Determine whether an array is a member of the specified class.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsUint64(const mxArray *pa)
Determine whether the specified array represents its data as unsigned 64-bit integers.
const std::string className() const
Class name of mxArray.
std::string toString() const
Convert MxArray to std::string.
bool isFromGlobalWS() const
Determine whether array was copied from MATLAB global workspace.
bool isLogicalScalar() const
Determine whether scalar array is of type mxLogical.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
bool isChar() const
Determine whether input is string array.
cv::Size toSize() const
Alias to toSize_<int>.
void transpose(InputArray src, OutputArray dst)
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
cv::DMatch toDMatch(mwIndex index=0) const
Convert MxArray to cv::DMatch.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C void mxDestroyArray(mxArray *pa)
mxArray destructor
bool isDouble() const
Determine whether mxArray represents data as double-precision, floating-point numbers.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsUint16(const mxArray *pa)
Determine whether the specified array represents its data as unsigned 16-bit integers.
bool isInt64() const
Determine whether array represents data as signed 64-bit integers.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
Undetermined class. You cannot specify this category for an mxArray; however, if mxGetClassID cannot ...
cv::Rect_< T > toRect_() const
Convert MxArray to Rect_<T>.
cv::Rect toRect() const
Alias to toRect_<int>.
static double NaN()
Value of NaN (Not-a-Number).
bool isUint64() const
Determine whether array represents data as unsigned 64-bit integers.
#define mxCreateStructMatrix
struct mxArray_tag mxArray
Forward declaration for mxArray.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
cv::Matx< T, m, n > toMatx() const
Convert MxArray to Matx<T,m,n>.
cv::Range toRange() const
Convert MxArray to cv::Range.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
bool isFloat() const
Determine whether array represents data as floating-point numbers, both single and double precision...
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C size_t mxGetNumberOfElements(const mxArray *pa)
Get number of elements in array.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsCell(const mxArray *pa)
Determine whether the given array is a cell array.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsLogicalScalarTrue(const mxArray *pa)
Returns true if the logical scalar value is true.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxLogical * mxGetLogicals(const mxArray *pa)
Get a properly typed pointer to the elements of a logical array.
#define mxGetNumberOfDimensions
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxClassID mxGetClassID(const mxArray *pa)
Return the class (catergory) of data that the array holds.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsFinite(double x)
Inform Watcom compilers that scalar double return values will be in the FPU register.
cv::Scalar toScalar() const
Alias to toScalar_<double>
static bool isFinite(double d)
Determine whether input is finite.
bool isInt8() const
Determine whether array represents data as signed 8-bit integers.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsInf(double x)
test for infinity in a machine-independent manner
std::vector< std::string > fieldnames() const
Get field names of a struct array.
Matx< _Tp, n, m > t() const
cv::Point_< T > toPoint_() const
Convert MxArray to Point_<T>.
cv::RotatedRect toRotatedRect(mwIndex index=0) const
Convert MxArray to cv::RotatedRect.
virtual ~MxArray()
Destructor.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsComplex(const mxArray *pa)
Determine whether the given array contains complex data.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsLogicalScalar(const mxArray *pa)
Returns true if we have a valid logical scalar mxArray.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C void * mxGetData(const mxArray *pa)
Get pointer to data.
bool toBool() const
Convert MxArray to bool.
Identifies a string mxArray, an mxArray whose data is represented as mxChar.
bool isNumeric() const
Determine whether array is numeric.
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.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsInt32(const mxArray *pa)
Determine whether the specified array represents its data as signed 32-bit integers.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C size_t mxGetM(const mxArray *pa)
Get row dimension.
bool isComplex() const
Determine whether data is complex.
cv::Point2f toPoint2f() const
Alias to toPoint_<float>.
bool isInteger() const
Determine whether array represents data as integer types (8-bit, 16-bit, 32-bit or 64-bit...
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C int mxGetNumberOfFields(const mxArray *pa)
Get number of structure fields in array.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsLogical(const mxArray *pa)
Determine whether the given array's logical flag is on.
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
float toFloat() const
Convert MxArray to float.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C int mxAddField(mxArray *pa, const char *fieldname)
Add a field to a structure array.
#define mxCreateNumericMatrix
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsInt16(const mxArray *pa)
Determine whether the specified array represents its data as signed 16-bit integers.
bool isCell() const
Determine whether input is cell array.
size_t mwIndex
unsigned pointer-width integer
bool isSparse() const
Determine whether input is sparse array.
cv::Point3f toPoint3f() const
Alias to toPoint3_<float>.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C size_t mxGetN(const mxArray *pa)
Get column dimension.
bool isField(const std::string &fieldName) const
Determine whether a struct array has a specified field.
mxArray object wrapper for data conversion and manipulation.
cv::SparseMat toSparseMat(int depth=CV_USRTYPE1) const
Convert double sparse MxArray to 2D single-channel cv::SparseMat.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C double mxGetInf(void)
Function for obtaining MATLAB's concept of INF (Used in MEX-File callback).
bool isStruct() const
Determine whether input is structure array.
static MxArray Cell(mwSize m=1, mwSize n=1)
Create a new cell array.
mxClassID
Enumeration corresponding to all the valid mxArray types.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsNumeric(const mxArray *pa)
Determine whether the specified array contains numeric (as opposed to cell or struct) data...
cv::KeyPoint toKeyPoint(mwIndex index=0) const
Convert MxArray to cv::KeyPoint.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
std::vector< T > toVector() const
Convert MxArray to std::vector<T> of primitive types.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsNaN(double x)
test for NaN in a machine-independent manner
bool isClass(std::string s) const
Determine whether array is member of specified class.
cv::MatND toMatND(int depth=CV_USRTYPE1, bool transpose=true) const
Convert MxArray to a single-channel cv::Mat.
Identifies a logical mxArray, an mxArray of mxLogical data.
int nfields() const
Number of fields in a struct array.
ConstMap(const T &key, const U &val)
Constructor with a single key-value pair.
#define mxCreateCellMatrix
bool isUint16() const
Determine whether array represents data as unsigned 16-bit integers.
bool isLogical() const
Determine whether array is of type mxLogical.
cv::Vec< T, cn > toVec() const
Convert MxArray to Vec<T,cn>.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsChar(const mxArray *pa)
Determine whether the given array contains character data.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsUint8(const mxArray *pa)
Determine whether the specified array represents its data as unsigned 8-bit integers.
cv::Mat toMat(int depth=CV_USRTYPE1, bool transpose=true) const
Convert MxArray to cv::Mat.
cv::Size_< T > toSize_() const
Convert MxArray to Size_<T>.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
mwSize rows() const
Number of rows in an array.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C double mxGetEps(void)
Function for obtaining MATLAB's concept of EPS.
mwSize cols() const
Number of columns in an array.
mwIndex subs(mwIndex i, mwIndex j=0) const
Offset from first element to desired element.
double toDouble() const
Convert MxArray to double.
const mwSize * dims() const
Array of each dimension.
MxArray(const mxArray *arr)
MxArray constructor from mxArray*.
cv::Point toPoint() const
Alias to toPoint_<int>.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
static bool isInf(double d)
Determine whether input is infinite.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsDouble(const mxArray *pa)
Determine whether the specified array represents its data as double-precision floating-point numbers...
cv::Moments toMoments(mwIndex index=0) const
Convert MxArray to cv::Moments.
bool isInt16() const
Determine whether array represents data as signed 16-bit integers.
bool isUint8() const
Determine whether array represents data as unsigned 8-bit integers.
ConstMap< T, U > & operator()(const T &key, const U &val)
Consecutive insertion operator.
bool mxLogical
Logical type.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C const char * mxGetClassName(const mxArray *pa)
Return the name of an array's class.
const U & operator[](const T &key) const
Lookup operator; fail if not found.
mwSize nzmax() const
Number of elements in IR, PR, and PI arrays.
bool isNull() const
Determine whether the array is initialized or not.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
std::map wrapper with one-line initialization and lookup method.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C bool mxIsInt64(const mxArray *pa)
Determine whether the specified array represents its data as signed 64-bit integers.
MxArray clone() const
Clone mxArray.
mxClassID classID() const
Class ID of mxArray.
CHAR16_T mxChar
Typedef required for Unicode support in MATLAB.
static bool isNaN(double d)
Determine whether input is NaN (Not-a-Number).
static double Eps()
Value of EPS.
MxArray & operator=(const MxArray &rhs)
Assignment operator.
Identifies an mxArray with no imaginary components.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C double * mxGetPr(const mxArray *pa)
Get real data pointer for numeric array.
cv::Scalar_< T > toScalar_() const
Convert MxArray to Scalar_<T>.