pixel data from mex to matlab: mxArray definition..

1 次查看(过去 30 天)
Hello I’m trying to use TCP/IP gEth. camera using mex file. The cpp code provides by camera vendor is very useful to open library/open/close camera and trigger, also I’m able to save image bmp in a selected folder from where I can read the image (1600X1200) from matlab (imread/imshow). Everything works fine but I’m not able to transfer the pixel data from mex to matlab. Below an example of the cpp code where a simple pixel calculation is performed (*pPixel = ~*pPixel): // get the pointer to the image data
void* pData = NULL;
int32_t iImageOffset = 0;
pBuffer->GetPtr (LvBuffer_UniBase, &pData);
pBuffer->GetInt32 (LvBuffer_UniImageOffset, &iImageOffset);
pData = (uint8_t*)pData + iImageOffset;
for (int32_t j=0; j<(1200); j++)
{
uint8_t* pPixel = ((uint8_t*)pData) + j*1600;
for (int32_t i=0; i<(1600); i++)
{
for (int32_t k=0; k<iBytesPerPixel; k++)
{
*pPixel = ~*pPixel;
pPixel++;
}
}
}
My problem is how to transfer the pPixel (uint_8) to matlab… I’m tring to use mxArray B; B= mxCreateNumericData(1600, 1200, mxINT8_CLASS, mxREAL); But I don’t know how to populate the matrix B. Please, any advices??
M. Thanks
Enrico

采纳的回答

Titus Edelhofer
Titus Edelhofer 2015-6-29
编辑:Titus Edelhofer 2015-6-30
Hi Enrico,
as a .bmp it probably has 24 bits, i.e., you iBytesPerPixel is 3. Therefore you should allocate a 1600x1200x3 matrix:
mwSize aSize[3] = {1600, 1200, 3};
plhs[0] = mxCreateNumericArray(3, aSize, mxUINT8_CLASS, mxREAL);
uint8_t *pData = (uint8_t*) mxGetData(plhs[0]);
You might use the code you have above to loop on the indices, and put each pixel from pPixel into pData. Note though, that the indices are running differently in MATLAB then in your code, it should be something like
pData[k*1200*1600 + j*1600 + i] = *pPixel;
but I'm not 100% sure I admit ;-).
Titus
  3 个评论
Titus Edelhofer
Titus Edelhofer 2015-6-30
Yes, of course, I mixed this up. I updated the answer. Thanks James!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by