trouble passing image from c to matlab..
Mostrar comentarios más antiguos
...
mxArray *mat1;
UINT8_T *dynamicData;
mwSize index;
unsigned long int elements;
elements = (ImgTempTp->width)*(ImgTempTp->height);
dynamicData = mxCalloc(elements, sizeof(UINT8_T));
for ( index = 0; index < elements; index++ ) {
dynamicData[index] = ImgTempTp->imageData[index];
}
mat1 = mxCreateNumericMatrix(0, 0, mxUINT8_CLASS, mxREAL);
mxSetData(mat1, dynamicData);
mxSetM(mat1, ImgTempTp->height);
mxSetN(mat1, ImgTempTp->width);
mlfShowimage(mat1);
.
.
ImgTempTp is an image created by opencv. the data type is unsigned char.
function [] = showimage(img)
figure,imshow(img);
input('Press Enter to continue...');
end
Some times the image appears properly but many times it gets mixed up in 2-3 manners i.e. it has 2-3 sections which contains parts of original image in tilted fashion
I have tried memcpy also. But i get the same error.. PLs help...
Respuestas (2)
Kaustubha Govind
el 11 de Mayo de 2011
Is there a reason your are using a rather roundabout way to achieve this? Why not use something like:
...
mxArray *mat1;
UINT8_T *dynamicData;
mwSize index;
unsigned long int elements;
elements = (ImgTempTp->width)*(ImgTempTp->height);
mat1 = mxCreateNumericMatrix(ImgTempTp->height, ImgTempTp->width, mxUINT8_CLASS, mxREAL);
dynamicData = (UINT8_T *)mxGetData(mat1);
for ( index = 0; index < elements; index++ ) {
dynamicData[index] = ImgTempTp->imageData[index];
}
mlfShowimage(mat1);
.
.
Do you know if ImgTempTp->imageData contains the image in the right indexing order? It seems like the image is being read along the diagonal. Have you tried examining the contents of ImgTempTp->imageData and comparing them with the value 'img' that's passed into showimage?
3 comentarios
Vikash Anand
el 11 de Mayo de 2011
Vikash Anand
el 11 de Mayo de 2011
Kaustubha Govind
el 11 de Mayo de 2011
Could it be than opencv is somehow not storing the pixel values in the expected linear order?
Vikash Anand
el 13 de Mayo de 2011
0 votos
Categorías
Más información sobre OpenCV Support en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!