필터 지우기
필터 지우기

pixel data from mex to matlab: mxArray definition..

조회 수: 1 (최근 30일)
Enrico  Boscolo
Enrico Boscolo 2015년 6월 29일
댓글: Enrico Boscolo 2015년 7월 2일
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!
Enrico  Boscolo
Enrico Boscolo 2015년 7월 2일
very helpful !!..it's working. Many thanks Enrico

댓글을 달려면 로그인하십시오.

추가 답변 (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