Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to pass OpenCV Mat(CV_8UC3) to Matlab generated code and vice-versa? Efficiently

'Matlab coder' generated a c++ function. (function name is 'matlab')

matlab(uv0, outImg);

//Before calling, arguments need to declared
emxArray_uint8_T *outImg;
static unsigned char uv0[758016];
emxInitArray_uint8_T(&outImg, 3);

I don't know how 'cv::Mat' can be converted into 'unsigned char uv0'

and

'emxArray_uint8_T *outImg' back into cv::Mat.

//some related function are

static void argInit_376x672x3_uint8_T(unsigned char result[758016])
{
  int idx0;
  int idx1;
  unsigned char result_tmp;
  for (idx0 = 0; idx0 < 376; idx0++) {
    for (idx1 = 0; idx1 < 672; idx1++) {
      result_tmp = argInit_uint8_T();
      result[idx0 + 376 * idx1] = result_tmp;
      result[(idx0 + 376 * idx1) + 252672] = result_tmp;
      result[(idx0 + 376 * idx1) + 505344] = argInit_uint8_T();
    }
  }
}

static unsigned char argInit_uint8_T()
{
  return 0U;
}

How to pass OpenCV Mat(CV_8UC3) to Matlab generated code and vice-versa? Efficiently

'Matlab coder' generated a c++ function. (function name is 'matlab')

matlab(uv0, outImg);

//Before calling, arguments need to declared
emxArray_uint8_T *outImg;
static unsigned char uv0[758016];
emxInitArray_uint8_T(&outImg, 3);

I don't know how 'cv::Mat' can be converted into 'unsigned char uv0'

and

'emxArray_uint8_T *outImg' back into cv::Mat.

//some related function are

static void argInit_376x672x3_uint8_T(unsigned char result[758016])
{
  int idx0;
  int idx1;
  unsigned char result_tmp;
  for (idx0 = 0; idx0 < 376; idx0++) {
    for (idx1 = 0; idx1 < 672; idx1++) {
      result_tmp = argInit_uint8_T();
      result[idx0 + 376 * idx1] = result_tmp;
      result[(idx0 + 376 * idx1) + 252672] = result_tmp;
      result[(idx0 + 376 * idx1) + 505344] = argInit_uint8_T();
    }
  }
}

static unsigned char argInit_uint8_T()
{
  return 0U;
}
click to hide/show revision 3
retagged

updated 2019-03-14 09:12:03 -0600

berak gravatar image

How to pass OpenCV Mat(CV_8UC3) to Matlab generated code and vice-versa? Efficiently

'Matlab coder' generated a c++ function. (function name is 'matlab')

matlab(uv0, outImg);

//Before calling, arguments need to declared
emxArray_uint8_T *outImg;
static unsigned char uv0[758016];
emxInitArray_uint8_T(&outImg, 3);

I don't know how 'cv::Mat' can be converted into 'unsigned char uv0'

and

'emxArray_uint8_T *outImg' back into cv::Mat.

//some related function are

static void argInit_376x672x3_uint8_T(unsigned char result[758016])
{
  int idx0;
  int idx1;
  unsigned char result_tmp;
  for (idx0 = 0; idx0 < 376; idx0++) {
    for (idx1 = 0; idx1 < 672; idx1++) {
      result_tmp = argInit_uint8_T();
      result[idx0 + 376 * idx1] = result_tmp;
      result[(idx0 + 376 * idx1) + 252672] = result_tmp;
      result[(idx0 + 376 * idx1) + 505344] = argInit_uint8_T();
    }
  }
}

static unsigned char argInit_uint8_T()
{
  return 0U;
}