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
0 件のコメント
採用された回答
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
2015 年 6 月 30 日
Yes, of course, I mixed this up. I updated the answer. Thanks James!
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!