trouble passing image from c to matlab..
显示 更早的评论
...
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...
回答(2 个)
Kaustubha Govind
2011-5-11
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 个评论
Vikash Anand
2011-5-11
Vikash Anand
2011-5-11
Kaustubha Govind
2011-5-11
Could it be than opencv is somehow not storing the pixel values in the expected linear order?
类别
在 帮助中心 和 File Exchange 中查找有关 OpenCV Support 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!