Main Content

ocvMxArrayToMat_{DataType}

Convert column major mxArray to row major cv::Mat for generic matrix

C++ Syntax

#include "opencvmex.hpp"
void ocvMxArrayToMat_double(const mxArray *in, cv::Mat &out);
void ocvMxArrayToMat_single(const mxArray *in, cv::Mat &out);
void ocvMxArrayToMat_uint8(const mxArray *in, cv::Mat &out);
void ocvMxArrayToMat_uint16(const mxArray *in, cv::Mat &out);
void ocvMxArrayToMat_uint32(const mxArray *in, cv::Mat &out);
void ocvMxArrayToMat_int8(const mxArray *in, cv::Mat &out);
void ocvMxArrayToMat_int16(const mxArray *in, cv::Mat &out);
void ocvMxArrayToMat_int32(const mxArray *in, cv::Mat &out);
void ocvMxArrayToMat_bool(const mxArray *in, cv::Mat &out);

cv::Ptr<cv::Mat> ocvMxArrayToMat_double(const mxArray *in, const bool copyData = true);
cv::Ptr<cv::Mat> ocvMxArrayToMat_single(const mxArray *in, const bool copyData = true);
cv::Ptr<cv::Mat> ocvMxArrayToMat_uint8(const mxArray *in, const bool copyData = true);
cv::Ptr<cv::Mat> ocvMxArrayToMat_uint16(const mxArray *in, const bool copyData = true);
cv::Ptr<cv::Mat> ocvMxArrayToMat_uint32(const mxArray *in, const bool copyData = true);
cv::Ptr<cv::Mat> ocvMxArrayToMat_int8(const mxArray *in, const bool copyData = true);
cv::Ptr<cv::Mat> ocvMxArrayToMat_int16(const mxArray *in, const bool copyData = true);
cv::Ptr<cv::Mat> ocvMxArrayToMat_int32(const mxArray *in, const bool copyData = true);
cv::Ptr<cv::Mat> ocvMxArrayToMat_uint8(const mxArray *in, const bool copyData = true);

Arguments

in

Pointer to a MATLAB® struct, mxArray, having column major data. The data can be n-channel matrices. Supported data types:

real_T (double)uint8_T (uint8)uint32_T (uint32)int16_T (int16)
real32_T (single)uint16_T (uint16)int8_T (int8)int32_T (int32)

copyData

Boolean flag to copy data from mxArray to the Mat object.

  • true (default) — The function transposes and interleaves (for RGB images) column major mxArray data into a row major cv::Mat object.

  • false — No data copies from the mxArray to the Mat object. The function creates a new Mat wrapper and uses it to point to the mxArray data. Because OpenCV is row-based and MATLAB is column-based, the columns of the mxArray become the rows of the Mat object. If the image is 2-D, then copyData is false.

out

Reference to OpenCV cv::Mat with row major data.

Returns

The functions that set copyData return an OpenCV smart pointer (cv::Ptr) to a cv::Mat object.

Description

The ocvMxArrayToMat_{DataType} function applies to two C++ implementations. One set returns void and the other set returns an OpenCV smart pointer. The functions that return void reallocate memory for the cv::Mat if needed.

The ocvMxArrayToMat_{DataType} transposes and interleaves column major mxArray data into row major cv::Mat. This matrix conversion is a generic routine for any number of channels.

Version History

Introduced in R2015a